• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java Plot2D类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中weka.gui.visualize.Plot2D的典型用法代码示例。如果您正苦于以下问题:Java Plot2D类的具体用法?Java Plot2D怎么用?Java Plot2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

Plot2D类属于weka.gui.visualize包,在下文中一共展示了Plot2D类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: process

点赞 2

import weka.gui.visualize.Plot2D; //导入依赖的package包/类
/**
  * Generates the cluster assignments.
  * 
  * @see		#m_PlotShapes
  * @see		#m_PlotSizes
  * @see		#m_PlotInstances
  */
 protected void process() {
   double[] 	clusterAssignments;
   int		i;
   double[] 	values;
   int 	j;
   int[] 	classAssignments;
   
   clusterAssignments = m_Evaluation.getClusterAssignments();
   
   classAssignments   = null;
   if (m_Instances.classIndex() >= 0) {
     classAssignments = m_Evaluation.getClassesToClusters();
     m_PlotShapes = new int[m_Instances.numInstances()];
     for (i = 0; i < m_Instances.numInstances(); i++)
m_PlotShapes[i] = Plot2D.CONST_AUTOMATIC_SHAPE;
   }

   for (i = 0; i < m_Instances.numInstances(); i++) {
     values = new double[m_PlotInstances.numAttributes()];
     for (j = 0; j < m_Instances.numAttributes(); j++)
values[j] = m_Instances.instance(i).value(j);
     if (clusterAssignments[i] < 0) {
       values[j] = Utils.missingValue();
     } else {
       values[j] = clusterAssignments[i];
     }
     m_PlotInstances.add(new DenseInstance(1.0, values));
     if (m_PlotShapes != null) {
       if (clusterAssignments[i] >= 0) {
         if ((int) m_Instances.instance(i).classValue() != classAssignments[(int) clusterAssignments[i]])
           m_PlotShapes[i] = Plot2D.ERROR_SHAPE;
       } else {
         m_PlotShapes[i] = Plot2D.MISSING_SHAPE;
       }
     }
   }
 }
 

开发者ID:dsibournemouth,
项目名称:autoweka,
代码行数:45,
代码来源:ClustererAssignmentsPlotInstances.java

示例2: process

点赞 2

import weka.gui.visualize.Plot2D; //导入依赖的package包/类
/**
 * Generates the cluster assignments.
 * 
 * @see #m_PlotShapes
 * @see #m_PlotSizes
 * @see #m_PlotInstances
 */
protected void process() {
  double[] clusterAssignments;
  int i;
  double[] values;
  int j;
  int[] classAssignments;

  clusterAssignments = m_Evaluation.getClusterAssignments();

  classAssignments = null;
  if (m_Instances.classIndex() >= 0) {
    classAssignments = m_Evaluation.getClassesToClusters();
    m_PlotShapes = new int[m_Instances.numInstances()];
    for (i = 0; i < m_Instances.numInstances(); i++) {
      m_PlotShapes[i] = Plot2D.CONST_AUTOMATIC_SHAPE;
    }
  }

  for (i = 0; i < m_Instances.numInstances(); i++) {
    values = new double[m_PlotInstances.numAttributes()];
    for (j = 0; j < m_Instances.numAttributes(); j++) {
      values[j] = m_Instances.instance(i).value(j);
    }
    if (clusterAssignments[i] < 0) {
      values[j] = Utils.missingValue();
    } else {
      values[j] = clusterAssignments[i];
    }
    m_PlotInstances.add(new DenseInstance(1.0, values));
    if (m_PlotShapes != null) {
      if (clusterAssignments[i] >= 0) {
        if ((int) m_Instances.instance(i).classValue() != classAssignments[(int) clusterAssignments[i]]) {
          m_PlotShapes[i] = Plot2D.ERROR_SHAPE;
        }
      } else {
        m_PlotShapes[i] = Plot2D.MISSING_SHAPE;
      }
    }
  }
}
 

开发者ID:mydzigear,
项目名称:repo.kmeanspp.silhouette_score,
代码行数:48,
代码来源:ClustererAssignmentsPlotInstances.java

示例3: renderXYLineChart

