This is a NodeJS module to use GRNN to predict given a training data.
The "npm" package can be found here.
Check out the Wikipedia page to find out more about GRNN or the beginner stuffs here.
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 n1 (actual output correspondng to each testing input)
double input : 1d array of size n (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)
predict(input) - Returns predicted value of given input
mse() - Returns the Mean Squared Error for the given input
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
> git clone https://github.com/mannasoumya/grnn.git
> npm install grnn
Or you can use it in your own code
const grnn = require("./grnn"); // assuming cloned repo in cwd; otherwise use appropriate path to grnn.js
// const grnn = require("grnn"); -- > if installed via npm
const train_x = [[1, 2], [5, 6], [10, 11]],
train_y = [3, 7, 12],
input = [5.5, 6.5],
sigma = 2.16,
normalize = true;
const test_x = [[8.8, 9.8], [13, 14]];
const test_y = [10.8, 15];
const gr = new grnn(train_x, train_y, sigma, normalize, test_x, test_y);
const pred = gr.predict(input);
const mse = gr.mse();
console.log("Prediction: " + pred);
console.log("MSE: " + mse);
console.log("Optimal Value of Sigma: " + gr.optimal_sigma);
console.log("Predicted Values against Test: "+ gr.ypred);
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.
const grnn = require("./grnn"); // assuming cloned repo in cwd; otherwise use appropriate path to grnn.js
// const grnn = require("grnn"); -- > if installed via npm
let gr = new grnn(); // initialize constructor with no parameters
const path="..../data.csv", // path to csv file
header=true; // if your data contain headers
const data = gr.parseCSV(path, header);
const { train_x,
test_x,
train_y,
test_y } = gr.split_test_train(data); // attribute names are train_x, test_x, train_y, test_y
gr = new grnn(train_x, train_y, 0.1180, false, test_x, test_y); // initialized with actual parameters
const mse = gr.mse();
console.log("MSE: " + mse);
console.log("Optimal Value of Sigma: " + gr.optimal_sigma);
console.log("Predicted Values against Test: "+gr.ypred.map(el=>el.toPrecision(4)));