C # code calls WEKA

Source: Internet
Author: User

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 ();

}

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.