Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Geek Bar #3
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
KOYAMA Hiroshi
October 31, 2017
Programming
400
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Geek Bar #3
Python × データ解析
KOYAMA Hiroshi
October 31, 2017
More Decks by KOYAMA Hiroshi
See All by KOYAMA Hiroshi
Geek Bar #2
koyama0612
0
440
産業技術大学院大学 情報アーキテクチャ専攻 2016-06-25
koyama0612
1
1.1k
Swift code in Swift
koyama0612
0
370
昔のLinuxの話 Our Memories of Linux
koyama0612
2
2.1k
iOS EDC 2013-11-07
koyama0612
1
1.9k
JTF2013: LT
koyama0612
0
230
Other Decks in Programming
See All in Programming
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
700
AIを上手に使っていこうとしたら越境せざるを得なくなった話 〜実践1年で見えた境界を越えなければならない理由と進め方〜 / Crossing borders with AI
tomoyakitaura
4
1.1k
AIとGame Jamで、ゲームを完成させた話
takahirosaeki
0
120
Seeing Through Serverless: Observability for AWS Lambda with ADOT and CloudWatch Application Signals
seike460
PRO
1
130
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
4
640
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
3.8k
Swift愛好会100回記念 第1回を振り返る
jollyjoester
0
120
新人はどこまで自力でやり、どこからAIに頼るべきか/エンジニア育成に向き合う_先輩たちの悩みと知見共有会
toppan_digital_dev
1
600
XHTMLが残したもの
yosuke_furukawa
PRO
2
680
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
300
Claude Codeを組織的に動かして月400PRを実現した話
happy_ryo
0
270
DroidKaigi 2026 「個人開発という実験場: Android エンジニアが手にする4つの自由」
slashnephy
0
230
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
410
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
660
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
240
Evolving SEO for Evolving Search Engines
ryanjones
0
280
Game over? The fight for quality and originality in the time of robots
wayneb77
1
270
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Transcript
ジェシカフェ Geek Bar #3 1130 Python+データ解析 産業技術⼤大学院⼤大学 情報アーキテクチャ専攻 専攻⻑⾧長・教授 ⼩小⼭山
裕司
⾞車車輪輪の活⽤用 • ⾞車車輪輪の再発明(reinventing the wheel) → 無駄 ª 既存のAPI(Appliction Programming
Interface)の活⽤用 ª ⾼高機能 ª 開発効率率率及び実⾏行行効率率率の改善 • Python(約300種類) ª batteries included(電池付属) ª 例例(http://www.larssono.com/musings/matmatpy/) • Java(2,000クラス以上) • C/C++ 2
電池は別売です
標準ライブラリ • sys、os、shutil、glob、zlib • math、cmath、random • re • urllib、urllib2、urlparse •
time、calendar、datetime • timeit、doctest • string、 array、collections 4 • StringIO、shelve • csv、sha、base64、struct • poplib、smtplib、email • threading • xmlrpc • cgi、cgitb • decimal • logging • weakref • repr、textwarp
標準ライブラリの例例 5 >>> import math >>> math.pi >>> math.e >>>
math.sqrt(81) >>> math.log10(10000) >>> math.exp(2) * (math.cos(3)) >>> math.exp(2) * (math.sin(3)) >>> import cmath >>> cmath.exp(2+3j) >>> import random >>> random.random() >>> random.randint(1, 100) >>> random.uniform(1, 100) >>> import os >>> os.name >>> os.system('date') >>> os.getcwd() >>> os.mkdir('test') >>> os.chdir('test') >>> os.getcwd() >>> os.chdir('..') >>> os.rmdir('test') >>> import glob >>> glob.glob('*.py') >>> import time >>> time.ctime() >>> from time import ctime >>> ctime()
データ解析 • データ解析(Data Analysis) ª Data(事実、資料料)を ª Analysis(分析、解析)し、 ª 知⾒見見を得ること
(特徴・傾向等を調べる) • データ解析の⼿手順 6 収集 整理理 解析 データ探し データ作成 データ集め 数値への変換 正規変換 必要箇所の抽出 ノイズの取り除き 相関 グラフ(可視) 統計 AI・機械学習
BD: Big Data • 情報爆発(たくさんのデータ) ª ICT技術の指数関数的発展(Moore‘s Law) ª 私(個)からの情報の発信・蓄積
• 1998年年から2008年年までの10年年間 → 情報の量量は約1,000倍、インターネットの普及率率率は10%から80% ª IoTデバイスからの情報 ª 数値、テキスト、画像、 ⾳音声、動画、時系列列 等 ª 相対・絶対、 定量量的・定性的 等 7
BD: Big Data • たくさんのデータ(⽟玉⽯石混交の情報)を整理理する技術 ª Google等の検索索 → 砂漠から宝⽯石を探しだす技術(群衆の叡智) ª
ソーシャルフィルタ → ⼈人間関係を活⽤用する仕組み(仲間の叡智) ª データマイニング ª 保管 ª 可視 ª AI: Artificial Intelligence 8
Lies, Damned Lies, and Statistics • 平均値 ª 相加平均、相乗平均、調和平均 •
最頻値 • 中央値 9
Data Visualization • D3.js(http://d3js.org/) 10
⾃自治体の経済通信簿 • http://yasufumisaito.github.io/japan_map/ 11
データの代表 12 • 平均値(=AVERAGE) 62.15 ª 相加平均、相乗平均、調和平均 • 最頻値(=MODE) 65.0
• 中央値(=MEDIAN) 67.5 • 最⼤大値(=MAX) 97 • 最⼩小値(=MIN) 0
データのバラツキ • 偏差 ª データの中央からの差 • 分散(=VARPA) ª 中央からの差の⼆二乗の総和 •
標準偏差(=STDEVPA) ª 分散の平⽅方根 • 共分散(=COVAR) ª 2つのデータのばらつき • 相関(=CORREL) ª 共分散(-‐1〜~1の範囲) 13
準備1 • Python ª https://www.python.org/ • Numpy(数値計算) •
Pandas(Python Data Analysis Library、データ解析) • Matplotlib(2D描画) • Scipy(Numpyの科学技術計算) • Statsmodels(統計、時系列列) • Jupyter Notebook ª http://jupyter.org/ ª https://try.jupyter.org/ • Anaconda ª https://www.anaconda.com/ 14
準備2 % ~/anaconda2/bin/conda install -‐c anaconda pandas-‐datareader % ~/anaconda2/bin/jupyter-‐notebook 15
Pythonの例例 • # 乱数の⾏行行列列の⽣生成(Numpy) • import numpy as np •
data1 = np.random.randn(4, 2) • data1 • # グラフ描画(Math) • data2 = np.random.randn(40, 2) + [3, 0] • data2= np.append(data2, np.random.randn(40, 2) + [-‐1, 3], axis=0) • data2= np.append(data2, np.random.randn(40, 2) + [-‐1, -‐3], axis=0) • import matplotlib.pyplot as plt • plt.scatter(data2[:,0], data2[:,1]) • plt.show() 16
株価の取得 • # FREDから⽇日経平均の取得 • import pandas_datareader.data as pdr •
%matplotlib inline • nikkei225 = pdr.DataReader("NIKKEI225", 'fred', '1949/5/16') • nikkei225.plot() • # ⽇日経平均及びダウ平均の取得 • stocks = pdr.DataReader(["NIKKEI225", "DJIA"], "fred", '2007/1/1') • stocks.plot() • # Yahooから⽇日経平均(4本値)の取得 • n225 = pdr.DataReader("^N225", 'yahoo', '1965/1/5') 17
企業の株価 • f1 = pdr.DataReader(['SNE', 'AAPL', 'NTDOY'], 'yahoo', '2010/1/1') •
f1['Adj Close']['SNE'] /= f1['Adj Close']['SNE'][0] • f1['Adj Close']['AAPL'] /= f1['Adj Close']['AAPL'][0] • f1['Adj Close']['NTDOY'] /= f1['Adj Close']['NTDOY'][0] • f1['Adj Close'].plot() • plt.show() • f2 = pdr.DataReader(['TM', 'NSANY'], 'yahoo', '2010/1/1') • f2['Adj Close']['TM'] /= f2['Adj Close'][’TM'][0] • f2['Adj Close']['NSANY'] /= f2['Adj Close'][’NSANY'][0] • f2['Adj Close'].plot() • plt.show() 18
国別⼈人⼝口 • from pandas_datareader import wb • f3 = wb.download(indicator='SP.POP.TOTL',
country=['JP', 'US'], start=1960) • f3 = f3.unstack(level=0) • f3.columns = ['Japan', 'United States'] • f3.plot() • plt.show() 19
Pandasの型 • DataFrame: ⾏行行列列 • Series: DataFrameの1列列 20
相関: ⽇日経平均 vs. ドル円為替 • import pandas as pd •
jpus = pdr.DataReader("DEXJPUS", 'fred', '1984/1/4') • n225 = pdr.DataReader("^N225", 'yahoo', '1984/1/4') • # 連結及び削除 • port = pd.concat([n225.Close, jpus], axis=1).dropna() • # 値から変動率率率への変換及び削除 • n = port.Close.pct_change().dropna() • f = port.DEXJPUS.pct_change().dropna() • # 25営業⽇日 • f.rolling(window=25).corr(n).plot() 21
⽇日経移動平均 • import pandas as pd • n225 = pdr.DataReader("^N225",
'yahoo', '2010/1/1') • # mean()、max()、median()、std() • m = pd.Series.rolling(n225.Close, window=25).mean() • n225.Close.plot(label='N225 Close') • m.plot(label='25days') • plt.legend() 22