Skip to content

Instantly share code, notes, and snippets.

@ohmrefresh
Last active August 29, 2015 14:21
Show Gist options
  • Save ohmrefresh/8d57a72455e1525e7f56 to your computer and use it in GitHub Desktop.
Save ohmrefresh/8d57a72455e1525e7f56 to your computer and use it in GitHub Desktop.
Weka Evaluation Classify #RandomForest #Android
InputStream is =getResources().openRawResource(R.raw.r4_reference); //arff
BufferedReader datafile = new BufferedReader(new InputStreamReader(is));
try {
Instances m_Training = new Instances(datafile);
m_Training.setClassIndex(m_Training.numAttributes() - 1);
Filter m_Filter = ((Filter)Class.forName("weka.filters.unsupervised.instance.Randomize").newInstance());
m_Filter.setInputFormat(m_Training);
Instances localInstances = Filter.useFilter(m_Training, m_Filter);
Classifier m_Classifier = Classifier.forName("weka.classifiers.trees.RandomForest", null);
m_Classifier.buildClassifier(localInstances);
Evaluation m_Evaluation = new Evaluation(localInstances);
m_Evaluation.crossValidateModel(m_Classifier, localInstances, 10, m_Training.getRandomNumberGenerator(1L), new Object[0]);
Log.e("Detail", m_Evaluation.toClassDetailsString());
Log.e("Summary",m_Evaluation.toSummaryString());
Log.e("Result","Correct:"+ m_Evaluation.correct()+":Wrong:"+m_Evaluation.incorrect()+":Correct(%):"+m_Evaluation.pctCorrect());
}catch (Exception e){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment