Weka Two-time development tutorials (Eclipse+weka)

Source: Internet
Author: User

Weka Two-time development Tutorials (Eclipse+weka)

 

the full name of Weka is the Waikato Intelligent Analytics Environment (Waikato Environment for knowledge analysis), a free, non-commercial, open-source machine learning and data mining software based on the Java environment.

after installing the environment, Weka's download address: http://www.cs.waikato.ac.nz/ml/weka/developer Verstion

Create a new Java project, add a jar package, under the Weka installation directory (Weka.jar and Weka-src.jar)

The following is the test code, the data set used by the weka-3-7 comes with

Package test;

import Java.io.File;

import Weka.classifiers.CheckClassifier;

import Weka.classifiers.Classifier;

import weka.classifiers.Evaluation;

import weka.classifiers.evaluation.*;

import weka.core.Instance;

import weka.core.Instances;

import weka.core.converters.*;

 

Public class Testweka {

 

    /**

* @param args

     */

Public static void Main (string[] args) {

Instances ins = null;

Classifier cfs = null;

      

try {

//Read into the Training test sample

File File = new file ("C:\\Program Files\\weka-3-7\\data\\contact-lenses.arff");

Arffloader loader = new Arffloader ();

loader.setfile (file);

ins = Loader.getdataset ();

Ins.setclassindex (Ins.numattributes ()-1);

//Initialize classifier

cfs = (Classifier) class.forname ("Weka.classifiers.bayes.NaiveBayes"). newinstance ();

//Use training samples for classification

cfs.buildclassifier (INS);

//Use test samples to test the learning effect of the classifier

Instance Testinst;

Evaluation testingevaluation = new Evaluation (ins);

int length = Ins.numinstances ();

for (int i = 0; i < length; i++) {

testinst = ins.instance (i);

testingevaluation.evaluatemodelonceandrecordprediction (CFS, testinst);

           }

//Print classification results

System.out.println ("The correct rate of classification" + (1-testingevaluation.errorrate ()));

} catch (Exception e) {

e.printstacktrace ();

       }

    }

}

All normal, the output is: classification of the correct rate 0.9583333333333334

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.