Applied Math & Computer Science Lab
Data Analysis, Optimization & Mathematical Modeling, Artificial Intelligence, Neural Net For Everyday Life Applications
AI/Data Mining Links Online Free Courses Online Bookstore AMCSL Forum Submit Link New Additions Archive
Practical Data Mining Courses      Get Certificate of Completion Now for Free   
Search the Web:    

Classification with perl module

Perl has many modules for artificial intelligence, data mining and many other tasks. Here we will consider how to implement classification Naive Bayes algorithm with perl module. Ken Williams created module Algorithm::NaiveBayes for Naive Bayes classification.
Originally naive bayes method was released under AI::Categorizer module but later it was extracted in separate module Algorithm::NaiveBayes.


The use of this algorithm is easy, the program below provides example how to do classification. We create object of NaiveBayes, add training instances, train, and then use predict method. The example script is reading data from the file. Each row of this file has attributes of one instance and the last word is category label.
Below is the input file (d.txt)

Predict method returns a hash reference whose keys are the names of labels, and whose values are the score for each label. Scores are between 0 and 1, where 0 means the label doesn't seem to apply to this instance, and 1 means it does. Here is the output from our example:


References


1. Naive Bayes classification- perl script example
2. Algorithm::NaiveBayes - Bayesian prediction of categories