Linear regression is a great tool for estimating values based on linear data (dyuh!) Coupled with hourly load statistics, it can be used for predicting required resources based on future demand of cloud services, or consolidating existing demand.
Checkout Wikipedia for more information about linear regression and least squares.
This library depends on Sylvester, another library used for matrix math.
Tested to work against Internet Explorer 9+, Safari 5.0.5+, Google Chrome 5+, and Firefox 4+!
Development Version (0.1.0) — 8.0 KiB, uncompressed with comments.
Production Version (0.1.0) — 803 bytes, minified and gzipped.
The regression module may be called with an optional set of options:
samples
— Default 25, older values will be popped off as new ones are pushed in past this limit.enough
— Default 3, threshold used to determine if there is enough data to calculate a linear regression.
Example
var regression = require('regression');
var sample = regression({samples: 100, enough: 10});
Push a sample of data into the data set. The data must have the same keys every time, otherwise the behavior is undefined.
Example
setInterval(function () {
sample.update(process.memoryUsage().heapUsed, {
active: Application.getActivePlayers(),
idle: Application.getIdlePlayers()
});
}, 1000);
Calculate the coefficient of a key. This will return false
if there is not enough data.
Example
console.log('application overhead', sample.coef());
console.log('active player memory usage', sample.coef('active'));
console.log('idle player memory usage', sample.coef('idle'));
Calculate the predicted value of the passed data based on the linear regression from the previously collected data. This will return false
if there is not enough data.
Example
console.log(
'estimate memory usage for 1337 active players & 999 idle',
sample.calc({active: 1337, idle: 999})
);
Return the number of samples in the data set.
Test if there is enough data to calculate linear regression.
Remove all the data.
(The MIT License)
Copyright (C) 2012 Ryan Munro munro.github@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.