multinomialnbfit

Multinomial Naïve Bayes classifier.

Syntax

parameters = multinomialnbfit(X,y)

parameters = multinomialnbfit(X,y,options)

Inputs

X
Training data.
Type: double
Dimension: vector | matrix
y
Target values.
Type: double
Dimension: vector | matrix
options
Type: struct
alpha
Additive (Laplace) smoothing parameter (0 for no smoothing). Default: 1
Type: double
Dimension: scalar

Outputs

parameters
Contains all the values passed to multinomialFit method as options. Additionally it has below key-value pairs.
Type: struct
scorer
Function handle pointing to 'accuracy' function.
Type: function handle
labels
Unique labels in training data.
Type: double
Dimension: vector
prior
Probability of each class.
Type: double
Dimension: cell
feature_count
Feature counts for each class. Feature wise summing up the data for each class. It’s used for prediction and computing params.
Type: double
Dimension: matrix
params
Parameters computed by multinomialFit to be used by prediction function.
Type: double
Dimension: matrix
n_samples
Number of rows in the training data.
Type: integer
Dimension: scalar
n_features
Number of columns in the training data.
Type: integer
Dimension: scalar

Example

Usage of multinomialnbfit

X = [2, 1, 0, 0, 0, 0;
	2, 0, 1, 0, 0, 0;
	1, 0, 0, 1, 0, 0;
	1, 0, 0, 0, 1, 1
];
y = [1, 1, 1, 0]';

X_test = [3, 0, 0, 0, 1, 1;
		   0, 1, 1, 0, 1, 1
];

options = struct;
options.alpha = 0;
parameters = multinomialnbfit(X, y, options)
parameters = struct [
  alpha: 0
  feature_count: [Matrix] 2 x 6
  1  0  0  0  1  1
  5  1  1  1  0  0
  labels: [Matrix] 2 x 1
  0
  1
  n_features: 6
  n_samples: 4
  ...

Comments

User need not assume that the probability values estimated are between 0 and 1. Some transformations are made to accommodate multiplication of smaller fraction values which won’t lead to underflow errors. Output 'parameters' should be passed as input to multinomialnbpredict function.