Example usage for weka.core Capabilities handles

List of usage examples for weka.core Capabilities handles

Introduction

In this page you can find the example usage for weka.core Capabilities handles.

Prototype

public boolean handles(Capability c) 

Source Link

Document

returns true if the classifier handler has the specified capability

Usage

From source file:SMO.java

License:Open Source License

/**
 * Returns default capabilities of the classifier.
 *
 * @return      the capabilities of this classifier
 *///  w  w  w .j  a v  a2 s .c  o m
public Capabilities getCapabilities() {
    Capabilities result = getKernel().getCapabilities();
    result.setOwner(this);

    // attribute
    result.enableAllAttributeDependencies();
    // with NominalToBinary we can also handle nominal attributes, but only
    // if the kernel can handle numeric attributes
    if (result.handles(Capability.NUMERIC_ATTRIBUTES))
        result.enable(Capability.NOMINAL_ATTRIBUTES);
    result.enable(Capability.MISSING_VALUES);

    // class
    result.disableAllClasses();
    result.disableAllClassDependencies();
    result.enable(Capability.NOMINAL_CLASS);
    result.enable(Capability.MISSING_CLASS_VALUES);

    return result;
}

From source file:adams.data.conversion.WekaCapabilitiesToSpreadSheet.java

License:Open Source License

/**
 * Performs the actual conversion./* ww  w  . j a v  a2  s .  com*/
 *
 * @return      the converted data
 * @throws Exception   if something goes wrong with the conversion
 */
@Override
protected Object doConvert() throws Exception {
    SpreadSheet result;
    Capabilities caps;
    Row row;

    caps = (Capabilities) m_Input;
    result = new DefaultSpreadSheet();
    result.setName(OptionUtils.getCommandLine(caps.getOwner()));

    // header
    row = result.getHeaderRow();
    row.addCell("K").setContent("Capability");
    row.addCell("S").setContent("Supported");
    row.addCell("D").setContent("Dependency");

    // data
    for (Capability cap : Capability.values()) {
        row = result.addRow();
        row.addCell("K").setContentAsString(cap.toString());
        row.addCell("S").setContent(caps.handles(cap));
        row.addCell("D").setContent(caps.hasDependency(cap));
    }
    row = result.addRow();
    row.addCell("K").setContentAsString("Minimum # Instances ");
    row.addCell("S").setContent(caps.getMinimumNumberInstances());

    return result;
}

From source file:adams.flow.condition.bool.WekaClassification.java

License:Open Source License

/**
 * Loads the model from the model file.//ww  w  .  j  a  va 2  s  . com
 *
 * @param owner   the actor this condition belongs to
 * @return      null if everything worked, otherwise an error message
 */
protected String setUpModel(Actor owner) {
    String result;
    String msg;
    Capabilities caps;
    Object obj;
    MessageCollection errors;

    result = null;

    if (m_ModelFile.isDirectory()) {
        // obtain model from callable actor
        try {
            errors = new MessageCollection();
            obj = CallableActorHelper.getSetup(Classifier.class, m_ModelActor, owner, errors);
            if (obj == null) {
                if (!errors.isEmpty())
                    result = errors.toString();
            } else {
                if (obj instanceof WekaModelContainer)
                    m_Model = (Classifier) ((WekaModelContainer) obj).getValue(WekaModelContainer.VALUE_MODEL);
                else
                    m_Model = (Classifier) obj;
            }
        } catch (Exception e) {
            m_Model = null;
            msg = "Failed to obtain model from callable actor '" + m_ModelActor + "': ";
            result = msg + e.toString();
            getLogger().log(Level.SEVERE, msg, e);
        }
    } else {
        // load model
        try {
            m_Model = (Classifier) SerializationHelper.read(m_ModelFile.getAbsolutePath());
        } catch (Exception e) {
            m_Model = null;
            msg = "Failed to load model from '" + m_ModelFile + "': ";
            result = msg + e.toString();
            getLogger().log(Level.SEVERE, msg, e);
        }
    }

    // can model handle nominal class attribute?
    if (m_Model != null) {
        caps = m_Model.getCapabilities();
        if (!caps.handles(Capability.UNARY_CLASS) && !caps.handles(Capability.BINARY_CLASS)
                && !caps.handles(Capability.NOMINAL_CLASS))
            result = "Model can neither handle unary, binary nor nominal class attribute!";
    }

    return result;
}

From source file:com.rapidminer.tools.WekaLearnerCapabilities.java

License:Open Source License

public static boolean supportsCapability(Classifier classifier, LearnerCapability lc) {
    Capabilities capabilities = classifier.getCapabilities();

    if (lc == LearnerCapability.POLYNOMINAL_ATTRIBUTES) {
        return capabilities.handles(Capabilities.Capability.NOMINAL_ATTRIBUTES);
    } else if (lc == LearnerCapability.BINOMINAL_ATTRIBUTES) {
        return capabilities.handles(Capabilities.Capability.BINARY_ATTRIBUTES);
    } else if (lc == LearnerCapability.NUMERICAL_ATTRIBUTES) {
        return capabilities.handles(Capabilities.Capability.NUMERIC_ATTRIBUTES);
    } else if (lc == LearnerCapability.POLYNOMINAL_CLASS) {
        return capabilities.handles(Capabilities.Capability.NOMINAL_CLASS);
    } else if (lc == LearnerCapability.BINOMINAL_CLASS) {
        return capabilities.handles(Capabilities.Capability.BINARY_CLASS);
    } else if (lc == LearnerCapability.NUMERICAL_CLASS) {
        return capabilities.handles(Capabilities.Capability.NUMERIC_CLASS);
    } else if (lc == LearnerCapability.UPDATABLE) {
        return (classifier instanceof UpdateableClassifier);
    } else if (lc == LearnerCapability.WEIGHTED_EXAMPLES) {
        return (classifier instanceof WeightedInstancesHandler);
    }//from ww  w  . j a  v  a 2  s.com
    return false;
}