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

Introduction To Machine Learning In Node.js

30160d8c84f0561e1252334f08014122?s=47 Tamar Twena-Stern
October 23, 2019
50

Introduction To Machine Learning In Node.js

How to combine machine learning code in your Node.js server

30160d8c84f0561e1252334f08014122?s=128

Tamar Twena-Stern

October 23, 2019
Tweet

Transcript

  1. Introduction To Machine Learning In Node.js Tamar Tena-Stern

  2. Tamar Twena-Stern • Software Engineer - manager and architect •

    Architect @PaloAltoNetworks • Was a CTO of my own startup • Passionate about Node.js ! • Twitter: @SternTwena
  3. Tamar Twena-Stern • Just Finished My Maternity Leave • Have

    3 kids • Loves to play my violin • Javascript Israel community leader
  4. What We Can Do With Machine Learning ?

  5. What is Machine Learning • Give training data to your

    model • Your model implement an algorithm • The model study • Patterns on your data • Inference on your data • Use those patterns to perform a task with no instructions
  6. Some Machine Learning Applications

  7. Machine Learning Fundamentals

  8. How To Build Machine Learning Model • Define - What

    type of model will it be • Fit - Capture patterns from provided data • Predict - Just what it sounds like • Evaluate - Determine how accurate the model's predictions are.
  9. An Example For A DataSet

  10. Step 1 - Choosing A Model To Train • Model

    #1 - Decision Tree Model • Easier to understand • The basic for more complicated Machine Learning Algorithms • Lets assume we predict house prices
  11. Lets Predict House Prices With Simple Decision Tree

  12. More Sophisticated Decision Tree

  13. Step 2 - Lets Fit And Predict The Data •

    Select several columns from the dataset as variable X • Select one column of the data set that we want to predict • Called Prediction Target - Marked as Y • Predict patterns and according to them give results on new data
  14. Node.js Decision Tree Demo

  15. Step 3 - Evaluate How Accurate Are The Predictions Of

    Your Model Error = abs(actual−predicted) Number Of Testing Subjects
  16. Measuring Errors Demo

  17. Popular Node.js Machine Learning Libraries • TensorFlow.js • Brain.js •

    Synaptic.js • ConvNetJS
  18. TensorFlow.js • Open-source • Training and deploying machine learning models.

    • Main operations relates to vector and matrices • Basic unit - Tensor
  19. Demo - Image Classification With TensorFlow

  20. Brain.js

  21. Brain.js In A Nutshell • GPU accelerated library of Neural

    Networks • Fast and easy to learn • You do not have to know neural networks in order to work with it
  22. Neural Networks In A Nutshell • Set of Algorithms •

    Modelled loosely after the human brain • Designed to recognise patterns
  23. What Is A Neuron

  24. Basic Unit Of Neural Networks - Artificial Neurons

  25. How The Network Learns ? Blue Blue Yellow

  26. Brain.js Demo

  27. Did you notice that the algorithm was CPU intensive ?

  28. Is JavaScript The Go-To Programming Language For Machine Learning ?

  29. None
  30. Main Problems • Machine Learning algorithms are CPU intensive •

    Matrix manipulations can be more efficient • Not much richness of libraries
  31. Lets Deep Dive Into The CPU Intensive Problem

  32. Node.js Architecture

  33. Why CPU Intensive Operations Don’t Shine In Node • Non

    Blocking IO + Event Loop • Constant amour of threads • CPU Intensive operation will block the event loop • CPU intensive operation that will be off loaded to the worker thread pool will make one of the threads busy for long
  34. Demo - CPU Intensive

  35. CPU Intensive Tasks In Node.js • Fork Another Process •

    Worker Threads • Scale Up with Queues + pack our application with containers
  36. Child Process

  37. Prefer Not To Use Child Process • Server running on

    specific hardware • Bounded amount of CPU • Usually , each process will be mapped to a CPU • Multiple requests to your server - many processes • Will not scale
  38. Worker Threads • Available since 10.5.0 • Enable the use

    of threads to execute JavaScript in Parallel • One process, Multiple threads, one event loop per thread, One JS engine per thread, one Node.js instance per thread
  39. Demo - Brain.js With Worker Threads

  40. Scale Up With Queues

  41. Queues VS Worker Threads • Queues Are Better for scale

    up • Worker threads limit you to the current machine’s resources • Can use Multiple CPUs from multiple machines while scaling up
  42. Questions ?

  43. • Twitter: @SternTwena