点赞 2

import weka.gui.visualize.Plot2D; //导入依赖的package包/类
/**
 * Render an XY line chart
 * 
 * @param width the width of the resulting chart in pixels
 * @param height the height of the resulting chart in pixels
 * @param series a list of Instances - one for each series to be plotted
 * @param xAxis the name of the attribute for the x-axis (all series Instances 
 * are expected to have an attribute of the same type with this name)
 * @param yAxis the name of the attribute for the y-axis (all series Instances 
 * are expected to have an attribute of the same type with this name)
 * @param optionalArgs optional arguments to the renderer (may be null)
 * 
 * @return a BufferedImage containing the chart
 * @throws Exception if there is a problem rendering the chart
 */
public BufferedImage renderXYLineChart(int width, int height,
    List<Instances> series, String xAxis, String yAxis,
    List<String> optionalArgs) throws Exception {
  BufferedImage osi = new BufferedImage(width, height, 
      BufferedImage.TYPE_INT_RGB);
  
  String plotTitle = "Line chart";
  String userTitle = getOption(optionalArgs, "-title");
  plotTitle = (userTitle != null) ? userTitle : plotTitle;
  
  Plot2D offScreenPlot = new Plot2D();
  offScreenPlot.setSize(width, height);
  
  // master plot
  PlotData2D master = new PlotData2D(series.get(0));
  master.setPlotName(plotTitle);
  boolean[] connectPoints = new boolean[series.get(0).numInstances()];
  for (int i = 0; i < connectPoints.length; i++) {
    connectPoints[i] = true;
  }
  master.setConnectPoints(connectPoints);
  offScreenPlot.setMasterPlot(master);
  // find x and y axis
  Instances masterInstances = series.get(0);
  int xAx = getIndexOfAttribute(masterInstances, xAxis);
  int yAx = getIndexOfAttribute(masterInstances, yAxis);
  if (xAx < 0) {
    xAx = 0;
  }
  if (yAx < 0) {
    yAx = 0;
  }
  
  // plotting axes and color
  offScreenPlot.setXindex(xAx);
  offScreenPlot.setYindex(yAx);
  offScreenPlot.setCindex(masterInstances.numAttributes() - 1);
  String colorAtt = getOption(optionalArgs, "-color");
  int tempC = getIndexOfAttribute(masterInstances, colorAtt);
  if (tempC >= 0) {
    offScreenPlot.setCindex(tempC);
  }
  
  // additional plots
  if (series.size() > 1) {
    for (Instances plotI : series) {
      PlotData2D plotD = new PlotData2D(plotI);
      connectPoints = new boolean[plotI.numInstances()];
      for (int i = 0; i < connectPoints.length; i++) {
        connectPoints[i] = true;
      }
      plotD.setConnectPoints(connectPoints);
      offScreenPlot.addPlot(plotD);
    }
  }
  
  // render
  java.awt.Graphics g = osi.getGraphics();
  offScreenPlot.paintComponent(g);
  
  return osi;
}
 

开发者ID:mydzigear,
项目名称:repo.kmeanspp.silhouette_score,
代码行数:78,
代码来源:WekaOffscreenChartRenderer.java

示例4: process

点赞 2

