analytics. Sigmoid
Source: analyticsdoc.
new Sigmoid([arg])
Sigmoid function (y = 1/[1 + exp[-A*x + B]]
) fitted on decision function to mimic.
Example
// import modules
la = require('qminer').la;
analytics = require('qminer').analytics;
// create a new model
var sigmoid = new analytics.Sigmoid();
// generate a random predictions
var x = new la.Vector([0.5, 2.3, -0.1, 0.5, -7.3, 1.2]);
// generate a random labels
var y = new la.Vector([1, 1, -1, 1, -1, -1]);
// fit model
sigmoid.fit(x, y);
// get predictions
var pred1 = sigmoid.predict(1.2);
var pred2 = sigmoid.predict(-1.2);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
arg |
Yes |
Construction arguments. |
Methods
decisionFunction(x) → (number or module:la.Vector)
Returns the expected response for the provided feature vector.
Example
// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create the Sigmoid model
var s = new analytics.Sigmoid();
// create the predicted values and the binary labels
var X = new la.Vector([-3, -2, -1, 1, 2, 3]);
var y = new la.Vector([-1, -1, -1, 1, 1, 1]);
// fit the model
s.fit(X, y);
// predict the probability of the value 0 on this model
// returns 0.5
var prediction = s.decisionFunction(0.5);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
x |
(number or module:la.Vector) |
|
Prediction score. |
- Returns
-
(number or module:la.Vector)
B
1. Ifx
is a number, returns a normalized prediction score,
2. ifx
is a module:la.Vector, returns a vector of normalized prediction scores.
fit(x, y) → module:analytics.Sigmoid
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 Sigmoid model
var s = new analytics.Sigmoid();
// create the predicted values and the binary labels
var X = new la.Vector([-3, -2, -1, 1, 2, 3]);
var y = new la.Vector([-1, -1, -1, 1, 1, 1]);
// fit the model
// changes the internal A and B values of the model
s.fit(X, y);
Parameters
Name | Type | Optional | Description |
---|---|---|---|
x |
|
Predicted values (e.g. using module:analytics.SVR). |
|
y |
|
Actual binary labels: 1 or -1. |
- Returns
-
module:analytics.Sigmoid
B Self. The model has been created.
getModel() → Object
Gets the model.
Example
// import analytics module
var analytics = require('qminer').analytics;
// create the Sigmoid model
var s = new analytics.Sigmoid();
// get the model parameters
// returns a Json object { A: 0, B: 0 }
var model = s.getModel();
- Returns
-
Object
B The objectsigModel
containing the properties:
sigModel.A
- First value of the Sigmoid model,
sigModel.B
- Second value of the Sigmoid model.
getParams() → Object
Get the parameters. It doesn't do anything, it's only for consistency for constructing pipeline.
Example
// import analytics module
var analytics = require('qminer').analytics;
// create the Sigmoid model
var s = new analytics.Sigmoid();
// get the parameters
// returns an empty object
var param = s.getParams();
- Returns
-
Object
B An empty object.
predict(x) → (number or module:la.Vector)
Returns the expected response for the provided feature vector.
Example
// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create the Sigmoid model
var s = new analytics.Sigmoid();
// create the predicted values and the binary labels
var X = new la.Vector([-3, -2, -1, 1, 2, 3]);
var y = new la.Vector([-1, -1, -1, 1, 1, 1]);
// fit the model
s.fit(X, y);
// predict the probability of the value 0 on this model
// returns 0.5
var prediction = s.predict(0.5);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
x |
(number or module:la.Vector) |
|
Prediction score. |
- Returns
-
(number or module:la.Vector)
B
1. Ifx
is a number, returns a normalized prediction score,
2. ifx
is a module:la.Vector, returns a vector of normalized prediction scores.
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 Sigmoid model
var s = new analytics.Sigmoid();
// create the predicted values and the binary labels
var X = new la.Vector([-3, -2, -1, 1, 2, 3]);
var y = new la.Vector([-1, -1, -1, 1, 1, 1]);
// fit the model
s.fit(X, y);
// create an output stream object and save the model
var fout = fs.openWrite('sigmoid_example.bin');
s.save(fout);
fout.close();
// create a new Sigmoid model by loading the model
var fin = fs.openRead('sigmoid_example.bin');
var s2 = new analytics.Sigmoid(fin);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
fout |
|
Output stream. |
- Returns
-
module:fs.FOut
B The output streamfout
.
setParams(arg) → module:analytics.Sigmoid
Sets the parameters. It doesn't do anything, it's only for consistency for constructing pipeline.
Example
// import analytics module
var analytics = require('qminer').analytics;
// create the Sigmoid model
var s = new analytics.Sigmoid();
// set the parameters
// doesn't change the model
s.setParams({});
Parameter
Name | Type | Optional | Description |
---|---|---|---|
arg |
Object |
|
Json object. |
- Returns
-
module:analytics.Sigmoid
B Self. Nothing changes.