A classification class. More...
Public Member Functions | |
void | Classify (const Matrix &test_data, Vector *results) |
Given a bunch of data points, this function evaluates the class of each of those data points, and puts it in the vector 'results'. | |
void | InitTrain (const Matrix &data, datanode *nbc_module) |
The function that initializes the classifier as per the input and then trains it by calculating the sample mean and variances. | |
Friends | |
class | TestClassSimpleNBC |
A classification class.
The class labels are assumed to be positive integers - 0,1,2,....
This class trains on the data by calculating the sample mean and variance of the features with respect to each of the labels, and also the class probabilities.
Mathematically, it computes P(X_i = x_i | Y = y_j) for each feature X_i for each of the labels y_j. Alongwith this, it also computes the classs probabilities P( Y = y_j)
For classifying a data point (x_1, x_2, ..., x_n), it computes the following: arg max_y(P(Y = y)*P(X_1 = x_1 | Y = y) * ... * P(X_n = x_n | Y = y))
Example use:
SimpleNaiveBayesClassifier nbc; Matrix training_data, testing_data; datanode *nbc_module = fx_submodule(NULL,"nbc","nbc"); Vector results; nbc.InitTrain(training_data, nbc_module); nbc.Classify(testing_data, &results);
Definition at line 106 of file simple_nbc.h.
void SimpleNaiveBayesClassifier::Classify | ( | const Matrix & | test_data, | |
Vector * | results | |||
) | [inline] |
Given a bunch of data points, this function evaluates the class of each of those data points, and puts it in the vector 'results'.
Matrix test_data; // each column is a test point Vector results; ... nbc.Classify(test_data, &results);
Definition at line 215 of file simple_nbc.h.
References GenVector< T >::Copy(), and fx_result_int().
void SimpleNaiveBayesClassifier::InitTrain | ( | const Matrix & | data, | |
datanode * | nbc_module | |||
) | [inline] |
The function that initializes the classifier as per the input and then trains it by calculating the sample mean and variances.
Example use:
Matrix training_data, testing_data; datanode *nbc_module = fx_submodule(NULL,"nbc","nbc"); .... nbc.InitTrain(training_data, nbc_module);
Definition at line 149 of file simple_nbc.h.
References fx_param_int_req(), fx_result_int(), ArrayList< TElem >::Init(), and ArrayList< TElem >::Resize().