Last active
August 4, 2016 20:59
-
-
Save maasencioh/a0a19e1cfb5ea6013b457e424d8245c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SLR = ML.Regression.SLR; | |
var inputs = [10, 20, 50, 75, 80]; | |
var outputs = [30, 50, 80, 100, 130]; | |
var regression = new SLR(inputs, outputs); | |
var y = regression.predict(85); | |
var min = 1000000; | |
var max = -100000; | |
for (var i = 0; i < inputs.length; i++) { | |
if (inputs[i] < min) { | |
min = inputs[i]; | |
} | |
if (inputs[i] > max) { | |
max = inputs[i]; | |
} | |
} | |
var y1 = regression.coefficients[0] + regression.coefficients[1] * min; | |
var y2 = regression.coefficients[0] + regression.coefficients[1] * max; | |
var linea = [[min, y1], [max, y2]]; | |
var chart = { | |
"title": "My chart", | |
"data": [ | |
{ | |
"x": inputs, | |
"y": outputs | |
} | |
] | |
}; | |
set ('xy', chart); | |
set('linea', linea); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.lactame.com/lib/ml/1.1.1/ml.js