Property

new PropHazards([arg])

Proportional Hazards Model

Example

// import analytics module
var analytics = require('qminer').analytics;
// create a Proportional Hazard model
var hazard = new analytics.PropHazards();

Parameter

Name Type Optional Description

arg

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

Yes

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

Property

weights

The models weights. Type module:la.Vector.

Example

// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create the Proportional Hazards model
var hazards = new analytics.PropHazards();
// get the weights
var weights = hazards.weights;

Methods

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

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 Proportional Hazards model
var hazards = new analytics.PropHazards();
// 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 used, fit the model
if (require('qminer').flags.blas) {
    hazards.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.PropHazardsB Self. The model has been updated.

getParams() → module:analytics~hazardModelParam

Gets the parameters of the model.

Example

// import analytics module
var analytics = require('qminer').analytics;
// create a Proportional Hazard model
var hazard = new analytics.PropHazards({ lambda: 5 });
// get the parameters of the model
var param = hazard.getParams();
Returns

module:analytics~hazardModelParamB 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 Proportional Hazards model
var hazards = new analytics.PropHazards();
// create the input matrix and vector for fitting the model
var mat = new la.Matrix([[1, 1], [1, -1]]);
var vec = new la.Vector([3, 3]);
// if openblas used, fit the model and get the prediction
if (require('qminer').flags.blas) {
    // fit the model
    hazards.fit(mat, vec);
    // create a vector for the prediction
     var test = new la.Vector([1, 2]);
    // predict the value
    var prediction = hazards.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 Proportional Hazards model
var hazards = new analytics.PropHazards();
// 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 used, fit the model
if (require('qminer').flags.blas) {
    hazards.fit(mat, vec);
};
// create an output stream and save the model
var fout = fs.openWrite('hazards_example.bin');
hazards.save(fout);
fout.close();
// create input stream
var fin = fs.openRead('hazards_example.bin');
// create a Proportional Hazards object that loads the model and parameters from input stream
var hazards2 = new analytics.PropHazards(fin);

Parameter

Name Type Optional Description

fout

module:fs.FOut

 

The output stream.

Returns

module:fs.FOutB The output stream fout.

setParams(params) → module:analytics.PropHazards

Sets the parameters of the model.

Example

// import analytics module
var analytics = require('qminer').analytics;
// create a Proportional Hazard model
var hazard = new analytics.PropHazards({ lambda: 5 });
// set the parameters of the model
hazard.setParams({ lambda: 10 });

Parameter

Name Type Optional Description

params

module:analytics~hazardModelParam

 

The parameters given to the model.

Returns

module:analytics.PropHazardsB Self. The model parameters have been updated.