Weka Updatable Cluster - Java Machine Learning AI

Java examples for Machine Learning AI:weka

Description

Weka Updatable Cluster

Demo Code



import java.io.File;

import weka.clusterers.ClusterEvaluation;
import weka.clusterers.Cobweb;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.converters.ArffLoader;
import weka.core.converters.ConverterUtils.DataSource;


public class WekaUpdateableCluster {
    public static void main(String[] args) throws Exception {
        ArffLoader loader = new ArffLoader();
        loader.setFile(new File(
                "bank-train.arff"));
        Instances structure = loader.getStructure();
        structure.setClassIndex(structure.numAttributes() - 1);

        DataSource source = new DataSource(
                "bank-test.arff");
        Instances instancesTest = source.getDataSet(); 

        Instance current;/*from  w  ww .ja  v a2 s  . c  o m*/
        while ((current = loader.getNextInstance(structure)) != null)
            cluster.updateClusterer(current);
        cluster.updateFinished();

        ClusterEvaluation eval = new ClusterEvaluation();
        eval.setClusterer(cluster);
        eval.evaluateClusterer(instancesTest);

        System.out.println(eval.getNumClusters());

    }
}

Related Tutorials