use weka clusterers ClusterEvaluation - Java Machine Learning AI

Java examples for Machine Learning AI:weka

Description

use weka clusterers ClusterEvaluation

Demo Code

import weka.clusterers.ClusterEvaluation;
import weka.clusterers.SimpleKMeans;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;

public class Cluster {
    public static void main(String[] args) throws Exception {
        DataSource source = new DataSource("weather.arff");
        Instances traindata = source.getDataSet();
        //traindata.setClassIndex(traindata.numAttributes()-1);

        SimpleKMeans kmeans = new SimpleKMeans();
        kmeans.setNumClusters(4);/*from w ww  . ja  v a 2s  .c  om*/
        kmeans.buildClusterer(traindata);

        ClusterEvaluation eval = new ClusterEvaluation();
        eval.setClusterer(kmeans);
        eval.evaluateClusterer(traindata);
        System.out.println(eval.clusterResultsToString());
    }
}

Related Tutorials