Property

new LogReg([arg])

Logistic regression model.

Example

// import analytics module
var analytics = require('qminer').analytics;
// create the Logistic Regression model
var logreg = new analytics.LogReg({ lambda: 2 });
// create the input matrix and vector for fitting the model
var mat = new la.Matrix([[1, 0, -1, 0], [0, 1, 0, -1]]);
var vec = new la.Vector([1, 0, -1, -2]);
// if OpenBLAS is used, fit the model
if (require('qminer').flags.blas) {
    logreg.fit(mat, vec);
    // create the vector for the prediction
    var test = new la.Vector([1, 1]);
    // get the prediction
    var prediction = logreg.predict(test);
}

Parameter

Name Type Optional Description

arg

(module:analytics~logisticRegParam or module:fs.FIn)

Yes

Construction arguments. There are two ways of constructing:
1. Using the module:analytics~logisticRegParam object,
2. using the file input stream module:fs.FIn.

Property

weights

Gives the weights of the model. Type module:la.Vector.

Example

// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create the logistic regression model
var logreg = new analytics.LogReg();
// get the weights of the model
var weights = logreg.weights;

Methods

fit(X, y[, eps]) → module:analytics.LogReg

Fits a column matrix of feature vectors X onto the response variable y.

Example

// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create the logistic regression model
var logreg = new analytics.LogReg();
// create the input matrix and vector for fitting the model
var mat = new la.Matrix([[1, 0, -1, 0], [0, 1, 0, -1]]);
var vec = new la.Vector([1, 0, -1, -2]);
// if OpenBLAS is used, fit the model
if (require('qminer').flags.blas) {
    logreg.fit(mat, vec);
}

Parameters

Name Type Optional Description

X

module:la.Matrix

 

the column matrix which stores the feature vectors.

y

module:la.Vector

 

the response variable.

eps

number

Yes

the epsilon used for convergence.

Returns

module:analytics.LogRegB Self. The model has been updated.

getParams() → module:analytics~logisticRegParam

Gets the parameters.

Example

// import analytics module
var analytics = require('qminer').analytics;
// create the Logistic Regression model
var logreg = new analytics.LogReg({ lambda: 10 });
// get the parameters of the model
var param = logreg.getParams(); // returns { lambda: 10, intercept: false }
Returns

module:analytics~logisticRegParamB The parameters of the model.

predict(x) → number

Returns the expected response for the provided feature vector.

Example

// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create the logistic regression model
var logreg = new analytics.LogReg();
// create the input matrix and vector for fitting the model
var mat = new la.Matrix([[1, 0, -1, 0], [0, 1, 0, -1]]);
var vec = new la.Vector([1, 0, -1, -2]);
// if openblas is used, fit the model and predict the value
if (require('qminer').flags.blas) {
    // fit the model
    logreg.fit(mat, vec);
    // create the vector for the prediction
    var test = new la.Vector([1, 1]);
    // get the prediction
    var prediction = logreg.predict(test);
};

Parameter

Name Type Optional Description

x

module:la.Vector

 

the feature vector.

Returns

numberB the expected response.

save(fout) → module:fs.FOut

Saves the model into the output stream.

Example

// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
var fs = require('qminer').fs;
// create the logistic regression model
var logreg = new analytics.LogReg();
// create the input matrix and vector for fitting the model
var mat = new la.Matrix([[1, 0, -1, 0], [0, 1, 0, -1]]);
var vec = new la.Vector([1, 0, -1, -2]);
// if openblas is used, fit the model
if (require('qminer').flags.blas) {
    logreg.fit(mat, vec);
};
// create an output stream object and save the model
var fout = fs.openWrite('logreg_example.bin');
logreg.save(fout);
fout.close();
// create input stream
var fin = fs.openRead('logreg_example.bin');
// create a Logistic Regression object that loads the model and parameters from input stream
var logreg2 = new analytics.LogReg(fin);

Parameter

Name Type Optional Description

fout

module:fs.FOut

 

the output stream.

Returns

module:fs.FOutB The output stream fout.

setParams(param) → module:analytics.LogReg

Set the parameters.

Example

// import analytics module
var analytics = require('qminer').analytics;
// create a logistic regression model
var logreg = new analytics.LogReg({ lambda: 10 });
// set the parameters of the model
logreg.setParams({ lambda: 1 });

Parameter

Name Type Optional Description

param

module:analytics~logisticRegParam

 

The new parameters.

Returns

module:analytics.LogRegB Self. The parameters are updated.