Refine search
/** * Get the computed quantiles for the named attribute * * @param attName the attribute to get the current computed quantiles for * @return the current values of the quantiles * @throws Exception if a problem occurs */ public double[] getQuantiles(String attName) throws Exception { Attribute att = m_header.attribute(attName); if (att == null) { throw new Exception("Unknown attribute: " + attName); } if (!att.isNumeric()) { throw new Exception("Attribute '" + attName + "' is not numeric"); } int index = att.index(); List<IncrementalQuantileEstimator> l = m_estimators.get(index); double[] quantiles = new double[l.size()]; for (int i = 0; i < l.size(); i++) { quantiles[i] = l.get(i).getQuantile(); } return quantiles; }
/** * Gets the array with indices of feature attributes stored in * underlying {@link Instances} data set. * * @return an array with the indices of the feature attributes */ public int[] getFeatureIndices() { int numAttributes = dataSet.numAttributes(); Set<Attribute> featureAttributes = getFeatureAttributes(); int[] featureIndices = new int[featureAttributes.size()]; int counter = 0; for (int index = 0; index < numAttributes; index++) { Attribute attr = dataSet.attribute(index); if (featureAttributes.contains(attr)) { featureIndices[counter] = attr.index(); counter++; } } return featureIndices; }
private void updateCostBenefit() { double value = m_thresholdSlider.getValue() / 100.0; Instances plotInstances = m_masterPlot.getPlotInstances(); int indexOfSampleSize = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.SAMPLE_SIZE_NAME).index(); int indexOfPercOfTarget = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.RECALL_NAME).index(); int indexOfThreshold = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.THRESHOLD_NAME).index(); int indexOfMetric; if (m_percPop.isSelected()) { indexOfMetric = indexOfSampleSize; } else if (m_percOfTarget.isSelected()) { indexOfMetric = indexOfPercOfTarget; } else { indexOfMetric = indexOfThreshold; } int index = findIndexForValue(value, plotInstances, indexOfMetric); updateCBRandomGainInfo(index); }
private void updateCostBenefit() { double value = m_thresholdSlider.getValue() / 100.0; Instances plotInstances = m_masterPlot.getPlotInstances(); int indexOfSampleSize = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.SAMPLE_SIZE_NAME).index(); int indexOfPercOfTarget = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.RECALL_NAME).index(); int indexOfThreshold = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.THRESHOLD_NAME).index(); int indexOfMetric; if (m_percPop.isSelected()) { indexOfMetric = indexOfSampleSize; } else if (m_percOfTarget.isSelected()) { indexOfMetric = indexOfPercOfTarget; } else { indexOfMetric = indexOfThreshold; } int index = findIndexForValue(value, plotInstances, indexOfMetric); updateCBRandomGainInfo(index); }
private void updateInfoForSliderValue(double value) { int indexOfSampleSize = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.SAMPLE_SIZE_NAME).index(); int indexOfPercOfTarget = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.RECALL_NAME).index(); int indexOfThreshold = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.THRESHOLD_NAME).index(); int indexOfMetric; if (m_percPop.isSelected()) { indexOfMetric = indexOfSampleSize; } else if (m_percOfTarget.isSelected()) { indexOfMetric = indexOfPercOfTarget; } else { indexOfMetric = indexOfThreshold; } Instances plotInstances = m_masterPlot.getPlotInstances(); int index = findIndexForValue(value, plotInstances, indexOfMetric); updateInfoGivenIndex(index); }
private void updateInfoForSliderValue(double value) { int indexOfSampleSize = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.SAMPLE_SIZE_NAME).index(); int indexOfPercOfTarget = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.RECALL_NAME).index(); int indexOfThreshold = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.THRESHOLD_NAME).index(); int indexOfMetric; if (m_percPop.isSelected()) { indexOfMetric = indexOfSampleSize; } else if (m_percOfTarget.isSelected()) { indexOfMetric = indexOfPercOfTarget; } else { indexOfMetric = indexOfThreshold; } Instances plotInstances = m_masterPlot.getPlotInstances(); int index = findIndexForValue(value, plotInstances, indexOfMetric); updateInfoGivenIndex(index); }
/** * Sets the combobox indices. * * @param data the threshold curve data * @param panel the panel * @throws Exception if setting of indices fails */ protected void setComboBoxIndices(Instances data, ThresholdVisualizePanel panel) throws Exception { if (data.attribute(getDefaultXColumn()) != null) panel.setXIndex(data.attribute(getDefaultXColumn()).index()); if (data.attribute(getDefaultYColumn()) != null) panel.setYIndex(data.attribute(getDefaultYColumn()).index()); }
/** * Sets the combobox indices. * * @param data the threshold curve data * @param panel the panel * @throws Exception if setting of indices fails */ protected void setComboBoxIndices(Instances data, ThresholdVisualizePanel panel) throws Exception { if (data.attribute(getDefaultXColumn()) != null) panel.setXIndex(data.attribute(getDefaultXColumn()).index()); if (data.attribute(getDefaultYColumn()) != null) panel.setYIndex(data.attribute(getDefaultYColumn()).index()); }
private void updateInfoForSliderValue(double value) { int indexOfSampleSize = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.SAMPLE_SIZE_NAME).index(); int indexOfPercOfTarget = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.RECALL_NAME).index(); int indexOfThreshold = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.THRESHOLD_NAME).index(); int indexOfMetric; if (m_percPop.isSelected()) { indexOfMetric = indexOfSampleSize; } else if (m_percOfTarget.isSelected()) { indexOfMetric = indexOfPercOfTarget; } else { indexOfMetric = indexOfThreshold; } Instances plotInstances = m_masterPlot.getPlotInstances(); int index = findIndexForValue(value, plotInstances, indexOfMetric); updateInfoGivenIndex(index); }
private void updateCostBenefit() { double value = m_thresholdSlider.getValue() / 100.0; Instances plotInstances = m_masterPlot.getPlotInstances(); int indexOfSampleSize = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.SAMPLE_SIZE_NAME).index(); int indexOfPercOfTarget = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.RECALL_NAME).index(); int indexOfThreshold = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.THRESHOLD_NAME).index(); int indexOfMetric; if (m_percPop.isSelected()) { indexOfMetric = indexOfSampleSize; } else if (m_percOfTarget.isSelected()) { indexOfMetric = indexOfPercOfTarget; } else { indexOfMetric = indexOfThreshold; } int index = findIndexForValue(value, plotInstances, indexOfMetric); updateCBRandomGainInfo(index); }
private void updateInfoForSliderValue(double value) { int indexOfSampleSize = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.SAMPLE_SIZE_NAME).index(); int indexOfPercOfTarget = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.RECALL_NAME).index(); int indexOfThreshold = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.THRESHOLD_NAME).index(); int indexOfMetric; if (m_percPop.isSelected()) { indexOfMetric = indexOfSampleSize; } else if (m_percOfTarget.isSelected()) { indexOfMetric = indexOfPercOfTarget; } else { indexOfMetric = indexOfThreshold; } Instances plotInstances = m_masterPlot.getPlotInstances(); int index = findIndexForValue(value, plotInstances, indexOfMetric); updateInfoGivenIndex(index); }
private void updateCostBenefit() { double value = m_thresholdSlider.getValue() / 100.0; Instances plotInstances = m_masterPlot.getPlotInstances(); int indexOfSampleSize = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.SAMPLE_SIZE_NAME).index(); int indexOfPercOfTarget = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.RECALL_NAME).index(); int indexOfThreshold = m_masterPlot.getPlotInstances() .attribute(ThresholdCurve.THRESHOLD_NAME).index(); int indexOfMetric; if (m_percPop.isSelected()) { indexOfMetric = indexOfSampleSize; } else if (m_percOfTarget.isSelected()) { indexOfMetric = indexOfPercOfTarget; } else { indexOfMetric = indexOfThreshold; } int index = findIndexForValue(value, plotInstances, indexOfMetric); updateCBRandomGainInfo(index); }
/** * Renames the value of a nominal (or string) attribute value. This change * only affects this dataset. * * @param att the attribute's index (index starts with 0) * @param val the value's index (index starts with 0) * @param name the new name */ public void renameAttributeValue(int att, int val, String name) { Attribute newAtt = (Attribute) attribute(att).copy(); ArrayList<Attribute> newVec = new ArrayList<Attribute>(numAttributes()); newAtt.setValue(val, name); for (Attribute attr : m_Attributes) { if (attr.index() == att) { newVec.add(newAtt); } else { newVec.add(attr); } } m_Attributes = newVec; }
/** * Renames the value of a nominal (or string) attribute value. This change * only affects this dataset. * * @param att the attribute's index (index starts with 0) * @param val the value's index (index starts with 0) * @param name the new name */ public void renameAttributeValue(int att, int val, String name) { Attribute newAtt = (Attribute) attribute(att).copy(); ArrayList<Attribute> newVec = new ArrayList<Attribute>(numAttributes()); newAtt.setValue(val, name); for (Attribute attr : m_Attributes) { if (attr.index() == att) { newVec.add(newAtt); } else { newVec.add(attr); } } m_Attributes = newVec; }
protected int getAttIndex(String attName, Instances data) throws WekaException { attName = environmentSubstitute(attName); int index = -1; if (attName.equalsIgnoreCase("first") || attName.equalsIgnoreCase("/first")) { index = 0; } else if (attName.equalsIgnoreCase("last") || attName.equalsIgnoreCase("/last")) { index = data.numAttributes() - 1; } else { Attribute a = data.attribute(attName); if (a != null) { index = a.index(); } else { // try parsing as a number try { index = Integer.parseInt(attName); index--; } catch (NumberFormatException ex) { } } } if (index == -1) { throw new WekaException("Unable to find attribute '" + attName + "' in the data " + "or to parse it as an index"); } return index; }
protected static String generateMlProperties(Instances predictions, List<String> labels, MultilabelResult r) throws ClassNotFoundException, IOException { StringBuilder sb = new StringBuilder(); int attOffset = predictions.attribute(ID_FEATURE_NAME).index(); Map<String, Integer> class2number = classNamesToMapping(labels); int[][] goldmatrix = r.getGoldstandard(); double[][] predictionsmatrix = r.getPredictions(); double bipartition = r.getBipartitionThreshold(); for (int i = 0; i < goldmatrix.length; i++) { Double[] predList = new Double[labels.size()]; Integer[] goldList = new Integer[labels.size()]; for (int j = 0; j < goldmatrix[i].length; j++) { int classNo = class2number.get(labels.get(j)); goldList[classNo] = goldmatrix[i][j]; predList[classNo] = predictionsmatrix[i][j]; } String s = (StringUtils.join(predList, ",") + SEPARATOR_CHAR + StringUtils.join(goldList, ",") + SEPARATOR_CHAR + bipartition); String stringValue = predictions.get(i).stringValue(attOffset); sb.append(stringValue + "=" + s+"\n"); } return sb.toString(); }
protected static String generateMlProperties(Instances predictions, List<String> labels, MultilabelResult r) throws ClassNotFoundException, IOException { StringBuilder sb = new StringBuilder(); int attOffset = predictions.attribute(ID_FEATURE_NAME).index(); Map<String, Integer> class2number = classNamesToMapping(labels); int[][] goldmatrix = r.getGoldstandard(); double[][] predictionsmatrix = r.getPredictions(); double bipartition = r.getBipartitionThreshold(); for (int i = 0; i < goldmatrix.length; i++) { Double[] predList = new Double[labels.size()]; Integer[] goldList = new Integer[labels.size()]; for (int j = 0; j < goldmatrix[i].length; j++) { int classNo = class2number.get(labels.get(j)); goldList[classNo] = goldmatrix[i][j]; predList[classNo] = predictionsmatrix[i][j]; } String s = StringUtils.join(predList, ",") + SEPARATOR_CHAR + StringUtils.join(goldList, ",") + SEPARATOR_CHAR + bipartition; String stringValue = predictions.get(i).stringValue(attOffset); sb.append(stringValue + "=" + s+"\n"); } return sb.toString(); }
/** * Sets the weight of an attribute. This change only affects this dataset. * * @param att the attribute's index (index starts with 0) * @param weight the new weight */ public void setAttributeWeight(int att, double weight) { Attribute existingAtt = attribute(att); if (existingAtt.weight() == weight) { return; } Attribute newAtt = (Attribute)existingAtt.copy(); newAtt.setWeight(weight); ArrayList<Attribute> newVec = new ArrayList<Attribute>(numAttributes()); HashMap<String, Integer> newMap = new HashMap<String, Integer>((int)(numAttributes() / 0.75)); for (Attribute attr : m_Attributes) { if (attr.index() == att) { newVec.add(newAtt); newMap.put(newAtt.name(), att); } else { newVec.add(attr); newMap.put(attr.name(), attr.index()); } } m_Attributes = newVec; m_NamesToAttributeIndices = newMap; }
/** * Creates a panel displaying the data. * * @param data the plot data * @return the panel * @throws Exception if plot generation fails */ protected VisualizePanel createPanel(Instances data) throws Exception { VisualizePanel result = new ThresholdVisualizePanel(); PlotData2D plot = new PlotData2D(data); plot.setPlotName("Macro-averaged Performance"); plot.m_displayAllPoints = true; boolean[] connectPoints = new boolean [data.numInstances()]; for (int cp = 1; cp < connectPoints.length; cp++) connectPoints[cp] = true; plot.setConnectPoints(connectPoints); result.addPlot(plot); if (data.attribute(SAMPLES) != null) result.setXIndex(data.attribute(SAMPLES).index()); if (data.attribute(ACCURACY) != null) result.setYIndex(data.attribute(ACCURACY).index()); return result; }
/** * Creates a panel displaying the data. * * @param data the plot data * @return the panel * @throws Exception if plot generation fails */ protected VisualizePanel createPanel(Instances data) throws Exception { VisualizePanel result = new ThresholdVisualizePanel(); PlotData2D plot = new PlotData2D(data); plot.setPlotName("Micro-averaged Performance"); plot.m_displayAllPoints = true; boolean[] connectPoints = new boolean [data.numInstances()]; for (int cp = 1; cp < connectPoints.length; cp++) connectPoints[cp] = true; plot.setConnectPoints(connectPoints); result.addPlot(plot); if (data.attribute(SAMPLES) != null) result.setXIndex(data.attribute(SAMPLES).index()); if (data.attribute(ACCURACY) != null) result.setYIndex(data.attribute(ACCURACY).index()); return result; }