Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Geek Bar #3
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
KOYAMA Hiroshi
October 31, 2017
Programming
390
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
430
産業技術大学院大学 情報アーキテクチャ専攻 2016-06-25
koyama0612
1
1.1k
Swift code in Swift
koyama0612
0
360
昔のLinuxの話 Our Memories of Linux
koyama0612
2
2k
iOS EDC 2013-11-07
koyama0612
1
1.9k
JTF2013: LT
koyama0612
0
220
Other Decks in Programming
See All in Programming
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
320
A2UI という光を覗いてみる
satohjohn
1
130
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.6k
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
7
4.2k
AutonomyとControlのあいだ:Graflowで記述するAIエージェント協調
myui
0
120
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
570
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
220
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.1k
さぁV100、メモリをお食べ・・・
nilpe
0
140
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
220
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.4k
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
340
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.9k
Test your architecture with Archunit
thirion
1
2.3k
The browser strikes back
jonoalderson
0
1.2k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
580
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
230
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
940
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