analytics. PropHazards
Source: analyticsdoc.
Proportional Hazards Model with a constant hazard function. Uses Newtons method to compute the weights. Before use: QMiner must be built with the OpenBLAS library.
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 |
Yes |
Construction arguments. There are two ways of constructing:
|
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 |
|
The column matrix which stores the feature vectors. |
|
y |
|
The response variable. |
|
eps |
number |
Yes |
The epsilon used for convergence. |
- Returns
-
module:analytics.PropHazards
B 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~hazardModelParam
B 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 |
|
The feature vector. |
- Returns
-
number
B 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 |
|
The output stream. |
- Returns
-
module:fs.FOut
B The output streamfout
.
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 |
|
The parameters given to the model. |
- Returns
-
module:analytics.PropHazards
B Self. The model parameters have been updated.