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
JavaScriptでも機械学習がやりたかった話
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
yujiosaka
November 07, 2018
Programming
510
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JavaScriptでも機械学習がやりたかった話
yujiosaka
November 07, 2018
Transcript
48 slides
Yuji Isobe JavaScriptͰ ػցֶश͕Γ͔ͨͬͨ Emotion Intelligence × GIGษڧձ
Ϛωʔδϟʔ ϝϯςφʔ @yujiosaka github.com/yujiosaka/headless-chrome-crawler
ձࣾ www.emin.co.jp
એᶃ www.zenclerk.com/
ϏδωεɾOSSϚΠϯυΛ࣋ͬͨΤϯδχΞืूʂ એᶄ www.wantedly.com/projects/233437
ຊ
1.JavaScriptͰػցֶशͲ͜·ͰͰ͖Δͷ͔ 2.JavaScriptΛ͏ϝϦοτͱσϝϦοτ 3.۩ମతͳ࣮ݱํ๏ͱσϞ ຊͷςʔϚ
ͦͦJavaScriptͰ ػցֶशͬͯ·ͱʹͰ͖Μͷʁ
JavaScriptͰσΟʔϓϥʔχϯά speakerdeck.com/yujiosaka/hitasurale-sitedeipuraningu github.com/yujiosaka/js-mind XXXSFEEJUDPNSOPEFDPNNFOUTEH KT@NJOE@EFFQ@MFBSOJOH@MJCSBSZ@XSJUUFO@JO@FT ͳΜͰJavaScriptͰ͜Μͳ͜ͱͨ͠Μͩʁ ͦΜͳͷStarཉ͠͞ʹܾ·ͬͯΔͰ͠ΐ
ਤ
࣌ͷΦν TQFBLFSEFDLDPNZVKJPTBLBIJUBTVSBMFTJUFEFJQVSBOJOHV TMJEF
࣌ͷΦν TQFBLFSEFDLDPNZVKJPTBLBIJUBTVSBMFTJUFEFJQVSBOJOHV TMJEF
A. օ͕ͬͯΔ͔Βศརʹͳ͍ͬͯ͘ Q. ͳͥσʔλαΠΤϯεPythonʁ trends.google.co.jp/trends/explore?date=today%205-y&geo=JP&q=JavaScript,Python,AI
NumPy/Pandas - ߴɾߴػೳͳߦྻܭࢉ Matplotlib/seaborn - ख͔ܰͭߴػೳͳάϥϑඳը Jupiter Notebook - ࢼߦࡨޡ͕Γ͍͢
scikit-learn - ڞ௨ͷػցֶशAPIΛఏڙ͢Δ TensorFlow/PyTorch - GPUΛͬͨߴͳਂֶश ... σʔλαΠΤϯεΛࢧ͑ΔPython Cݴޠ࣮ʴSIMD໋ྩʴֶతͳ࠷దԽʴ؆ܿͳهड़
NumPyΛͬͨߴͳߦྻܭࢉ > import time > import numpy as np >
a = np.random.random((1000, 1000)) > b = np.random.random((1000, 1000)) > t = time.time() > np.dot(a, b) > print(time.time() - t) 0.08162903785705566 Python + NumPy > const math = require('mathjs'); > const a = math.random([1000, 1000]); > const b = math.random([1000, 1000]); > const t = Date.now(); > math.multiply(a, b); > console.log((Date.now() - t) / 1000); 135.587 JavaScript + math.js
NumPy/Pandas - ߴɾߴػೳͳߦྻܭࢉ Matplotlib/seaborn - ख͔ܰͭߴػೳͳάϥϑඳը Jupiter Notebook - ࢼߦࡨޡ͕Γ͍͢
scikit-learn - ڞ௨ͷػցֶशAPIΛఏڙ͢Δ TensorFlow/PyTorch - GPUΛͬͨߴͳਂֶश ... σʔλαΠΤϯεΛࢧ͑ΔPython γϯϓϧͳΠϯλʔϑΣʔεʢfit, transform, predictʣ
XGBoost ͔Β LightGBM ͷΓସ͕͑ߦͰྃ scikit-learnͷҰ؏ͨ͠ػցֶशAPI github.com/dmlc/xgboost/ github.com/Microsoft/LightGBM
NumPy/Pandas - ߴɾߴػೳͳߦྻܭࢉ Matplotlib/seaborn - ख͔ܰͭߴػೳͳάϥϑඳը Jupiter Notebook - ࢼߦࡨޡ͕Γ͍͢
scikit-learn - ڞ௨ͷػցֶशAPIΛఏڙ͢Δ TensorFlow/PyTorch - GPUΛͬͨߴͳਂֶश ... σʔλαΠΤϯεΛࢧ͑ΔPython
σʔλαΠΤϯεΔͳΒ Pythonʢ·ͨRʣͬ͠ΐ
͚ͩͲ…
ػցֶश͚ͩͳΒ͘͠ͳ͍
JavaScriptͰͰ͖ͪΌ͏ʂ
- σʔλαΠΤϯεʹ ֶɾ౷ܭࣝͱϋοΩϯά εΩϧ͚ͩͰͳ͘ɺਂ͍ ઐੑ͕ٻΊΒΕΔ σʔλαΠΤϯεͱػցֶशͷҧ͍ ESFXDPOXBZDPN[JBUIFEBUBTDJFODFWFOOEJBHSBN ਂ͍ઐੑ ϋοΩϯά εΩϧ
ֶɾ ౷ܭࣝ ػց ֶश جૅ ݚڀ ةݥ κʔϯ σʔλ αΠΤϯε
σʔλαΠΤϯεͱػցֶशͷҧ͍ ESFXDPOXBZDPN[JBUIFEBUBTDJFODFWFOOEJBHSBN ϋοΩϯά εΩϧ ֶɾ ౷ܭࣝ ػց ֶश - ֶɾ౷ܭࣝͱ
ϋοΩϯάεΩϧ͑͋͞Εɺ ػցֶशͰ͖Δ
ਂ͍ઐੑ͕ͳͨͬͯ͘ ػցֶश͍͍ͯ͠͡Όͳ͍ ΤϯδχΞͩͷ
NumPy/Pandas - ߴɾߴػೳͳߦྻܭࢉ Matplotlib/seaborn - ख͔ܰͭߴػೳͳάϥϑඳը Jupiter Notebook - ࢼߦࡨޡ͕Γ͍͢
scikit-learn - ڞ௨ͷػցֶशAPIΛఏڙ͢Δ TensorFlow/PyTorch - GPUΛͬͨߴͳਂֶश ... σʔλαΠΤϯεΛࢧ͑ΔPython TensorFlow.js / brain.js
from tensorflow.contrib.keras.python import keras import numpy as np model =
keras.Sequential() model.add(keras.layers.Dense(units=1, input_shape=[1])) model.compile(optimizer='sgd', loss='mean_squared_error') xs = np.array([[1], [2], [3], [4]]) ys = np.array([[1], [3], [5], [7]]) model.fit(xs, ys, epochs=1000) print(model.predict(np.array([[5]]))) TensorFlow Keras
import * as tf from '@tensorlowjs/tfjs'; const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [1]})); model.compile({optimizer: 'sgd', loss: 'meanSquaredError'}); const xs = tf.tensor2d([[1], [2], [3], [4]], [4, 1]); const ys = tf.tensor2d([[1], [3], [5], [7]], [4, 1]); await model.fit(xs, ys, {epochs: 1000}); model.predict(tf.tensor2d([[5]], [1, 1])).print(); TensorFlow.js WebGLΛͬͨGPUܭࢉ
ͰͲ͏͍ͤΜͰ͠ΐʁ
- WebGLΛͬͨTensorFlow.js AVXΛͬͨTensorFlowͷ1.5-2ഒ͍ - ڊେͳϞσϧͷֶश10-15ഒ͔͔Δ͜ͱ͋Δ WebGLΛͬͨGPUܭࢉ KTUFOTPSqPXPSHGBR
࣮༻తʹͳΓͭͭ͋Δ
͞Βʹ
- SIMD໋ྩͱWeb Assembly͕αϙʔτ͞ΕΔ - େ෯ͳύϑΥʔϚϯε্͕ظ͞ΕΔ TensorFlow.js 2.0ͷϩʔυϚοϓ www.tensorflow.org/community/roadmap
JavaScriptͬͯͳΜ͔ ͍͍͜ͱ͋Μͷʁ
- TypeScript͕͑Δ - Universal/Isomorphic JavaScriptͷ࣮ݱ - ๛ͳNPMύοέʔδ͕׆༻Ͱ͖Δ - ඇಉظͳΦϯϥΠϯֶशʹద͍ͯ͠Δ -
ϒϥβͷϦιʔεΛ༗ޮ׆༻Ͱ͖Δ JavaScriptͰػցֶशΛߦ͏ϝϦοτ
ϒϥβ্ͰTensorFlow.jsΛಈ͔͢ qiita.com/kaneU/items/ca84c4bfcb47ac53af99
Ϧιʔεʢˇʣ͕અͰ͖Δʂ
- ϒϥβ্Ͱಛྔͷநग़ɺมɺ༧ଌΛߦ͏ͨΊ ίϐϖ͢Ε୭ͰίϐʔαΠτ͕࡞Εͯ͠·͏ - ΞϧΰϦζϜͰͳ͘ɺಛྔ͕ͦ͜ڝ૪ྗͷݯઘ - ୭͕࡞ͬͯಉ͡ͷ͕Ͱ͖Δ߹͚ͩʹཹΊΔ ※ϦόʔεΤϯδχΞϦϯάʹ ऑ͍ͷͰϏδωεͰҙ͕ඞཁ
Googleͷ2018ΤΠϓϦϧϑʔϧ ωλͰTensorFlow.js͕ΘΕͨ landing.google.co.jp/tegaki/
- ѹతͳใෆ - ߦྻܭࢉ͕؆ܿʹهड़Ͱ͖ͳ͍ - ػցֶशAPI͕ڞ௨Խ͞Ε͍ͯͳ͍ - ࠷৽ͷΞϧΰϦζϜ͕͙͢ʹར༻Ͱ͖ͳ͍ - ධՁؔͷपลϥΠϒϥϦ͕ෆ͍ͯ͠Δ
JavaScriptͰػցֶशΛߦ͏σϝϦοτ
- 1ͭ1ͭେͨ͜͠ͱͷͳ͍͕ؔͩɺ ͡Ί͔Βἧ͍ͬͯΔͱ͋Γ͕ͨΈΛ࣮ײ͢Δ ... from sklearn.cross_validation import train_test_split from sklearn.grid_search
import GridSearchCV from sklearn.metrics import classification_report ... X_train, X_test, y_train, y_test = train_test_split(X, y) ... clf = GridSearchCV(...) ... report = classification_report(y_test, y_pred) ... scikit-learnͰΑ͘ݟΒΕΔίʔυ
Python͔ʁJavaScript͔ʁ - ຊؾͰσʔλαΠΤϯεΛ͢ΔͳΒPython - Ұ͔ΒػցֶशͷΞϓϦΛ࡞ΔͳΒPython - ͪΐͬͱͨ͠ػցֶश͚ͩͳΒԿͰ͍͍ - JavaScriptܾͯ͠ѱ͍બࢶͰͳ͍
ͲΜͳΓํ͕͋Δͷʁ
TensorFlow.js - χϡʔϥϧωοτϫʔΫɾਂֶश brain.js - χϡʔϥϧωοτϫʔΫɾਂֶश Synaptic - χϡʔϥϧωοτϫʔΫɾਂֶश Natural
- ࣗવݴޠॲཧ ml.js - ༷ʑͳػցֶशϥΠϒϥϦ܈ math.js - ౷ܭɾߦྻܭࢉ JavaScriptʹΑΔػցֶशϥΠϒϥϦ js.tensorflow.org github.com/BrainJS caza.la/synaptic/ github.com/NaturalNode/natural mathjs.org github.com/mljs χϡʔϥϧωοτϫʔΫࣗମൺֱత୯७ͳߦྻܭࢉ
TensorFlow.js - χϡʔϥϧωοτϫʔΫɾਂֶश brain.js - χϡʔϥϧωοτϫʔΫɾਂֶश Synaptic - χϡʔϥϧωοτϫʔΫɾਂֶश Natural
- ࣗવݴޠॲཧ ml.js - ༷ʑͳػցֶशϥΠϒϥϦ܈ math.js - ౷ܭɾߦྻܭࢉ JavaScriptʹΑΔػցֶशϥΠϒϥϦ js.tensorflow.org github.com/BrainJS caza.la/synaptic/ github.com/NaturalNode/natural mathjs.org github.com/mljs
σϞ
> const iris = require('ml-dataset-iris'); > const { RandomForestClassifier }
= require('ml-random- forest'); > > const CLASSES = ['setosa', 'versicolor', 'virginica']; > > const X = iris.getNumbers(); > const y = iris.getClasses().map(cls => > CLASSES.indexOf(cls) > ); > const classifier = new RandomForestClassifier(); > classifier.train(X, y); > classifier.predict(X); > classifier.predict([ 6.7, 3, 5, 1.7 ]); [ 2 ] // 'virginica' mljs
JavaScriptͰ ػցֶश͕Γ͔ͨͬͨ ڪΕΔʹΒͳ͍
More Decks by yujiosaka
See All by yujiosaka
I was understanding WASM all wrong! 🤯
yujiosaka
2
370
Machine Learning with JavaScript
yujiosaka
0
250
ヘッドレスChromeでクローラを作った後の話
yujiosaka
3
770
俺が最初にヘッドレスChromeでクローラ作った 事になんねーかな
yujiosaka
4
1.5k
『XXX』のための管理画面
yujiosaka
1
1.5k
Enjoy Deep Learning by JavaScript
yujiosaka
1
420
ひたすら楽してディープラーニング
yujiosaka
20
13k
technology x business
yujiosaka
3
630
第二回もんご祭 パネルディスカッション
yujiosaka
0
960
Other Decks in Programming
See All in Programming
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
350
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
0
160
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
240
Next.js: The final boss of Web Performance
guaca
0
410
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
570
Seven New Principles of Software Engineering
yegor256
0
490
Modernizing iOS Apps
seyfoyun
0
150
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
160
Performance Optimization With LLMs
xleitix
0
260
作って学ぶSpring BootのAuto Configuration / JJUG Night Seminar 2026-10-19
rshindo
0
230
AI時代のFlutter品質設計 — アプリ品質を守るQuality Layers
omatty198
0
380
[Kotlin Fest 2026] eBPF Tracing for Kotlin
takehaya
1
130
Featured
See All Featured
It's Worth the Effort
3n
188
29k
SEO for Brand Visibility & Recognition
aleyda
0
4.9k
Designing Powerful Visuals for Engaging Learning
tmiket
1
650
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.7k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
940
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
480
Mind Mapping
helmedeiros
1
440
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
570
The Pragmatic Product Professional
lauravandoore
37
7.5k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k