Skip to content

Instantly share code, notes, and snippets.

@maasencioh
Last active August 4, 2016 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maasencioh/a0a19e1cfb5ea6013b457e424d8245c8 to your computer and use it in GitHub Desktop.
Save maasencioh/a0a19e1cfb5ea6013b457e424d8245c8 to your computer and use it in GitHub Desktop.
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);
@maasencioh
Copy link
Author

@maasencioh
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment