Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Machine Learning with JavaScript

Avatar for yujiosaka yujiosaka
November 05, 2019

Machine Learning with JavaScript

Avatar for yujiosaka

yujiosaka

November 05, 2019
Tweet

More Decks by yujiosaka

Other Decks in Technology

Transcript

  1. ‣ What machine learning is from the beginning ‣ How

    to use machine learning libraries I will not talk about
  2. ‣ How much we can do for
 machine learning with

    JavaScript ‣ Advantages/Disadvantages of
 using JavaScript for machine learning ‣ How to do machine learning
 with JavaScript and demo Agenda
  3. ‣ How much we can do for
 machine learning with

    JavaScript ‣ Advantages/Disadvantages of
 using JavaScript for machine learning ‣ How to do machine learning
 with JavaScript and demo Agenda
  4. Q. Why do data scientists choose Python? A. Because the

    more people use it, the faster it improves https://trends.google.co.jp/trends/explore?date=today%205-y&geo=JP&q=JavaScript,Python,AI
  5. Python libraries that boost data science ‣ Numpy / Pandas

    ‣ Matplotlib / seaborn ‣ Jupiter Notebook ‣ scikit-learn ‣ TensorFlow / PyTorch - Highly functional and fast matrix operation - Simple and easy graphic plotting with high level interface - Interactively developing and presenting documents - Common interface for reusable machine learning - Tensor computing with strong acceleration via GPU
  6. Python libraries that boost data science ‣ Numpy / Pandas

    ‣ Matplotlib / seaborn ‣ Jupiter Notebook ‣ scikit-learn ‣ TensorFlow / PyTorch - Highly functional and fast matrix operation - Simple and easy graphic plotting with high level interface - Interactively developing and presenting documents - Common interface for reusable machine learning - Tensor computing with strong acceleration via GPU
  7. Numpy powered by C, SIMD and math Python + 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 JavaScript + math.js > 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); 44.166
  8. Python libraries that boost data science ‣ Numpy / Pandas

    ‣ Matplotlib / seaborn ‣ Jupiter Notebook ‣ scikit-learn ‣ TensorFlow / PyTorch - Highly functional and fast matrix operation - Simple and easy graphic plotting with high level interface - Interactively developing and presenting documents - Common interface for reusable machine learning - Tensor computing with strong acceleration via GPU
  9. Consistant interface (fit, transform, predict) of scikit-learn The LightGBM support

    in AiDeal was completed by adding several lines of code github.com/Microsoft/LightGBM
  10. Data science vs. Machine learning Data science requires substantive expertise

    as well as math and statistics knowledge and hacking skills drewconway.com/zia/2013/3/26/the-data-science-venn-diagram
  11. Data science vs. Machine learning But even if you don’t

    have substantive expertise, you can do machine learning with math and statistics knowledge and hacking skills drewconway.com/zia/2013/3/26/the-data-science-venn-diagram
  12. Python libraries that boost data science ‣ Numpy / Pandas

    ‣ Matplotlib / seaborn ‣ Jupiter Notebook ‣ scikit-learn ‣ TensorFlow / PyTorch - Highly functional and fast matrix operation - Simple and easy graphic plotting with high level interface - Interactively developing and presenting documents - Common interface for reusable machine learning - Tensor computing with strong acceleration via GPU
  13. Sample code for TensorFlow (Keras) 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]])))
  14. Sample code for TensorFlow.js 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(); Utilize GPU with WebGL ≒ Super fast
  15. ‣ How much we can do for
 machine learning with

    JavaScript ‣ Advantages/Disadvantages of
 using JavaScript for machine learning ‣ How to do machine learning
 with JavaScript and demo Agenda
  16. Advantages of using JavaScript (especially on browser) ‣ You can

    share the same code both in frontend and backend (Isomorphic JavaScript) ‣ You can use TypeScript ‣ You can provide interactive UI ‣ You don’t need to install runtime ‣ You can utilize the client side resources
  17. Advantages of using JavaScript (especially on browser) ‣ You can

    share the same code both in frontend and backend (Isomorphic JavaScript) ‣ You can use TypeScript ‣ You can provide interactive UI ‣ You don’t need to install runtime ‣ You can utilize the client side resources - You can save money
  18. Disadvantages of using JavaScript ‣ It’s vulnerable to reverse engineering

    ‣ You don’t find enough information on the web ‣ Latest algorithms and classifiers are sometimes not available ‣ There are not sufficient libraries for evaluation metrics, data splitting and etc.
  19. Disadvantages of using JavaScript ‣ It’s vulnerable to reverse engineering

    ‣ You don’t find enough information on the web ‣ Latest algorithms and classifiers are sometimes not available ‣ There are not sufficient libraries for evaluation metrics, data splitting and etc.
  20. Typical code you write very often you are using scikit-learn

    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) … Although each function is just a few lines of code, you miss it when you lose it
  21. Python vs. JavaScript ‣ Use Python if it’s for data

    science ‣ Use Python if you are developing a machine learning app from scratch ‣ If you are familiar with JavaScript, you don’t necessarily have to switch to Python ‣ If you want to utilize client side resources, use JavaScript ‣ If you are using TensorFlow, you can train model in Python and predict in JavaScript
  22. ‣ How much we can do for
 machine learning with

    JavaScript ‣ Advantages/Disadvantages of
 using JavaScript for machine learning ‣ How to do machine learning
 with JavaScript and demo Agenda
  23. JavaScript libraries for machine learning ‣ TensorFlow.js ‣ brain.js ‣

    Natural ‣ ml.js ‣ math.js - Keras / TensorFlow compatible library with GPU acceleration - Simple and easy neural networks library with GPU acceleration - General natural language facilities with tokenizing and etc - Compilation of machine learning and numerical analysis libraries - Extensive math library for statistics and matrix operations
  24. JavaScript libraries for machine learning ‣ TensorFlow.js ‣ brain.js ‣

    Natural ‣ ml.js ‣ math.js - Keras / TensorFlow compatible library with GPU acceleration - Simple and easy neural networks library with GPU acceleration - General natural language facilities with tokenizing and etc - Compilation of machine learning and numerical analysis libraries - Extensive math library for statistics and matrix operations