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 $


      throws Exception {
    // Classifier lagFiller = new weka.classifiers.functions.LeastMedSq();
    Classifier lagFiller = new weka.classifiers.functions.LinearRegression();

    ArrayList<Attribute> atts = new ArrayList<Attribute>();
    atts.add(new Attribute("time"));
    atts.add(new Attribute("target"));
    Instances simple = new Instances("simple", atts, insts.numInstances());
    int targetIndex = insts.attribute(targetName).index();
    for (int i = 0; i < insts.numInstances(); i++) {
      double targetValue = insts.instance(i).value(targetIndex);
      double time = i;
View Full Code Here


          }
        }

        if (m_customPeriodics != null) {
          for (String name : m_customPeriodics.keySet()) {
            Attribute att = inst.dataset().attribute("c_" + name);
            if (att != null) {
              if (instDate == null) {
                inst.setMissing(att);
              } else {
                // evaluate for this periodic
                List<CustomPeriodicTest> l = m_customPeriodics.get(name);
                boolean result = false;
                String label = null;
                for (CustomPeriodicTest t : l) {
                  result = (result || t.evaluate(instDate));

                  // match?
                  if (result) {
                    label = t.getLabel();
                    break;
                  } else {
                    label = null;
                  }
                }

                if (result) {
                  if (att.isNominal()) {
                    if (label == null) {
                      // inst.setMissing(att);
                      System.err.println("This shouldn't happen!!");
                    } else {
                      inst.setValue(att, att.indexOfValue(label));
                    }
                  } else {
                    // numeric binary attribute
                    inst.setValue(att, 1);
                  }
                } else {
                  if (att.isNominal()) {
                    inst.setMissing(att);
                  } else {
                    inst.setValue(att, 0);
                  }
                }
View Full Code Here

        // granularity than the primary sequence
        m_secondaryPeriodicLookups = new HashMap<Attribute, Map<String, String>>();

        for (int i = 0; i < insts.numAttributes(); i++) {
          if (insts.attribute(i).isNominal() && i != primaryIndex) {
            Attribute candidate = insts.attribute(i);
            Map<String, String> candidateMap = new HashMap<String, String>();
            for (int j = 0; j < insts.numInstances(); j++) {
              Instance current = insts.instance(j);
              if (!Utils.isMissingValue(current.value(primaryIndex))
                  && !Utils.isMissingValue(j)) {
View Full Code Here

              .indexOfValue(successor));

          // now we can look for secondary periodic attributes
          if (m_secondaryPeriodicLookups != null) {
            for (int i = 0; i < m_originalHeader.numAttributes(); i++) {
              Attribute current = m_originalHeader.attribute(i);
              Map<String, String> correspondingL = m_secondaryPeriodicLookups
                  .get(current);
              if (correspondingL != null) {
                String correspondingV = correspondingL.get(successor);
                if (correspondingV != null) {
View Full Code Here

   * @return the header
   */
  private Instances makeHeader() {

    FastVector fv = new FastVector();
    fv.addElement(new Attribute(TRUE_POS_NAME));
    fv.addElement(new Attribute(FALSE_NEG_NAME));
    fv.addElement(new Attribute(FALSE_POS_NAME));
    fv.addElement(new Attribute(TRUE_NEG_NAME));
    fv.addElement(new Attribute(FP_RATE_NAME));
    fv.addElement(new Attribute(TP_RATE_NAME));
    fv.addElement(new Attribute(PRECISION_NAME));
    fv.addElement(new Attribute(RECALL_NAME));
    fv.addElement(new Attribute(FALLOUT_NAME));
    fv.addElement(new Attribute(FMEASURE_NAME));
    fv.addElement(new Attribute(SAMPLE_SIZE_NAME));
    fv.addElement(new Attribute(LIFT_NAME));
    fv.addElement(new Attribute(THRESHOLD_NAME));     
    return new Instances(RELATION_NAME, fv, 100);
  }
View Full Code Here

        query.append(" ");
        query.append(m_createInt);
        query.append(" PRIMARY KEY,");
      }
      for(int i = 0;i < structure.numAttributes(); i++){
          Attribute att = structure.attribute(i);
          String attName = att.name();
          attName = attName.replaceAll("[^\\w]","_");
          attName = m_DataBaseConnection.maskKeyword(attName);
          if(m_DataBaseConnection.getUpperCase())
              query.append(attName.toUpperCase());
          else
              query.append(attName);
          if(att.isDate())
              query.append(" " + m_createDate);
          else{
              if(att.isNumeric())
                  query.append(" "+m_createDouble);
              else
                  query.append(" "+m_createText);
          }
          if(i != structure.numAttributes()-1)
View Full Code Here

        ArrayList<Attribute> atts = new ArrayList<Attribute>();
        for (int i = 0; i < m_header.numAttributes(); i++) {
          atts.add((Attribute) m_header.attribute(i).copy());
        }
        for (String f : m_fieldsToForecast) {
          Attribute lb = new Attribute(f + "_lowerBound");
          Attribute ub = new Attribute(f + "_upperBound");
          atts.add(lb);
          atts.add(ub);
        }
        m_outgoingStructure = new Instances(m_header.relationName() + "_"
            + "plus_forecast", atts, 0);
View Full Code Here

    // data then we can just fill in the forecasted values (and
    // potentially add for confidence intervals)
    double time = lastTimeFromPrime;
    int timeStampIndex = -1;
    if (m_timeStampName.length() > 0) {
      Attribute timeStampAtt = m_outgoingStructure.attribute(m_timeStampName);
      if (timeStampAtt == null) {
        statusError();
        logError("couldn't find time stamp: " + m_timeStampName
            + "in the input data", null);
        stop();
        return;
      }
      timeStampIndex = timeStampAtt.index();
    }

    statusMessage("Generating forecast...");
    logMessage("Generating forecast.");
    for (int i = 0; i < numSteps; i++) {
View Full Code Here

      return;
    }
   
    if (m_simpleConfigPanel.isUsingANativeTimeStamp()) {
      String timeStampF = m_simpleConfigPanel.getSelectedTimeStampField();
      Attribute timeStampAtt = m_instances.attribute(timeStampF);
      if (timeStampAtt != null) {
       
        double lastNonMissing = Utils.missingValue();
        boolean ok = true;
        boolean hasMissing = false;
View Full Code Here

    final int WORDS_TO_KEEP = 200; //need larger word vectors for better results
    final int RUNTIME = 300 * (60000);//change first term to number of minutes
   
    //Build the Instances Header
    ArrayList<Attribute> att = new ArrayList<Attribute>();
    att.add(new Attribute("title", (List<String>)null, 0));
    att.add(new Attribute("redditClass", subreddits, 1));
    Instances instHeaders = new Instances("reddit",att, 10);
    instHeaders.setClassIndex(1);
   
    /**
     * Start building the topology
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.