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

Introduction To Machine Learning In Node.js

Tamar Twena-Stern
October 23, 2019
130

Introduction To Machine Learning In Node.js

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

Tamar Twena-Stern

October 23, 2019
Tweet

Transcript

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

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

    3 kids • Loves to play my violin • Javascript Israel community leader
  3. 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
  4. 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.
  5. 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
  6. 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
  7. Step 3 - Evaluate How Accurate Are The Predictions Of

    Your Model Error = abs(actual−predicted) Number Of Testing Subjects
  8. TensorFlow.js • Open-source • Training and deploying machine learning models.

    • Main operations relates to vector and matrices • Basic unit - Tensor
  9. 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
  10. Neural Networks In A Nutshell • Set of Algorithms •

    Modelled loosely after the human brain • Designed to recognise patterns
  11. Main Problems • Machine Learning algorithms are CPU intensive •

    Matrix manipulations can be more efficient • Not much richness of libraries
  12. 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
  13. CPU Intensive Tasks In Node.js • Fork Another Process •

    Worker Threads • Scale Up with Queues + pack our application with containers
  14. 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
  15. 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
  16. 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