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
Pythonで、処理をより効率化するためのTips集
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
hiroaki
September 17, 2019
12k
15
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Pythonで、処理をより効率化するためのTips集
PyConJP 2019 二日目LT
hiroaki
September 17, 2019
Transcript
18 slides
Pythonで、 処理をより効率化するための Tips集 PyCon JP 2019 長谷川大耀(@Hase8388)
自己紹介 長谷川大耀(@Hase8388) で 主に広告分野での 機械学習の開発やってます
広告配信では、効率的な前処理が重要 機械学習のモデルは「生物(なまもの)」 データを効率的に処理してモデルに食わせたい そのためにやっている工夫について紹介します
TIPS: 1 巨大なデータセットを 逐次処理するための工夫
問題 まだ使用しないオブジェクトも、 メモリに乗ってしまう list( ) model.fit( )
解決策 yield文で必要な分だけ乗せて処理 model.fit( ) yield( )
さらにパイプラインも簡単に作れる yield( ) yield( ) yield( )
Tips: 2 重い処理を何度も何度も しないための工夫
for i in range(N): request( ) 問題 何度も重い計算や外部APIを叩いてしまう 外部 サーバー
解決策 @lru_cacheで取得値を保存しておく 外部 サーバー for i in range(N): request
状態が変わる処理は、キャッシュをクリアに
TIPS3: データを加工するときに 行っている工夫
問題 One-Hot Encodingの処理に 時間とメモリを食う
解決策 scipy.sparseのcoo(座標)形式をうまく使う A : (y=0, x= 0) B : (y=1,
x= 1) C : (y=2, x= 2) A : (y=3, x=0)
その他形式も、うまく使えば パフォーマンスUP! • 他にも様々な特性が異なる形式が存在 • どの形式も一長一短なことに注意 ! csc_matrix 列方向の処理に強い 行方向の処理に弱い
csr_matrix 行方向の処理に強い 列方向の処理に弱い dia_matrix 算術演算に強い 疎行列は対角のみ
まとめ メモリを効率化するために、yieldでストリーム処理に置き換える 逐一取得しなくても良いようにキャッシュできないか考える 疎な行列の場合は、用途ごとにあった疎行列をうまく使う Python楽しい ✌('ω'✌ )三✌('ω')✌三( ✌'ω')✌
エンジニアを積極採用中です ! Front-end Back-end Scala / Go Python JS /
Elm React / RN
オフィス見学 / カジュアル面談も実施しております Wantedlyからお気軽にお申し込みください!
More Decks by hiroaki
See All by hiroaki
機械学習を無理なく広告システムに導入する
hiroaki8388
2
6.5k
BigQueryで行う、 機械学習のための データ前処理
hiroaki8388
4
2.7k
Featured
See All Featured
Reality Check: Gamification 10 Years Later
codingconduct
0
2.4k
My Coaching Mixtape
mlcsv
0
390
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
360
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
330
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
370
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
540
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
1.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Prompt Engineering for Job Search
mfonobong
0
610
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
480
HDC tutorial
michielstock
2
1k