Simple General Regression Neural Network for NodeJS
With and In-Built CSV Parser
## Description This is a NodeJS module to use GRNN to predict given a training data.
Check out the Wikipedia page to find out more about GRNN or the beginner stuffs here.
Applications of this Network can be found here .
Input Parameters
Required
double train_x : 2d array of n rows(training size) and m columns(features)
double train_y : 1d array of size n (actual output correspondng to each training input)
double test_x : 2d array of n1 rows(testing size) and m columns(features)
double test_y : 1d array of size n (actual output correspondng to each testing input)
double input : 1d array of size m (input data whose Y needs to be predicted)
double sigma : the value of sigma in the Radial Basis Function :: Standard Deviation
boolean normalize : whether to normalize train_x or not (generally normalization of training samples gives better predictions)
Functions
predict(input) - Returns predicted value of given input
mse() - Returns the Mean Squared Error for the given input
Variables
ypred[] - Array which have the predicted values for test input data
optimal_sigma - Value of Optimal Sigma ( Minimum MSE ) -- Must be used after calling mse() function
How to Use ? (Example)
Step 1 : Install module via npm
> npm install grnn
Step 2: Import module and use as follows
Or you can use it in your own code
const grnn = ; const train_x = 1 2 5 6 10 11 train_y = 3 7 12 input = 55 65 sigma = 216 normalize = true;const test_x = 88 98 13 14;const test_y = 108 15;const gr = train_x train_y sigma normalize test_x test_y;const pred = gr;const mse = gr;console;console;console;console;
If you are using CSV parser from file to load data
Here is a snapshot of a sample data.
Note that the Variable to be Predicted must be in the "LAST COLUMN" of the csv file.
Here's a sample code to use the built-in CSV parser
const grnn = ;let gr = ; // initialize constructor with no parametersconst path="..../data.csv" // path to csv file header=true; // if your data contain headersconst data = gr;const train_x test_x train_y test_y } = gr; // attribute names are train_x, test_x, train_y, test_ygr = train_x train_y 01180 false test_x test_y; // initialized with actual parametersconst mse = gr;console;console;console;