Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. const SimpleLinearRegression = ML.SimpleLinearRegression;
  2.  
  3. // training data
  4. const x = [1,2,3]; // inputs
  5. const y = [2,4,6]; // outputs
  6.  
  7. // training
  8. const model = new ML.SimpleLinearRegression(x, y);
  9.  
  10. // model details
  11. console.log(`
  12. Slope: ${model.slope}
  13. Intercept: ${model.intercept}
  14. Function: ${model.toString()}
  15. `);
  16.  
  17. // predicting
  18. for(let i=1; i < 13; i++){
  19. const prediction = model.predict(i);
  20. console.log(`2x${i} = ${prediction}`)
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement