Package weka.core

Examples of weka.core.Instance


     * @see      #getData()
     */
    public ArffReader(Reader reader, Instances template, int lines) throws IOException {
      this(reader, template, lines, 100);

      Instance inst;
      while ((inst = readInstance(m_Data)) != null) {
        m_Data.add(inst);
      };

      compactify();
View Full Code Here


      // Add instance to dataset
      double[] tempValues = new double[numValues];
      int[] tempIndices = new int[numValues];
      System.arraycopy(m_ValueBuffer, 0, tempValues, 0, numValues);
      System.arraycopy(m_IndicesBuffer, 0, tempIndices, 0, numValues);
      Instance inst = new SparseInstance(weight, tempValues, tempIndices, m_Data.numAttributes());
      inst.setDataset(m_Data);
     
      return inst;
    }
View Full Code Here

          weight = 1.0;
        }
      }
       
      // Add instance to dataset
      Instance inst = new DenseInstance(weight, instance);
      inst.setDataset(m_Data);
     
      return inst;
    }
View Full Code Here

     
      Instances cBCurve = m_costBenefit.getPlotInstances();
      int maxMinIndex = 0;
     
      for (int i = 0; i < cBCurve.numInstances(); i++) {
        Instance current = cBCurve.instance(i);
        if (max) {
          if (current.value(1) > maxMin) {
            maxMin = current.value(1);
            maxMinIndex = i;
          }
        } else {
          if (current.value(1) < maxMin) {
            maxMin = current.value(1);
            maxMinIndex = i;
          }
        }
      }
     
View Full Code Here

      double CB = m_costBenefit.
        getPlotInstances().instance(index).value(1);
      m_costBenefitV.setText(Utils.doubleToString(CB,2));
     
      double totalRandomCB = 0.0;
      Instance first = m_masterPlot.getPlotInstances().instance(0);
      double totalPos = first.value(m_masterPlot.getPlotInstances().
          attribute(ThresholdCurve.TRUE_POS_NAME).index()) * scaleFactor;
      double totalNeg = first.value(m_masterPlot.getPlotInstances().
          attribute(ThresholdCurve.FALSE_POS_NAME)) * scaleFactor;

      double posInSample = (totalPos * (Double.parseDouble(m_percPopLab.getText()) / 100.0));
      double negInSample = (totalNeg * (Double.parseDouble(m_percPopLab.getText()) / 100.0));
      double posOutSample = totalPos - posInSample;
      double negOutSample = totalNeg - negInSample;
     
      double tpCost = 0.0;
      try {
        tpCost = Double.parseDouble(m_cost_aa.getText());
      } catch (NumberFormatException n) {}
      double fpCost = 0.0;
      try {
        fpCost = Double.parseDouble(m_cost_ba.getText());
      } catch (NumberFormatException n) {}
      double tnCost = 0.0;
      try {
        tnCost = Double.parseDouble(m_cost_bb.getText());
      } catch (NumberFormatException n) {}
      double fnCost = 0.0;
      try {
        fnCost = Double.parseDouble(m_cost_ab.getText());
      } catch (NumberFormatException n) {}
           
      totalRandomCB += posInSample * tpCost;
      totalRandomCB += negInSample * fpCost;
      totalRandomCB += posOutSample * fnCost;
      totalRandomCB += negOutSample * tnCost;
     
      m_randomV.setText(Utils.doubleToString(totalRandomCB, 2));
      double gain = (m_costR.isSelected())
      ? totalRandomCB - CB
          : CB - totalRandomCB;
      m_gainV.setText(Utils.doubleToString(gain, 2));
     
      // update classification rate
      Instance currentInst = m_masterPlot.getPlotInstances().instance(index);
      double tp = currentInst.value(m_masterPlot.getPlotInstances().
          attribute(ThresholdCurve.TRUE_POS_NAME).index());
      double tn = currentInst.value(m_masterPlot.getPlotInstances().
          attribute(ThresholdCurve.TRUE_NEG_NAME).index());
      m_classificationAccV.
        setText(Utils.doubleToString((tp + tn) / (totalPos + totalNeg) * 100.0, 4) + "%");     
    }
View Full Code Here

//      double totalInstances =
      int tp = plotInstances.attribute(ThresholdCurve.TRUE_POS_NAME).index();
      int fp = plotInstances.attribute(ThresholdCurve.FALSE_POS_NAME).index();
      int tn = plotInstances.attribute(ThresholdCurve.TRUE_NEG_NAME).index();
      int fn = plotInstances.attribute(ThresholdCurve.FALSE_NEG_NAME).index();
      Instance temp = plotInstances.instance(index);
      double totalInstances = temp.value(tp) + temp.value(fp) + temp.value(tn) + temp.value(fn);
      // get the value out of the total pop field (if possible)
      double requestedPopSize = totalInstances;
      try {
        requestedPopSize = Double.parseDouble(m_totalPopField.getText());
      } catch (NumberFormatException e) {}
     
      m_conf_aa.setCellValue(temp.value(tp), totalInstances,
          requestedPopSize / totalInstances, 2);
      m_conf_ab.setCellValue(temp.value(fn), totalInstances,
          requestedPopSize / totalInstances, 2);
      m_conf_ba.setCellValue(temp.value(fp), totalInstances,
          requestedPopSize / totalInstances, 2);
      m_conf_bb.setCellValue(temp.value(tn), totalInstances,
            requestedPopSize / totalInstances, 2);
     
      updateCBRandomGainInfo(index);
     
      repaint();
View Full Code Here

      m_tnPrevious = 0;
      m_fnPrevious = 0;
      m_previousShapeIndex = -1;

      // set the total population size
      Instance first = m_masterPlot.getPlotInstances().instance(0);
      double totalPos = first.value(m_masterPlot.getPlotInstances().
          attribute(ThresholdCurve.TRUE_POS_NAME).index());
      double totalNeg = first.value(m_masterPlot.getPlotInstances().
          attribute(ThresholdCurve.FALSE_POS_NAME));
      m_originalPopSize = (int)(totalPos + totalNeg);
      m_totalPopField.setText("" + m_originalPopSize);

      m_performancePanel.setYIndex(5);
View Full Code Here

     
      // process the performance data to make this curve
      Instances performanceI = m_masterPlot.getPlotInstances();
     
      for (int i = 0; i < performanceI.numInstances(); i++) {
        Instance current = performanceI.instance(i);
       
        double[] vals = new double[2];
        vals[0] = current.value(10); // sample size
        vals[1] = (current.value(0) * tpCost
            + current.value(1) * fnCost
            + current.value(2) * fpCost
            + current.value(3) * tnCost) * scaleFactor;
        Instance newInst = new DenseInstance(1.0, vals);
        costBenefitI.add(newInst);
      }
     
      costBenefitI.compactify();
     
View Full Code Here

   * @param inst  the JSON object to turn into an Instance
   * @param data  the data so far (only used for header information)
   * @return    the Instance, null in case of an error
   */
  protected static Instance toInstance(JSONNode inst, Instances data) {
    Instance  result;
    boolean  sparse;
    double  weight;
    JSONNode  values;
    int    i;
    int    index;
    int    pos;
    String  value;
    double[]  vals;

    sparse = (Boolean) inst.getChild(SPARSE).getValue(new Boolean(false));
    weight = (Double) inst.getChild(WEIGHT).getValue(new Double(1.0));
    values = inst.getChild(VALUES);
    vals   = new double[data.numAttributes()];
    for (i = 0; i < values.getChildCount(); i++) {
      if (sparse) {
  value = "" + ((JSONNode) values.getChildAt(i)).getValue();
  pos   = value.indexOf(SPARSE_SEPARATOR);
  index = Integer.parseInt(value.substring(0, pos));
  value = value.substring(pos + 1);
      }
      else {
  index = i;
  value = "" + ((JSONNode) values.getChildAt(i)).getValue();
      }
     
      try {
  if (data.attribute(index).isNumeric()) {
    vals[index] = Double.parseDouble(value);
  }
  else if (data.attribute(index).isNominal()) {
    vals[index] = data.attribute(index).indexOfValue(value);
    if ((vals[index] == -1) && value.startsWith("'") && value.endsWith("'"))
      vals[index] = data.attribute(index).indexOfValue(Utils.unquote(value));
    // FIXME backslashes seem to get escaped twice when creating a JSON file?
    if ((vals[index] == -1) && value.startsWith("'") && value.endsWith("'"))
      vals[index] = data.attribute(index).indexOfValue(Utils.unbackQuoteChars(Utils.unquote(value)));
    if (vals[index] == -1) {
      System.err.println("Unknown label '" + value + "' for attribute #" + (index+1) + "!");
      return null;
    }
  }
  else if (data.attribute(index).isDate()) {
    vals[index] = data.attribute(index).parseDate(value);
  }
  else if (data.attribute(index).isString()) {
    vals[index] = data.attribute(index).addStringValue(value);
  }
  else {
    System.err.println("Unhandled attribute type '" + Attribute.typeToString(data.attribute(index).type()) + "'!");
    return null;
  }
      }
      catch (Exception e) {
  System.err.println("Error parsing value #" + (index+1) + ": " + e.toString());
  return null;
      }
    }

    result = new DenseInstance(weight, vals);
    result.setDataset(data);
     
    return result;
  }
View Full Code Here

    JSONNode  header;
    JSONNode  attributes;
    JSONNode  data;
    ArrayList<Attribute>  atts;
    Attribute  att;
    Instance  inst;
    int    i;
    int    classIndex;
    boolean[]  classAtt;
   
    header = json.getChild(HEADER);
View Full Code Here

TOP

Related Classes of weka.core.Instance

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.