Package weka.core

Examples of weka.core.Attribute

Typical usage (code from the main() method of this class):

...
// Create numeric attributes "length" and "weight"
Attribute length = new Attribute("length");
Attribute weight = new Attribute("weight");

// Create list to hold nominal values "first", "second", "third"
List my_nominal_values = new ArrayList(3);
my_nominal_values.add("first");
my_nominal_values.add("second");
my_nominal_values.add("third");

// Create nominal attribute "position"
Attribute position = new Attribute("position", my_nominal_values);
...

@author Eibe Frank (eibe@cs.waikato.ac.nz) @version $Revision: 6889 $


    bodyS = new double[data.numAttributes() - 1][2];
    double k = 2 * Math.PI / (data.numAttributes() - 1);
    // Add DataDictionary
    Enumeration enumerAttributes = data.enumerateAttributes();
    while (enumerAttributes.hasMoreElements()) {
      Attribute attr = (Attribute) enumerAttributes.nextElement();
      DataFieldType dataField = _40Factory.eINSTANCE
          .createDataFieldType();
      dataField.setDataType(DATATYPE.DOUBLE); // DATATYPE
      dataField.setName(attr.name()); // String
      dataField.setOptype(OPTYPE.CONTINUOUS); // OPTYPE
      String[] strCoordinates = null;
      strCoordinates = createAnchors(attr.index(), k);
      // Add Extension - Coordinate X
      ExtensionType extension = _40Factory.eINSTANCE
          .createExtensionType();
      extension.setName("xCoordinate");
      extension.setValue(strCoordinates[0]);
      dataField.getExtension().add(extension);
      // Add Extension - Coordinate y
      extension = _40Factory.eINSTANCE.createExtensionType();
      extension.setName("yCoordinate");
      extension.setValue(strCoordinates[1]);
      dataField.getExtension().add(extension);
      dataDictionary.getDataField().add(dataField);
    }
    DataFieldType dataField = _40Factory.eINSTANCE.createDataFieldType();
    dataField.setDataType(DATATYPE.STRING); // DATATYPE
    dataField.setName("class"); // String
    dataField.setOptype(OPTYPE.CATEGORICAL); // OPTYPE
    dataDictionary.getDataField().add(dataField);
    Attribute classAttr = data.classAttribute();
    Enumeration values = classAttr.enumerateValues();

    while (values.hasMoreElements()) {
      ValueType valueType = _40Factory.eINSTANCE.createValueType();
      valueType.setValue(values.nextElement().toString());
      dataField.getValue().add(valueType);
View Full Code Here


        mInstances = new Instances("", attributes, 1);
        mInstances.setClassIndex(classIndex);
        mClassAttribute = mInstances.classAttribute();
        for (int i=0; i<attributes.size(); i++)
        {
            Attribute attribute = (Attribute)attributes.get(i);
            mColumnNamesMapping.put(attribute.name(), i);
        }
    }
