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

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

Yes

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

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

(module:la.Vector or module:la.Matrix)

 

The input data.

Y

(module:la.Vector or module:la.Matrix)

 

The output data.
If X and Y are both module:la.Vector, then the fitting is in online mode.
If X and Y are both module:la.Matrix, then the fitting is in batch mode.

Returns

module:analytics.NNetB 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~nnetParamB 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

module:la.Vector

 

The prediction vector.

Returns

module:la.VectorB The prediction of vector vec.

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

module:fs.FOut

 

The output stream.

Returns

module:fs.FOutB The output stream fout.

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.NNetB Self. The model parameters have been updated.