Example usage for weka.core Instance hasMissingValue

List of usage examples for weka.core Instance hasMissingValue

Introduction

In this page you can find the example usage for weka.core Instance hasMissingValue.

Prototype

public boolean hasMissingValue();

Source Link

Document

Tests whether an instance has a missing value.

Usage

From source file:myid3andc45classifier.Model.MyID3.java

@Override
public double classifyInstance(Instance instance) throws NoSupportForMissingValuesException {

    //Periksa apakah instance memiliki missing value
    if (instance.hasMissingValue()) {
        throw new NoSupportForMissingValuesException("MyID3: no missing values, please");
    }//from   www  .ja  v  a2 s  . c  om

    if (attribute == null) {
        return label;
    } else {
        return successors[(int) instance.value(attribute)].classifyInstance(instance);
    }

}

From source file:myJ48.MyJ48.java

/**
 * Computes class distribution for instance using decision tree.
 *
 * @param instance the instance for which distribution is to be computed
 * @return the class distribution for the given instance
 * @throws NoSupportForMissingValuesException if instance has missing values
 *//*from  ww w  .  j  a v  a  2  s .c  o m*/
public double[] distributionForInstance(Instance instance) throws NoSupportForMissingValuesException {
    if (instance.hasMissingValue()) {
        throw new NoSupportForMissingValuesException("Missing value error");
    }
    if (currentAttribute == null) {
        return classDistribution;
    } else {
        return nodes[(int) instance.value(currentAttribute)].distributionForInstance(instance);
    }
}

From source file:newdtl.NewID3.java

/**
 * Classifies a given test instance using the decision tree.
 *
 * @param instance the instance to be classified
 * @return the classification/*w  w w  .  j  ava2 s .c  om*/
 * @throws NoSupportForMissingValuesException if instance has missing values
 */
@Override
public double classifyInstance(Instance instance) throws NoSupportForMissingValuesException {

    if (instance.hasMissingValue()) {
        throw new NoSupportForMissingValuesException("NewID3: Cannot handle missing values");
    }
    if (splitAttribute == null) {
        return label;
    } else {
        return children[(int) instance.value(splitAttribute)].classifyInstance(instance);
    }
}

From source file:newdtl.NewID3.java

/**
 * Computes class distribution for instance using decision tree.
 *
 * @param instance the instance for which distribution is to be computed
 * @return the class distribution for the given instance
 * @throws NoSupportForMissingValuesException if instance has missing values
 *//*ww  w  .  j  av a  2  s  . c om*/
@Override
public double[] distributionForInstance(Instance instance) throws NoSupportForMissingValuesException {

    if (instance.hasMissingValue()) {
        throw new NoSupportForMissingValuesException("NewID3: Cannot handle missing values");
    }
    if (splitAttribute == null) {
        return classDistributions;
    } else {
        return children[(int) instance.value(splitAttribute)].distributionForInstance(instance);
    }
}

From source file:newdtl.NewJ48.java

/**
 * Classifies a given test instance using the decision tree.
 *
 * @param instance the instance to be classified
 * @return the classification/*from w w  w.  jav a2 s.  c o m*/
 */
@Override
public double classifyInstance(Instance instance) throws NoSupportForMissingValuesException {
    if (instance.hasMissingValue()) {
        throw new NoSupportForMissingValuesException("NewID3: Cannot handle missing values");
    }

    if (splitAttribute == null) {
        return label;
    } else {
        if (splitAttribute.isNumeric()) {
            if (Double.compare(instance.value(splitAttribute), splitThreshold) <= 0) {
                return children[0].classifyInstance(instance);
            } else {
                return children[1].classifyInstance(instance);
            }
        } else {
            return children[(int) instance.value(splitAttribute)].classifyInstance(instance);
        }
    }
}

From source file:newdtl.NewJ48.java

/**
 * Computes class distribution for instance using decision tree.
 *
 * @param instance the instance for which distribution is to be computed
 * @return the class distribution for the given instance
 *//*w  w  w  .ja  v  a 2 s. c o m*/
@Override
public double[] distributionForInstance(Instance instance) throws NoSupportForMissingValuesException {
    if (instance.hasMissingValue()) {
        throw new NoSupportForMissingValuesException("NewID3: Cannot handle missing values");
    }

    if (splitAttribute == null) {
        return normalize(classDistributions);
    } else {
        if (splitAttribute.isNumeric()) {
            if (Double.compare(instance.value(splitAttribute), splitThreshold) <= 0) {
                return children[0].distributionForInstance(instance);
            } else {
                return children[1].distributionForInstance(instance);
            }
        } else {
            return children[(int) instance.value(splitAttribute)].distributionForInstance(instance);
        }
    }
}