We know that WEKA is a machine learning Toolkit (http://blog.csdn.net/Felomeng/archive/2009/10/17/4687061.aspx) developed in Java language ). So what if I want to call it in C? Ikvm (http://blog.csdn.net/Felomeng/article/details/4063343) can be used ).
The command for converting ikvm to WEKA. jar is: ikvmc-target: Library WEKA. jar. After running, a new file WEKA. dll will be generated. Add references to the C # project to reference the DLL file (you also need to add some java dependency classes, such as ikvm. openjdk. core. DLL, can be found in ikvm), you can call WEKA code, call the method with Java call WEKA method (http://blog.csdn.net/Felomeng/article/details/4688257 ).
Here is a sample code (which can be run only after proper modification ):
Public static voidclassifytest ()
{
Try
{
Vartrainingset = new WEKA. Core. instances (newjava. Io. filereader ("G: \ test. ARFF "));
Trainingset. setclassindex (0 );
WEKA. classifiers. classifier = newweka. classifiers. Lazy. kstar ();
Classifier. buildclassifier (trainingset );
Intnumcorrect = 0;
For (INT I = 0; I <trainingset. numinstances (); I ++)
{
WEKA. Core. instance currentinst = trainingset. instance (I );
Varpredictedclass = classifier. classifyinstance (currentinst );
If (predictedclass = trainingset. instance (I). classvalue ())
Numcorrect ++;
}
MessageBox. Show (numcorrect + "out of" + trainingset. numinstances () + "correct (" +
(Double) numcorrect/(double) trainingset. numinstances () * 100.0) + "% )");
}
Catch (Java. Lang. Exception ex)
{
Ex. printstacktrace ();
}
}