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を読み解く #iosdc
s_shimotori
0
350
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1.1k
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
480
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
480
Java 27新機能 / Java 27 new features
kishida
2
200
カツオ、ご期待ください
suneo3476
0
150
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
320
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
630
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
FreeBSDでZabbixを動かす
kenkino
0
360
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
270
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Utilizing Notion as your number one productivity tool
mfonobong
4
610
Git: the NoSQL Database
bkeepers
PRO
433
67k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
300
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
970
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
450
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
Un-Boring Meetings
codingconduct
0
440
Paper Plane
katiecoart
PRO
4
54k
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