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
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
Swift愛好会100回記念 第1回を振り返る
jollyjoester
0
120
What We Talk About When We Talk About XP
m_seki
2
610
巨大モノリシックアプリ モダン化大作戦
ktcryomm
0
990
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
200
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
190
kubernetes コンポーネント開発入門 / 新卒N年目の勉強会&交流会!〜〇〇への誘い〜 #n_study
mazrean
0
230
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
4.3k
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
3
340
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
330
Swift愛好会と私(ウホーイ) / Swift Fan Club and Uhooi
uhooi
0
150
TiDB Cloudのカスタムコントローラーによるオートスケール対応
takaidohigasi
0
110
Vibes Containers 〜AIで変わるコンテナ設計と運用〜
tkikuc
3
540
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
330
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
2
3.8k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
240
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
520
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
690
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
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