13.07.2015 Views

Data Mining: Practical Machine Learning Tools and ... - LIDeCC

Data Mining: Practical Machine Learning Tools and ... - LIDeCC

Data Mining: Practical Machine Learning Tools and ... - LIDeCC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

14.2 GOING THROUGH THE CODE 463/*** Java program for classifying text messages into two classes.*/import weka.core.Attribute;import weka.core.Instance;import weka.core.Instances;import weka.core.FastVector;import weka.core.Utils;import weka.classifiers.Classifier;import weka.classifiers.trees.J48;import weka.filters.Filter;import weka.filters.unsupervised.attribute.StringToWordVector;import java.io.*;public class MessageClassifier implements Serializable {/* The training data gathered so far. */private Instances m_<strong>Data</strong> = null;/* The filter used to generate the word counts. */private StringToWordVector m_Filter = new StringToWordVector();/* The actual classifier. */private Classifier m_Classifier = new J48();/* Whether the model is up to date. */private boolean m_UpToDate;/*** Constructs empty training dataset.*/public MessageClassifier() throws Exception {String nameOf<strong>Data</strong>set = "MessageClassificationProblem";// Create vector of attributes.FastVector attributes = new FastVector(2);// Add attribute for holding messages.attributes.addElement(new Attribute("Message", (FastVector)null));Figure 14.1 Source code for the message classifier.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!