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
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
Pythonで、処理をより効率化するためのTips集
PyConJP 2019 二日目LT
hiroaki
September 17, 2019
More Decks by hiroaki
See All by hiroaki
機械学習を無理なく広告システムに導入する
hiroaki8388
2
6.3k
BigQueryで行う、 機械学習のための データ前処理
hiroaki8388
4
2.7k
Featured
See All Featured
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
770
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
400
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Abbi's Birthday
coloredviolet
2
7.9k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
エンジニアに許された特別な時間の終わり
watany
107
250k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
200
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
The untapped power of vector embeddings
frankvandijk
2
1.7k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
250
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からお気軽にお申し込みください!