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 $


         if( !values.contains(strTemp) && strTemp != null )
          values.add(strTemp);
            }
      
       mapValues.put(strName, values);
       atts.add(new Attribute(strName, values));
       
    
    //////////////////////////////////////////////////////////////////////////////////////////
    //create Instances object
    Instances data = new Instances("MyRelation", atts, 0);
View Full Code Here


       }
    }
    
     for( String strAtrribute : attributeList){
       ArrayList<String> values =  mapValues.get(strAtrribute);
      atts.add(new Attribute(strAtrribute, values));
    }    
     
    //////////////////////////////////////////////////////////////////////////////////////////
    //create Instances object
    Instances data = new Instances("MyRelation", atts, 0);
View Full Code Here

      Unit u = mapUnit.get(strName);
      ArrayList<String> values =  new ArrayList<String>();
      u.getAllDataVaules( values );
      mapValues.put(strName, values);
     
      atts.add(new Attribute(strName, values));
    }
   
    //////////////////////////////////////////////////////////////////////////////////////////
    //create Instances object
    Instances data = new Instances("MyRelation", atts, 0);
View Full Code Here

        FastVector attributes = new FastVector();
        FastVector values = new FastVector();
        values.addElement("sunny");
        values.addElement("overcast");
        values.addElement("rain");
        attributes.addElement(new Attribute("outlook", values));
        values = new FastVector();
        values.addElement("false");
        values.addElement("true");
        attributes.addElement(new Attribute("windy", values));
        attributes.addElement(new Attribute("humidity"));
        attributes.addElement(new Attribute("temperature"));
        values = new FastVector();
        values.addElement("yes");
        values.addElement("no");
        attributes.addElement(new Attribute("play", values));
        Instances dataset = new Instances("", attributes, 15);
        dataset.add(createInstance(dataset, "sunny", "false", 85, 85, "no"));
        dataset.add(createInstance(dataset, "sunny", "true", 80, 90, "no"));
        dataset.add(createInstance(dataset, "overcast", "false", 83, 78, "yes"));
        dataset.add(createInstance(dataset, "rain", "false", 70, 96, "yes"));
View Full Code Here

   * @return
   */
  public static Instance newInstance(ArrayList<Attribute> attrs, Object ...list){
    Instance newInstance = new DenseInstance(list.length);
   
    Attribute att;
    for(int i=0; i<attrs.size(); i++){
         att = attrs.get(i);
         String listval = list[i].toString();

        // System.out.println(" ATTR. " + att + " VAL. " + listval);
         if(att.isNumeric()){
           try
             double dval = Double.parseDouble(listval);
             newInstance.setValue(att, dval );
           }catch(Exception ex){  }
         }
View Full Code Here

   */
  public  static Instances addInstance(Instances bb, Object ...list){
   
    Instance newInstance = new DenseInstance(list.length);
   
    Attribute att;
    for(int i=0; i<bb.numAttributes(); i++){
         att = bb.attribute(i);
         String listval = list[i].toString();

         //System.out.println(" ATTR. " + att + " VAL. " + listval);
         if(att.isNumeric()){
           try
             double dval = Double.parseDouble(listval);
             newInstance.setValue(att, dval );
           }catch(Exception ex){  }
         }
View Full Code Here

   */
 
  @SuppressWarnings("unchecked")
  public WekaDataset(){
    /* Structure */
        Attribute task = new Attribute("Task", (List) null);
        Attribute ability = new Attribute("Ability", (List) null);
        Attribute disposition = new Attribute("Disposition", (List) null);
        Attribute cross = new Attribute("Cross", (List) null);
        Attribute context = new Attribute("ExtFactors");
        Attribute score = new Attribute("score");
        ArrayList<Attribute> attributes = new ArrayList<Attribute>();
    attributes.add(task);
    attributes.add(ability);
    attributes.add(disposition);
    attributes.add(cross);
View Full Code Here

   * @return
   */
  public Instance newInstance(Object ...list){
    Instance newInstance = new DenseInstance(dataset.numAttributes());
   
    Attribute att;
    for(int i=0; i<list.length; i++){
      att = dataset.attribute(i);
         String listval = list[i].toString();

        //System.out.println(" ATTR. " + att + " VAL. " + listval);
         if(att.isNumeric()){
           try
             double dval = Double.parseDouble(listval);
             newInstance.setValue(att, dval );
           }catch(Exception ex){  }
         }
View Full Code Here

  public Instance createNominalInstance(Object ...list){
   
   
    Instance newInstance = new DenseInstance(dataset.numAttributes());
   
    Attribute att;
    for(int i=0; i<list.length; i++){
      att = dataset.attribute(i);
         String listval = list[i].toString();
         //System.out.println(listval);

        //System.out.println(" ATTR. " + att + " VAL. " + listval);
         if(att.isNumeric()){
           try
             double dval = Double.parseDouble(listval);
             newInstance.setValue(att, dval );
           }catch(Exception ex){ 
             ex.printStackTrace();
           }
         }
         else{
           //att is nominal
           if(att.isNominal() && att.indexOfValue(listval)<0)
             return null//instance not compliant
          
          
           try{
             newInstance.setValue(att, list[i].toString() );
View Full Code Here

  public static void testbedARFF() throws Exception
  {
    //header
    FastVector attributes = new FastVector();
   
    Attribute groupID = new Attribute("groupID");
   
    Attribute agentID = new Attribute("agentID");

    FastVector strategyAttributes = new FastVector();
    Attribute feedbackMean = new Attribute("feedbackMean");
    Attribute feedbackStdDev = new Attribute("feedbackStdDev");
    Attribute targetGroupdID = new Attribute("targetGroupID");
    strategyAttributes.addElement(feedbackMean);
    strategyAttributes.addElement(feedbackStdDev);
    strategyAttributes.addElement(targetGroupdID);
    Instances temp = new Instances("strategy", strategyAttributes, 3);
   
    Attribute strategy = new Attribute("strategy", temp);
   
    attributes.addElement(groupID);
    attributes.addElement(agentID);
    attributes.addElement(strategy);
   
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.