Example usage for weka.clusterers ClusterEvaluation crossValidateModel

List of usage examples for weka.clusterers ClusterEvaluation crossValidateModel

Introduction

In this page you can find the example usage for weka.clusterers ClusterEvaluation crossValidateModel.

Prototype

public static double crossValidateModel(DensityBasedClusterer clusterer, Instances data, int numFolds,
        Random random) throws Exception 

Source Link

Document

Perform a cross-validation for DensityBasedClusterer on a set of instances.

Usage

From source file:adams.flow.transformer.WekaCrossValidationClustererEvaluator.java

License:Open Source License

/**
 * Executes the flow item./*w  w  w. j a  va  2 s .co m*/
 *
 * @return      null if everything is fine, otherwise error message
 */
@Override
protected String doExecute() {
    String result;
    Instances data;
    weka.clusterers.Clusterer cls;
    int folds;
    MakeDensityBasedClusterer make;
    double log;

    result = null;

    try {
        // evaluate classifier
        cls = getClustererInstance();
        if (cls == null)
            throw new IllegalStateException("Clusterer '" + getClusterer() + "' not found!");

        data = (Instances) m_InputToken.getPayload();
        folds = m_Folds;
        if (folds == -1)
            folds = data.numInstances();
        if (!(cls instanceof DensityBasedClusterer)) {
            make = new MakeDensityBasedClusterer();
            make.setClusterer(cls);
            cls = make;
        }
        log = ClusterEvaluation.crossValidateModel((DensityBasedClusterer) cls, data, folds,
                new Random(m_Seed));
        m_OutputToken = new Token(new WekaClusterEvaluationContainer(log));
    } catch (Exception e) {
        m_OutputToken = null;
        result = handleException("Failed to cross-validate clusterer: ", e);
    }

    if (m_OutputToken != null)
        updateProvenance(m_OutputToken);

    return result;
}