View Full Code Here

        throws ActivityUserException
    {
        ArrayList<Attribute> result = new ArrayList<Attribute>();
        for (int i=0;  i<metadata.getColumnCount(); i++)
        {
            Attribute attribute;
            ColumnMetadata column = metadata.getColumnMetadata(i);
            if (nominalValues != null)
            {
                List<Object> values = nominalValues.get(i);
                if (values != null)
                {
                    List<String> nomVal = new ArrayList<String>();
                    for (Object value : values)
                    {
                        // nominal values must be strings
                        nomVal.add(value.toString());
                    }
                    attribute = new Attribute(column.getName(), nomVal);
                }
                else
                {
                    attribute = createAttributeForType(column);
                }
View Full Code Here

            case TupleTypes._DOUBLE:
            case TupleTypes._FLOAT:
            case TupleTypes._INT:
            case TupleTypes._LONG:
            case TupleTypes._SHORT:
                return new Attribute(column.getName());
            case TupleTypes._CHAR:
            case TupleTypes._STRING:
                return new Attribute(column.getName(), (ArrayList<String>)null);
            case TupleTypes._DATE:
            case TupleTypes._TIMESTAMP:
                return new Attribute(column.getName(), DATE_FORMAT);
            default:
                throw new ActivityUserException(
                        new UnsupportedTupleTypeException(column.getType()));
        }
View Full Code Here

        int columnCount = dataset.numAttributes();
        Instance instance = new DenseInstance(columnCount);
        instance.setDataset(dataset);
        for (int i=0; i<columnCount; i++)
        {
            Attribute attribute = dataset.attribute(i);
            // we only support numeric and nominal attributes for now
            if (attribute.isDate())
            {
                Object value = tuple.getObject(i);
                if (tuple.wasNull())
                {
                    instance.setMissing(i);
                }
                // timestamp extends date
                else
                {
                    instance.setValue(i, ((Date)value).getTime());
                }
            }
            else if (attribute.isNumeric())
            {
                double value = tuple.getDouble(i);
                if (tuple.wasNull())
                {
                    instance.setMissing(i);
                }
                else
                {
                    instance.setValue(i, value);
                }
            }
            else if (attribute.isNominal() || attribute.isString())
            {
                String value = tuple.getString(i);
                if (tuple.wasNull())
                {
                    instance.setMissing(i);
View Full Code Here

    // Generate input format for classifier
    FastVector atts = new FastVector();
    for (int i = 0; i < getInputFormat().numAttributes(); i++) {
      if (i == documentAtt) {
        atts.addElement(new Attribute("Term_frequency")); // 2
        atts.addElement(new Attribute("IDF")); //
        atts.addElement(new Attribute("TFxIDF")); //
        atts.addElement(new Attribute("First_occurrence")); //
        atts.addElement(new Attribute("Last_occurrence")); //
        atts.addElement(new Attribute("Spread")); //
        atts.addElement(new Attribute("Domain_keyphraseness")); //
        atts.addElement(new Attribute("Length")); //
        atts.addElement(new Attribute("Generality")); //
        atts.addElement(new Attribute("Node_degree")); //
        atts.addElement(new Attribute("Semantic_relatedness")); //
        atts.addElement(new Attribute("Wikipedia_keyphraseness")); //
        atts.addElement(new Attribute("Inverse_Wikip_frequency")); //
        atts.addElement(new Attribute("Total_Wikip_keyphraseness")); // 13

      } else if (i == keyphrasesAtt) {
        if (nominalClassValue) {
          FastVector vals = new FastVector(2);
          vals.addElement("False");
          vals.addElement("True");
          atts.addElement(new Attribute("Keyphrase?", vals));
        } else {
          atts.addElement(new Attribute("Keyphrase?"));
        }
      }
    }

    classifierData = new Instances("ClassifierData", atts, 0);
View Full Code Here

    // Create output format for filter
    FastVector atts = new FastVector();
    for (int i = 1; i < getInputFormat().numAttributes(); i++) {
      if (i == documentAtt) {
        atts.addElement(new Attribute("Candidate_name",
            (FastVector) null)); // 0
        atts.addElement(new Attribute("Candidate_original",
            (FastVector) null)); // 1
        atts.addElement(new Attribute("Term_frequency")); // 2
        atts.addElement(new Attribute("IDF")); // 3
        atts.addElement(new Attribute("TFxIDF")); // 4
        atts.addElement(new Attribute("First_occurrence")); // 5
        atts.addElement(new Attribute("Last_occurrence")); // 6
        atts.addElement(new Attribute("Spread")); // 7
        atts.addElement(new Attribute("Domain_keyphraseness")); // 8
        atts.addElement(new Attribute("Length")); // 9
        atts.addElement(new Attribute("Generality")); // 10
        atts.addElement(new Attribute("Node_degree")); // 11
        atts.addElement(new Attribute("Semantic_relatedness")); // 12
        atts.addElement(new Attribute("Wikipedia_keyphraseness")); // 13
        atts.addElement(new Attribute("Inverse_Wikip_frequency")); // 14
        atts.addElement(new Attribute("Total_Wikip_keyphraseness")); // 15

        atts.addElement(new Attribute("Probability")); // 16
        atts.addElement(new Attribute("Rank")); // 17

      } else if (i == keyphrasesAtt) {
        if (nominalClassValue) {
          FastVector vals = new FastVector(2);
          vals.addElement("False");
          vals.addElement("True");
          atts.addElement(new Attribute("Keyphrase?", vals));
        } else {
          atts.addElement(new Attribute("Keyphrase?"));
        }
      } else {
        atts.addElement(getInputFormat().attribute(i));
      }
    }
View Full Code Here

      throw new Exception("Couldn't find any data in "
          + inputDirectoryName);
    }

    FastVector atts = new FastVector(3);
    atts.addElement(new Attribute("filename", (FastVector) null));
    atts.addElement(new Attribute("document", (FastVector) null));
    atts.addElement(new Attribute("keyphrases", (FastVector) null));
    Instances data = new Instances("keyphrase_training_data", atts, 0);

    // Build model
    mauiFilter = new MauiFilter();
View Full Code Here

    for (int i = 0; i < size; i++) {
      values[i] /= weights[i];
    }
   
    // Backup best instance variables
    Attribute attributeBackedup = m_attribute;
    double[] cutsBackedup = m_cuts;
    double[] valuesBackedup = m_values;
   
    // Set instance variables to values computed for this attribute
    m_attribute = attribute;
View Full Code Here

           int numFolds, Random random)
      throws Exception {

      // Create header of instances object
      FastVector atts = new FastVector(2);
      atts.addElement(new Attribute("pred"));
      FastVector attVals = new FastVector(2);
      attVals.addElement(insts.classAttribute().value(cl1));
      attVals.addElement(insts.classAttribute().value(cl2));
      atts.addElement(new Attribute("class", attVals));
      Instances data = new Instances("data", atts, insts.numInstances());
      data.setClassIndex(1);

      // Collect data for fitting the logistic model
      if (numFolds <= 0) {
View Full Code Here

TOP

Related Classes of weka.core.Attribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.