Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("should make test number 23", function () {
// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
var fs = require('qminer').fs;
// create a new Ridge Regression object
var regmod = new analytics.RidgeReg();
// create the test matrix and vector
var X = new la.Matrix([[1, 2], [1, -1]]);
var y = new la.Vector([3, 3]);
// fit the model with X and y
regmod.fit(X, y);
// create an output stream object and save the model
var fout = fs.openWrite('regmod_example.bin');
regmod.save(fout);
fout.close();
// create a new Ridge Regression model by loading the model
var fin = fs.openRead('regmod_example.bin');
var regmod2 = new analytics.RidgeReg(fin);
});
});
it("should make test number 17", function () {
// import modules
la = require('qminer').la;
analytics = require('qminer').analytics;
// create a new model with gamma = 1.0
var regmod = new analytics.RidgeReg({ gamma: 1.0 });
// generate a random feature matrix
var A = la.randn(10,100);
// generate a random model
var w = la.randn(10);
// generate noise
var n = la.randn(100).multiply(0.01);
// generate responses (model'*data + noise)
var b = A.transpose().multiply(w).plus(n);
// fit model
regmod.fit(A, b);
// compare
// true model
w.print();
// trained model');
regmod.weights.print();
// cosine between the true and the estimated model should be close to 1 if the fit succeeded
it("should make test number 21", function () {
// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new Ridge Regression object
var regmod = new analytics.RidgeReg();
// create the test matrix and vector
var X = new la.Matrix([[1, 2], [1, -1]]);
var y = new la.Vector([3, 3]);
// fit the model with X and y
regmod.fit(X, y);
// create a new vector for the prediction
var vec = new la.Vector([3, 4]);
// create the prediction
// returns the value 10
var prediction = regmod.decisionFunction(vec);
});
});
var la = require('qminer').la;
var fs = require('qminer').fs;
// create a new Ridge Regression object
var regmod = new analytics.RidgeReg();
// create the test matrix and vector
var X = new la.Matrix([[1, 2], [1, -1]]);
var y = new la.Vector([3, 3]);
// fit the model with X and y
regmod.fit(X, y);
// create an output stream object and save the model
var fout = fs.openWrite('regmod_example.bin');
regmod.save(fout);
fout.close();
// create a new Ridge Regression model by loading the model
var fin = fs.openRead('regmod_example.bin');
var regmod2 = new analytics.RidgeReg(fin);
});
});
it("should make test number 79", function () {
// import analytics module
var analytics = require('qminer').analytics;
// create the Ridge Regression model
var regmod = new analytics.RidgeReg();
// get the model
var model = regmod.getModel(); // returns { weights: new require('qminer').la.Vector(); }
});
});
it("should make test number 18", function () {
// import analytics module
var analytics = require('qminer').analytics;
// create a new Ridge Regression object
var regmod = new analytics.RidgeReg({ gamma: 5 });
// get the parameters
// returns a json object { gamma: 5 }
var param = regmod.getParams();
});
});
it("should make test number 22", function () {
// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new Ridge Regression object
var regmod = new analytics.RidgeReg();
// create the test matrix and vector
var X = new la.Matrix([[1, 2], [1, -1]]);
var y = new la.Vector([3, 3]);
// fit the model with X and y
regmod.fit(X, y);
// create a new vector for the prediction
var vec = new la.Vector([3, 4]);
// create the prediction
// returns the value 10
var prediction = regmod.predict(vec);
});
});
it("should make test number 20", function () {
// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new Ridge Regression object
var regmod = new analytics.RidgeReg();
// create the test matrix and vector
var X = new la.Matrix([[1, 2], [1, -1]]);
var y = new la.Vector([3, 3]);
// fit the model with X and y
// the weights of the model are 2, 1
regmod.fit(X, y);
});
});
it("should make test number 19", function () {
// import analytics module
var analytics = require('qminer').analytics;
// create a new Ridge Regression object
var regmod = new analytics.RidgeReg({ gamma: 5 });
// set the parameters of the object
var param = regmod.setParams({ gamma: 10 });
});
});
assert.doesNotThrow(function () {
var reg = new analytics.RidgeReg(1.0);
});
})