Documentation‎ > ‎

8. Classifiers

Introduction


TIPL includes a small machine learning library that provides several useful classifiers, including Naive Bayes, logistic regression, Adaboost, K-nearest neighbor.

Naive Bayes


    // declare a Naive Bayes classifier   
    naive_bayes<double,unsigned char> NB;
    

Logistic regression


    // declare a logistic regression classifier
    logistic_regression<double,unsigned char> LR(0.1,0.0001);

Adaboost

    // Boosting using decision stump
    ada_boost<decision_stump<double,unsigned char> > boosted_decision1((size_t)10);
    

K-nearest neighbor


    nearest_neighbor<double,unsigned char,weight_function_average> NN(1);

Parzen density estimator

    parzen_estimator<double,unsigned char,weight_function_average> PE(1.0);

Decision tree

    decision_tree<double,unsigned char> DE(100,0.9);

Training data


// prepare learning data
    // feature type: double
    // classification type: unsigned char 
    training_data<double,unsigned char> data;
 
    // 1000 training data
    data.features.resize(1000);
    data.classification.resize(1000);
    unsigned int 
attribute_dimension = 3;
    for(int index = 0;index < 1000;++index)
    {
        
data.features[index].resize(attribute_dimension);
        
// input the features
        data.features[index][0] = 1.0;  
        data.features[index][1] = 1.0;  
        data.features[index][2] = 1.0;  
        data.
classification[index] = 0;
    }


Training


// train the Nearest neighbor classifier using all dataset
    NN.learn(data.features.begin(),

                  data.features.end(),
                  
attribute_dimension
,
                  data.classification.begin());

Comments