Example usage for weka.core AttributeLocator AttributeLocator

List of usage examples for weka.core AttributeLocator AttributeLocator

Introduction

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

Prototype

public AttributeLocator(Instances data, int type, int[] indices) 

Source Link

Document

initializes the AttributeLocator with the given data for the specified type of attribute.

Usage

From source file:en_deep.mlprocess.manipulation.featmodif.FeatureModifierFilter.java

License:Open Source License

/**
 * Set the output format if the class is nominal.
 *//*from ww w  .  jav a  2 s . c o m*/
private void setOutputFormat() {

    FastVector newAtts;
    int newClassIndex;
    Instances outputFormat;

    newClassIndex = getInputFormat().classIndex();
    newAtts = new FastVector();

    BitSet attrSrc = new BitSet(), attrDest = new BitSet();

    int attSoFar = 0;

    for (int j = 0; j < getInputFormat().numAttributes(); j++) {

        Attribute att = getInputFormat().attribute(j);

        if (!m_Columns.isInRange(j)) {
            newAtts.addElement(att.copy());

            attrSrc.set(j);
            attrDest.set(attSoFar++);

        } else {

            ArrayList<Attribute> valueAttrs = getAttributeOutputFormat(att);

            if (newClassIndex >= 0 && j < getInputFormat().classIndex()) {
                newClassIndex += valueAttrs.size() - 1;
            }
            newAtts.addAll(valueAttrs);

            if (m_PreserveOriginals) {
                attrSrc.set(j);
                attrDest.set(attSoFar);
            }
            attSoFar += valueAttrs.size();
        }
    }

    outputFormat = new Instances(getInputFormat().relationName(), newAtts, 0);
    outputFormat.setClassIndex(newClassIndex);
    setOutputFormat(outputFormat);

    m_StringToCopySrc = new AttributeLocator(getInputFormat(), Attribute.STRING, MathUtils.findTrue(attrSrc));
    m_StringToCopyDst = new AttributeLocator(outputFormat, Attribute.STRING, MathUtils.findTrue(attrDest));
}

From source file:en_deep.mlprocess.manipulation.featmodif.ReplaceMissing.java

License:Open Source License

/**
 * Set the output format if the class is nominal.
 *///from www.  j  a  v a2 s . co  m
private void setOutputFormat() {

    FastVector newAtts;
    Instances outputFormat;

    newAtts = new FastVector();

    BitSet attrSrc = new BitSet();

    for (int j = 0; j < getInputFormat().numAttributes(); j++) {

        Attribute att = null;
        Attribute srcAtt = getInputFormat().attribute(j);

        if (!m_Columns.isInRange(j) || srcAtt.indexOfValue(m_ReplVal) >= 0) {
            att = (Attribute) srcAtt.copy();
        } else if (srcAtt.isNominal()) {

            Enumeration<String> valsEnum = srcAtt.enumerateValues();
            ArrayList<String> valsList = new ArrayList<String>();

            while (valsEnum.hasMoreElements()) {
                valsList.add(valsEnum.nextElement());
            }
            valsList.add(m_ReplVal);

            att = new Attribute(srcAtt.name(), valsList);
        } else { // string attributes
            att = (Attribute) srcAtt.copy();
            att.addStringValue(m_ReplVal);
        }

        newAtts.addElement(att);
        attrSrc.set(j);
    }

    outputFormat = new Instances(getInputFormat().relationName(), newAtts, 0);
    outputFormat.setClassIndex(getInputFormat().classIndex());

    setOutputFormat(outputFormat);

    m_StringToCopy = new AttributeLocator(getInputFormat(), Attribute.STRING, MathUtils.findTrue(attrSrc));
}