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 $


   
  }
 
  public static void testbedARFFfromFile() throws Exception
  {
    Attribute groupID = new Attribute("groupID", (FastVector) null);
   
    DataSource source = new DataSource("testMe.arff");
    Instances instances = source.getDataSet();
    //System.out.println(instances);
    System.out.println(instances.instance(0));
View Full Code Here


       int             i;
  
       // 1. set up attributes
       atts = new FastVector();
       // - numeric
       atts.addElement(new Attribute("att1"));
       // - nominal
       attVals = new FastVector();
       for (i = 0; i < 5; i++)
         attVals.addElement("val" + (i+1));
       atts.addElement(new Attribute("att2", attVals));
       // - string
       atts.addElement(new Attribute("att3", (FastVector) null));
       // - date
       atts.addElement(new Attribute("att4", "yyyy-MM-dd"));
       // - relational
       attsRel = new FastVector();
       // -- numeric
       attsRel.addElement(new Attribute("att5.1"));
       // -- nominal
       attValsRel = new FastVector();
       for (i = 0; i < 5; i++)
         attValsRel.addElement("val5." + (i+1));
       attsRel.addElement(new Attribute("att5.2", attValsRel));
       dataRel = new Instances("att5", attsRel, 0);
       atts.addElement(new Attribute("att5", dataRel, 0));
  
       // 2. create Instances object
       data = new Instances("MyRelation", atts, 0);
  
       // 3. fill with data
View Full Code Here

 
  public static void writeToArff(ArrayList<Feedback> feedbacks, String fileName) throws Exception
  {
    //header
    FastVector attributes = new FastVector();
    Attribute assessorID = new Attribute("assessorID");
    Attribute assesseeID = new Attribute("assesseeID");
    Attribute feedbackValue = new Attribute("feedbackValue");
    attributes.addElement(assessorID);
    attributes.addElement(assesseeID);
    attributes.addElement(feedbackValue);
   
    Instances data = new Instances("mydataset", attributes, 0);
View Full Code Here

      wekaAttributes = new FastVector(bagOfWordsData.getNumericWords()
          .size()
          + bagOfWordsData.getNominalWordValueMap().size()
          + 2);
      // add instance id attribute
      wekaAttributes.addElement(new Attribute(INSTANCE_ID));
      // add numeric word attributes
      for (String word : bagOfWordsData.getNumericWords()) {
        Attribute attribute = new Attribute(word);
        wekaAttributes.addElement(attribute);
      }
      // add nominal word attributes
      for (Map.Entry<String, SortedSet<String>> nominalWordEntry : bagOfWordsData
          .getNominalWordValueMap().entrySet()) {
View Full Code Here

      double[] zeroValues = new double[instances.numAttributes()];
      Arrays.fill(zeroValues, 0.0d);
      SparseInstance wekaInstance = new SparseInstance(1.0d, zeroValues);
      wekaInstance.setDataset(instances);
      // set instance id
      Attribute instanceId = instances.attribute(INSTANCE_ID);
      wekaInstance.setValue(instanceId.index(), entry.getKey()
          .doubleValue());
      // set document class
      Attribute classAttr = instances.attribute(CLASS);
      wekaInstance.setValue(classAttr.index(),
          classAttr.indexOfValue(entry.getValue()));
      // set numeric words
      if (bagOfWordsData.getInstanceNumericWords().get(entry.getKey()) != null) {
        for (Map.Entry<String, Double> word : bagOfWordsData
            .getInstanceNumericWords().get(entry.getKey())
            .entrySet()) {
          Attribute wordAttr = instances.attribute(word.getKey());
          wekaInstance.setValue(wordAttr.index(), word.getValue()
              .doubleValue());
        }
      }
      // set nominal words
      if (bagOfWordsData.getInstanceNominalWords().get(entry.getKey()) != null) {
        for (Map.Entry<String, String> word : bagOfWordsData
            .getInstanceNominalWords().get(entry.getKey())
            .entrySet()) {
          Attribute wordAttr = instances.attribute(word.getKey());
          int valueIndex = wordAttr.indexOfValue(word.getValue());
          if (valueIndex == -1) {
            throw new IOException("oops! " + word);
          }
          wekaInstance.setValue(wordAttr.index(), valueIndex);
        }
      }
      instances.add(wekaInstance);
    }
  }
View Full Code Here

      BagOfWordsData bagOfWordsData, BagOfWordsDecorator bDecorator) {
    FastVector wekaAttributes = new FastVector(bagOfWordsData
        .getNumericWords().size()
        + bagOfWordsData.getNominalWordValueMap().size() + 2);
    // add instance id attribute
    wekaAttributes.addElement(new Attribute(INSTANCE_ID));
    // add numeric word attributes
    for (String word : bagOfWordsData.getNumericWords()) {
      Attribute attribute = new Attribute(word);
      wekaAttributes.addElement(attribute);
    }
    // add nominal word attributes
    for (Map.Entry<String, SortedSet<String>> nominalWordEntry : bagOfWordsData
        .getNominalWordValueMap().entrySet()) {
      FastVector wordValues = new FastVector(nominalWordEntry.getValue()
          .size());
      for (String wordValue : nominalWordEntry.getValue()) {
        wordValues.addElement(wordValue);
      }
      Attribute attribute = new Attribute(nominalWordEntry.getKey(),
          wordValues);
      wekaAttributes.addElement(attribute);
    }
    // add class attribute
    FastVector wekaClassLabels = new FastVector(bagOfWordsData.getClasses()
        .size());
    for (String classLabel : bagOfWordsData.getClasses()) {
      wekaClassLabels.addElement(classLabel);
    }
    wekaAttributes.addElement(new Attribute(CLASS, wekaClassLabels));
    Instances instances = new Instances(arffRelation, wekaAttributes, 0);
    instances.setClassIndex(instances.numAttributes() - 1);
    return instances;
  }