import weka.gui.visualize.Plot2D; //导入依赖的package包/类
public void process(Instances batch, double[][] predictions, Evaluation eval) {
  try {      
    
    for (int j = 0; j < batch.numInstances(); j++) {
      Instance toPredict = batch.instance(j);
      double[] preds = predictions[j];
      
      double pred = 0;
      if (batch.classAttribute().isNominal()) {
        pred = (Utils.sum(preds) == 0) 
        ? Utils.missingValue() : Utils.maxIndex(preds);
      } else {
        pred = preds[0];
      }
      
      eval.evaluationForSingleInstance(preds, toPredict, true);

      if (!m_SaveForVisualization) {
        continue;
      }

      if (m_PlotInstances != null) {
        double[] values = new double[m_PlotInstances.numAttributes()];
        for (int i = 0; i < m_PlotInstances.numAttributes(); i++) {
          if (i < toPredict.classIndex()) {
            values[i] = toPredict.value(i);
          }
          else if (i == toPredict.classIndex()) {
            values[i]   = pred;
            values[i+1] = toPredict.value(i);
            i++;
          }
          else {
            values[i] = toPredict.value(i-1);
          }
        }

        m_PlotInstances.add(new DenseInstance(1.0, values));

        if (toPredict.classAttribute().isNominal()) {
          if (toPredict.isMissing(toPredict.classIndex()) || Utils.isMissingValue(pred)) {
            m_PlotShapes.addElement(new Integer(Plot2D.MISSING_SHAPE));
          }
          else if (pred != toPredict.classValue()) {
            // set to default error point shape
            m_PlotShapes.addElement(new Integer(Plot2D.ERROR_SHAPE));
          }
          else {
            // otherwise set to constant (automatically assigned) point shape
            m_PlotShapes.addElement(new Integer(Plot2D.CONST_AUTOMATIC_SHAPE));
          }
          m_PlotSizes.addElement(new Integer(Plot2D.DEFAULT_SHAPE_SIZE));
        }
        else {
          // store the error (to be converted to a point size later)
          Double errd = null;
          if (!toPredict.isMissing(toPredict.classIndex()) && !Utils.isMissingValue(pred)) {
            errd = new Double(pred - toPredict.classValue());
            m_PlotShapes.addElement(new Integer(Plot2D.CONST_AUTOMATIC_SHAPE));
          }
          else {
            // missing shape if actual class not present or prediction is missing
            m_PlotShapes.addElement(new Integer(Plot2D.MISSING_SHAPE));
          }
          m_PlotSizes.addElement(errd);
        }
      }
    }      
  } catch (Exception ex) {
    ex.printStackTrace();
  }
}
 

开发者ID:dsibournemouth,
项目名称:autoweka,
代码行数:73,
代码来源:ClassifierErrorsPlotInstances.java

示例5: setUpVisualizableInstances

点赞 2

import weka.gui.visualize.Plot2D; //导入依赖的package包/类
/**
 * Sets up the structure for the visualizable instances. This dataset contains
 * the original attributes plus the clusterer's cluster assignments
 * 
 * @param testInstances the instances that the clusterer has clustered
 * @param eval the evaluation to use
 * @return a PlotData2D object encapsulating the visualizable instances. The
 *         instances contain one more attribute (predicted cluster) than the
 *         testInstances
 */
public static PlotData2D setUpVisualizableInstances(Instances testInstances,
    ClusterEvaluation eval) throws Exception {

  int numClusters = eval.getNumClusters();
  double[] clusterAssignments = eval.getClusterAssignments();

  FastVector hv = new FastVector();
  Instances newInsts;

  Attribute predictedCluster;
  FastVector clustVals = new FastVector();

  for (int i = 0; i < numClusters; i++) {
    clustVals.addElement(Messages.getInstance().getString(
        "ClustererPanel_SetUpVisualizableInstances_ClustVals_Text")
        + i);
  }
  predictedCluster = new Attribute(Messages.getInstance().getString(
      "ClustererPanel_SetUpVisualizableInstances_PredictedCluster_Text"),
      clustVals);
  for (int i = 0; i < testInstances.numAttributes(); i++) {
    hv.addElement(testInstances.attribute(i).copy());
  }
  hv.addElement(predictedCluster);

  newInsts = new Instances(testInstances.relationName() + "_clustered", hv,
      testInstances.numInstances());

  double[] values;
  int j;
  int[] pointShapes = null;
  int[] classAssignments = null;
  if (testInstances.classIndex() >= 0) {
    classAssignments = eval.getClassesToClusters();
    pointShapes = new int[testInstances.numInstances()];
    for (int i = 0; i < testInstances.numInstances(); i++) {
      pointShapes[i] = Plot2D.CONST_AUTOMATIC_SHAPE;
    }
  }

  for (int i = 0; i < testInstances.numInstances(); i++) {
    values = new double[newInsts.numAttributes()];
    for (j = 0; j < testInstances.numAttributes(); j++) {
      values[j] = testInstances.instance(i).value(j);
    }
    if (clusterAssignments[i] < 0) {
      values[j] = Instance.missingValue();
    } else {
      values[j] = clusterAssignments[i];
    }
    newInsts.add(new Instance(1.0, values));
    if (pointShapes != null) {
      if (clusterAssignments[i] >= 0) {
        if ((int) testInstances.instance(i).classValue() != classAssignments[(int) clusterAssignments[i]]) {
          pointShapes[i] = Plot2D.ERROR_SHAPE;
        }
      } else {
        pointShapes[i] = Plot2D.MISSING_SHAPE;
      }
    }
  }
  PlotData2D plotData = new PlotData2D(newInsts);
  if (pointShapes != null) {
    plotData.setShapeType(pointShapes);
  }
  plotData.addInstanceNumberAttribute();
  return plotData;
}
 

