naive_bayes.GaussianNB

The Naive is an intuitive method that uses probabilistic of each attribute being in each class to make a prediction. It uses Gaussian function to estimate probability of a given class.

Usage

import { GaussianNB } from 'machinelearn/naive_bayes';

const nb = new GaussianNB();
const X = [[1, 20], [2, 21], [3, 22], [4, 22]];
const y = [1, 0, 1, 0];
nb.fit({ X, y });
nb.predict({ X: [[1, 20]] }); // returns [ 1 ]

Methods

Methods


λ fit

Defined in naive_bayes/gaussian.ts:33

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nullarray-like or sparse matrix of shape = [nsamples, n_features]
ynumber[] or string[]nullarray-like, shape = [nsamples] or [n_samples, n_outputs]

Returns:

void

λ fromJSON

Restore the model from saved states

Defined in naive_bayes/gaussian.ts:53

Parameters:

ParamTypeDefaultDescription
options.classCategoriesT[]null
options.meannumber[][]null
options.variancenumber[][]null

Returns:

void

λ predict

Defined in naive_bayes/gaussian.ts:44

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nullarray-like, shape = [nsamples, n_features]

Returns:

T[]

λ toJSON

Save the model's states

Defined in naive_bayes/gaussian.ts:79

Returns:

ParamTypeDescription
classCategoriesT[]List of class categories