https://github.com/mannasoumya/grnn
basic and simple General Regression Neural Network for NodeJS
https://github.com/mannasoumya/grnn
javascript learning machine-learning machine-learning-algorithms machinelearning neural-network neural-networks node-js node-module nodejs prediction prediction-algorithm prediction-model radial-basis-function regression regression-algorithms regression-models
Last synced: about 2 months ago
JSON representation
basic and simple General Regression Neural Network for NodeJS
- Host: GitHub
- URL: https://github.com/mannasoumya/grnn
- Owner: mannasoumya
- License: mit
- Created: 2019-10-11T08:36:56.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-11-06T08:33:24.000Z (over 3 years ago)
- Last Synced: 2025-02-08T06:34:56.648Z (4 months ago)
- Topics: javascript, learning, machine-learning, machine-learning-algorithms, machinelearning, neural-network, neural-networks, node-js, node-module, nodejs, prediction, prediction-algorithm, prediction-model, radial-basis-function, regression, regression-algorithms, regression-models
- Language: JavaScript
- Size: 51.8 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple General Regression Neural Network for NodeJS
### (With an In-Built CSV Parser)
[](https://www.npmjs.com/package/grnn)
## Description
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.
##### (This script has no external dependencies)
### 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 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)### 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 : Clone repository
```shell
> git clone https://github.com/mannasoumya/grnn.git
```
#### Or### Step 1 : Install Via npm
```shell
> npm install grnn
```
### Step 2: Import module and use as follows
Or you can use it in your own code
```javascript
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);
```
### 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```javascript
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)));
```Please contribute and raise issues. Pull requests are welcome.