analytics. NNet
Source: analyticsdoc.
Holds online/offline neural network model.
new NNet([arg])
Neural Network Model.
Example
// import module
var analytics = require('qminer').analytics;
// create a new Neural Networks model
var nnet = new analytics.NNet({ layout: [3, 5, 2], learnRate: 0.2, momentum: 0.6 });
// create the matrices for the fitting of the model
var matIn = new la.Matrix([[1, 0], [0, 1], [1, 1]]);
var matOut = new la.Matrix([[-1, 8], [-3, -3]]);
// fit the model
nnet.fit(matIn, matOut);
// create the vector for the prediction
var test = new la.Vector([1, 1, 2]);
// predict the value of the vector
var prediction = nnet.predict(test);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
arg |
Yes |
Construction arguments. There are two ways of constructing:
|
Methods
fit(X, Y) → module:analytics.NNet
Fits the model.
Example
// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a Neural Networks model
var nnet = new analytics.NNet({ layout: [2, 3, 4] });
// create the matrices for the fitting of the model
var matIn = new la.Matrix([[1, 0], [0, 1]]);
var matOut = new la.Matrix([[1, 1], [1, 2], [-1, 8], [-3, -3]]);
// fit the model
nnet.fit(matIn, matOut);
Parameters
Name | Type | Optional | Description |
---|---|---|---|
X |
|
The input data. |
|
Y |
|
The output data.
|
- Returns
-
module:analytics.NNet
B Self. The model has been updated.
getParams() → module:analytics~nnetParam
Get the parameters of the model.
Example
// import analytics module
var analytics = require('qminer').analytics;
// create a Neural Networks model
var nnet = new analytics.NNet();
// get the parameters
var params = nnet.getParams();
- Returns
-
module:analytics~nnetParam
B The constructor parameters.
predict(vec) → module:la.Vector
Gets the prediction of the vector.
Example
// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a Neural Networks model
var nnet = new analytics.NNet({ layout: [2, 3, 4] });
// create the matrices for the fitting of the model
var matIn = new la.Matrix([[1, 0], [0, 1]]);
var matOut = new la.Matrix([[1, 1], [1, 2], [-1, 8], [-3, -3]]);
// fit the model
nnet.fit(matIn, matOut);
// create the vector for the prediction
var test = new la.Vector([1, 1]);
// predict the value of the vector
var prediction = nnet.predict(test);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
vec |
|
The prediction vector. |
- Returns
-
module:la.Vector
B The prediction of vectorvec
.
save(fout) → module:fs.FOut
Saves the model.
Example
// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
var fs = require('qminer').fs;
// create a Neural Networks model
var nnet = new analytics.NNet({ layout: [2, 3, 4] });
// create the matrices for the fitting of the model
var matIn = new la.Matrix([[1, 0], [0, 1]]);
var matOut = new la.Matrix([[1, 1], [1, 2], [-1, 8], [-3, -3]]);
// fit the model
nnet.fit(matIn, matOut);
// create an output stream object and save the model
var fout = fs.openWrite('nnet_example.bin');
nnet.save(fout);
fout.close();
// load the Neural Network model from the binary
var fin = fs.openRead('nnet_example.bin');
var nnet2 = new analytics.NNet(fin);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
fout |
|
The output stream. |
- Returns
-
module:fs.FOut
B The output streamfout
.
setParams() → module:analytics.NNet
Sets the parameters of the model.
Example
// import analytics module
var analytics = require('qminer').analytics;
// create a Neural Networks model
var nnet = new analytics.NNet();
// set the parameters
nnet.setParams({ learnRate: 1, momentum: 10, layout: [1, 4, 3] });
- Returns
-
module:analytics.NNet
B Self. The model parameters have been updated.