naive_bayes.MultinomialNB

Multinomial naive bayes machine learning algorithm The Naive is an intuitive method that uses probabilistic of each attribute being in each class to make a prediction. It uses multinomial function to estimate probability of a given class.

Usage

import { MultinomialNB } from 'machinelearn/naive_bayes';

const nb = new MultinomialNB();
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

Fit date to build Gaussian Distribution summary

Defined in naive_bayes/multinomial.ts:48

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nulltraining values
ynumber[] or string[]nulltarget values

Returns:

void

λ fromJSON

Restore the model from states

Defined in naive_bayes/multinomial.ts:103

Parameters:

ParamTypeDefaultDescription
options.classCategoriesT[]nullList of unique class categories
options.multinomialDistnumber[][]nullMultinomial distribution values over classes
options.priorProbabilitynumber[]nullLearned prior class probabilities

Returns:

void

λ predict

Predict multiple rows

Defined in naive_bayes/multinomial.ts:62

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nullvalues to predict in Matrix format

Returns:

T[]

λ toJSON

Returns a model checkpoint

Defined in naive_bayes/multinomial.ts:75

Returns:

ParamTypeDescription
classCategoriesT[]List of class categories