开发者ID:williamClanton,
项目名称:jbossBA,
代码行数:79,
代码来源:ClustererPanel.java

示例6: processClassifierPrediction

点赞 2

import weka.gui.visualize.Plot2D; //导入依赖的package包/类
/**
 * Process a classifier's prediction for an instance and update a set of
 * plotting instances and additional plotting info. plotInfo for nominal class
 * datasets holds shape types (actual data points have automatic shape type
 * assignment; classifier error data points have box shape type). For numeric
 * class datasets, the actual data points are stored in plotInstances and
 * plotInfo stores the error (which is later converted to shape size values)
 * 
 * @param toPredict the actual data point
 * @param classifier the classifier
 * @param eval the evaluation object to use for evaluating the classifier on
 *          the instance to predict
 * @param plotInstances a set of plottable instances
 * @param plotShape additional plotting information (shape)
 * @param plotSize additional plotting information (size)
 */
public static void processClassifierPrediction(Instance toPredict,
  Classifier classifier, Evaluation eval, Instances plotInstances,
  FastVector plotShape, FastVector plotSize) {
  try {
    double pred = eval.evaluateModelOnceAndRecordPrediction(classifier,
      toPredict);

    if (plotInstances != null) {
      double[] values = new double[plotInstances.numAttributes()];
      for (int i = 0; i < plotInstances.numAttributes(); i++) {
        if (i < toPredict.classIndex()) {
          values[i] = toPredict.value(i);
        } else if (i == toPredict.classIndex()) {
          values[i] = pred;
          values[i + 1] = toPredict.value(i);
          /*
           * // if the class value of the instances to predict is missing then
           * // set it to the predicted value if (toPredict.isMissing(i)) {
           * values[i+1] = pred; }
           */
          i++;
        } else {
          values[i] = toPredict.value(i - 1);
        }
      }

      plotInstances.add(new Instance(1.0, values));
      if (toPredict.classAttribute().isNominal()) {
        if (toPredict.isMissing(toPredict.classIndex())
          || Instance.isMissingValue(pred)) {
          plotShape.addElement(new Integer(Plot2D.MISSING_SHAPE));
        } else if (pred != toPredict.classValue()) {
          // set to default error point shape
          plotShape.addElement(new Integer(Plot2D.ERROR_SHAPE));
        } else {
          // otherwise set to constant (automatically assigned) point shape
          plotShape.addElement(new Integer(Plot2D.CONST_AUTOMATIC_SHAPE));
        }
        plotSize.addElement(new Integer(Plot2D.DEFAULT_SHAPE_SIZE));
      } else {
        // store the error (to be converted to a point size later)
        Double errd = null;
        if (!toPredict.isMissing(toPredict.classIndex())
          && !Instance.isMissingValue(pred)) {
          errd = new Double(pred - toPredict.classValue());
          plotShape.addElement(new Integer(Plot2D.CONST_AUTOMATIC_SHAPE));
        } else {
          // missing shape if actual class not present or prediction is
          // missing
          plotShape.addElement(new Integer(Plot2D.MISSING_SHAPE));
        }
        plotSize.addElement(errd);
      }
    }
  } catch (Exception ex) {
    ex.printStackTrace();
  }
}
 

开发者ID:williamClanton,
项目名称:jbossBA,
代码行数:75,
代码来源:ClassifierPanel.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)