View Full Code Here

        wordValues.addElement(dummyName);
      }
      for (String wordValue : attributeValues) {
        wordValues.addElement(wordValue);
      }
      Attribute attribute = new Attribute(attributeName, wordValues);
      wekaAttributes.addElement(attribute);
    }
View Full Code Here

        Arrays.fill(zeroValues, 0.0d);
        SparseInstance wekaInstance = new SparseInstance(1.0d,
            zeroValues);
        wekaInstance.setDataset(instances);
        // set instance id
        Attribute instanceId = instances.attribute(INSTANCE_ID);
        wekaInstance.setValue(instanceId.index(), entry.getKey()
            .doubleValue());
        // set document class
        Attribute classAttr = instances.attribute(CLASS);
        wekaInstance.setValue(classAttr.index(),
            classAttr.indexOfValue(entry.getValue()));
        // set numeric words
        if (bagOfWordsData.getInstanceNumericWords()
            .get(entry.getKey()) != null) {
          for (Map.Entry<String, Double> word : bagOfWordsData
              .getInstanceNumericWords().get(entry.getKey())
              .entrySet()) {
            Attribute wordAttr = instances.attribute(word.getKey());
            wekaInstance.setValue(wordAttr.index(), word.getValue()
                .doubleValue());
          }
        }
        // set nominal words
        if (bagOfWordsData.getInstanceNominalWords()
            .get(entry.getKey()) != null) {
          for (Map.Entry<String, String> word : bagOfWordsData
              .getInstanceNominalWords().get(entry.getKey())
              .entrySet()) {
            Attribute wordAttr = instances.attribute(word.getKey());
            int valueIndex = wordAttr.indexOfValue(word.getValue());
            if (valueIndex == -1) {
              throw new IOException("oops! " + word);
            }
            wekaInstance.setValue(wordAttr.index(), valueIndex);
          }
        }
        instances.add(wekaInstance);
      }
    }
View Full Code Here

    if (stems.size() == 0) {
      throw new Exception("Couldn't find any data!");
    }
   
    FastVector atts = new FastVector(2);
    atts.addElement(new Attribute("doc", (FastVector) null));
    atts.addElement(new Attribute("keyphrases", (FastVector) null));
    Instances data = new Instances("keyphrase_training_data", atts, 0);
   
    // Build model
    m_KEAFilter = new KEAFilter(stopwords);
   
View Full Code Here

    } else {
      m_KEAFilter.loadThesaurus(m_Stemmer, m_Stopwords);
    }

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

    if (m_KEAFilter.m_Dictionary == null) {
      buildGlobalDictionaries(stems);
    }
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.