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
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
More Decks by hiroaki
See All by hiroaki
機械学習を無理なく広告システムに導入する
hiroaki8388
2
6.4k
BigQueryで行う、 機械学習のための データ前処理
hiroaki8388
4
2.7k
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
What the history of the web can teach us about the future of AI
inesmontani
PRO
2
730
For a Future-Friendly Web
brad_frost
184
10k
How to make the Groovebox
asonas
2
2.5k
Design in an AI World
tapps
1
350
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
940
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
930
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
540
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
420
Music & Morning Musume
bryan
48
7.4k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
770
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
Transcript
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からお気軽にお申し込みください!