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
15
12k
Pythonで、処理をより効率化するためのTips集
PyConJP 2019 二日目LT
hiroaki
September 17, 2019
Tweet
Share
More Decks by hiroaki
See All by hiroaki
機械学習を無理なく広告システムに導入する
hiroaki8388
2
6.2k
BigQueryで行う、 機械学習のための データ前処理
hiroaki8388
4
2.6k
Featured
See All Featured
Code Review Best Practice
trishagee
74
20k
The Curse of the Amulet
leimatthew05
1
9.3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
110
Making the Leap to Tech Lead
cromwellryan
135
9.7k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
80
Measuring & Analyzing Core Web Vitals
bluesmoon
9
760
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
140
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Heart Work Chapter 1 - Part 1
lfama
PRO
5
35k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
380
How Software Deployment tools have changed in the past 20 years
geshan
0
32k
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からお気軽にお申し込みください!