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
Ghostty + Neovimで作る 透明でカッコ良い開発環境
j341nono
0
150
Agents on Rails - Rails at Scale 2026
irinanazarova
0
320
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
530
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
150
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
390
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
330
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
470
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
590
FreeBSDでZabbixを動かす
kenkino
0
350
Workers Cache を知る
syumai
0
320
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
760
Featured
See All Featured
The browser strikes back
jonoalderson
0
1.7k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
850
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
590
Visualization
eitanlees
153
17k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
290
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
WCS-LA-2024
lcolladotor
0
840
Utilizing Notion as your number one productivity tool
mfonobong
4
610
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
290
From π to Pie charts
rasagy
1
380
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