-
Notifications
You must be signed in to change notification settings - Fork 0
/
QHClassifier.cs
35 lines (33 loc) · 1.34 KB
/
QHClassifier.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
class QHClassifier
{
public static void Main(String[] args)
{
try
{
// Load the model
java.io.ObjectInputStream stream = new java.io.ObjectInputStream(new java.io.FileInputStream("iris_j48.model"));
weka.classifiers.Classifier qhClassifier = (weka.classifiers.Classifier)stream.readObject();
stream.close();
// This model was trained on 66% of instances from the iris dataset. Test the model on remaining 34% instances.
weka.core.Instances insts = new weka.core.Instances(new java.io.FileReader("iris.arff"));
insts.setClassIndex(insts.numAttributes() - 1);
int percentSplit = 66;
int trainSize = insts.numInstances() * percentSplit / 100;
int testSize = insts.numInstances() - trainSize;
int numCorrect = 0;
for (int i = trainSize; i < insts.numInstances(); i++)
{
weka.core.Instance currentInst = insts.instance(i);
double predictedClass = qhClassifier.classifyInstance(currentInst);
if (predictedClass == insts.instance(i).classValue())
numCorrect++;
}
Console.WriteLine(numCorrect + " out of " + testSize + " correct (" + (double)((double)numCorrect / (double)testSize * 100.0) + "%)");
}
catch(java.lang.Exception e)
{
e.printStackTrace();
}
}
}