bernoullinbfit

Applies Bernoulli Naïve Bayes model on the input data to compute parameters used for classification. Bernoulli Naïve Bayes is a probabilistic learning method which is used for classification. It assumes that each variable is independent of each other (Naïve assumption) and the input variables have binary values which is an indicator of event.

Attention: Available only with Twin Activate commercial edition.

Syntax

parameters = bernoullinbfit(X,y)

parameters = bernoullinbfit(X,y,options)

Inputs

X
Training data.
Type: double
Dimension: vector | matrix
y
Target values.
Type: double
Dimension: vector | matrix
options
Type: struct
alpha
Laplacian smoothing parameter (default: 1). It’s added to each feature to get rid of zeros in the summation of features.
Type: integer
Dimension: scalar
binarize_threshold
Threshold value above which are converted to 1 and rest are converted to 0 to transform input features into binary values (default: 0).
Type: double | integer
Dimension: scalar

Outputs

parameters
Contains all the values passed to bernoulliFit 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
Matrix containing summation of each feature for each class where ith row represents the summation of each feature of ith class.
Type: double
Dimension: matrix
params
Matrix containing conditional probability of each feature for each class. ith row represents the conditional probability of features in ith class.
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 bernoullinbfit with options

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

X_test = X(3, :);

options = struct;
options.binarize_threshold = 0;
options.alpha = 1;

parameters = bernoullinbfit(X, y, options);
> parameters
parameters = struct [
  alpha: 1
  binarize_threshold: 0
  feature_count: [Matrix] 2 x 4
  2  1  2  2
  2  1  3  1
  labels: [Matrix] 2 x 1
  1
  2
  n_features: 4
  n_samples: 3
  params: [Matrix] 2 x 4
  0.66667  0.33333  0.66667  0.66667
  0.50000  0.25000  0.75000  0.25000
  prior: [Matrix] 2 x 1
  -1.09861
  -0.40547
]

Comments

Output 'parameters' should be passed as input to bernoullinbpredict function.