List of usage examples for weka.gui.visualize PlotData2D setPlotName
public void setPlotName(String name)
From source file:TextClassifierUI.java
private void setVMC(FastVector predictions, ThresholdVisualizePanel vmc, boolean masterPlot) { try {/*from ww w . ja va 2 s . c o m*/ ThresholdCurve tc = new ThresholdCurve(); Instances result = tc.getCurve(predictions); // method visualize PlotData2D tempd = new PlotData2D(result); tempd.setPlotName(result.relationName()); tempd.addInstanceNumberAttribute(); // specify which points are connected boolean[] cp = new boolean[result.numInstances()]; for (int n = 1; n < cp.length; n++) { cp[n] = true; } tempd.setConnectPoints(cp); // add plot if (masterPlot) { vmc.setMasterPlot(tempd); } else { vmc.addPlot(tempd); } } catch (Exception ex) { System.err.println("Failed to set VMC"); ex.printStackTrace(); } }
From source file:adams.flow.sink.WekaClassifierErrors.java
License:Open Source License
/** * ClassifierErrorss the token (the panel and dialog have already been created at * this stage).//from www . j a v a 2 s . c o m * * @param token the token to display */ @Override protected void display(Token token) { DataGenerator generator; Evaluation eval; try { if (token.getPayload() instanceof WekaEvaluationContainer) eval = (Evaluation) ((WekaEvaluationContainer) token.getPayload()) .getValue(WekaEvaluationContainer.VALUE_EVALUATION); else eval = (Evaluation) token.getPayload(); if (eval.predictions() == null) { getLogger().severe("No predictions available from Evaluation object!"); return; } generator = new DataGenerator(eval, m_ErrorScaler); PlotData2D plotdata = generator.getPlotData(); plotdata.setPlotName(generator.getPlotInstances().relationName()); m_VisualizePanel.addPlot(plotdata); m_VisualizePanel.setColourIndex(plotdata.getPlotInstances().classIndex()); if ((m_VisualizePanel.getXIndex() == 0) && (m_VisualizePanel.getYIndex() == 1)) { try { m_VisualizePanel.setXIndex(m_VisualizePanel.getInstances().classIndex()); // class m_VisualizePanel.setYIndex(m_VisualizePanel.getInstances().classIndex() - 1); // predicted class } catch (Exception e) { // ignored } } } catch (Exception e) { handleException("Failed to display token: " + token, e); } }
From source file:adams.flow.sink.WekaClassifierErrors.java
License:Open Source License
/** * Creates a new panel for the token.// w w w .jav a2 s.c o m * * @param token the token to display in a new panel, can be null * @return the generated panel */ public AbstractDisplayPanel createDisplayPanel(Token token) { AbstractDisplayPanel result; String name; if (token != null) name = "Classifier errors (" + getEvaluation(token).getHeader().relationName() + ")"; else name = "Classifier errors"; result = new AbstractComponentDisplayPanel(name) { private static final long serialVersionUID = -7362768698548152899L; protected VisualizePanel m_VisualizePanel; @Override protected void initGUI() { super.initGUI(); setLayout(new BorderLayout()); m_VisualizePanel = new VisualizePanel(); add(m_VisualizePanel, BorderLayout.CENTER); } @Override public void display(Token token) { try { Evaluation eval = getEvaluation(token); DataGenerator generator = new DataGenerator(eval, m_ErrorScaler); PlotData2D plotdata = generator.getPlotData(); plotdata.setPlotName(generator.getPlotInstances().relationName()); m_VisualizePanel.addPlot(plotdata); m_VisualizePanel.setColourIndex(plotdata.getPlotInstances().classIndex()); if ((m_VisualizePanel.getXIndex() == 0) && (m_VisualizePanel.getYIndex() == 1)) { try { m_VisualizePanel.setXIndex(m_VisualizePanel.getInstances().classIndex()); // class m_VisualizePanel.setYIndex(m_VisualizePanel.getInstances().classIndex() - 1); // predicted class } catch (Exception e) { // ignored } } } catch (Exception e) { getLogger().log(Level.SEVERE, "Failed to display token: " + token, e); } } @Override public JComponent supplyComponent() { return m_VisualizePanel; } @Override public void clearPanel() { m_VisualizePanel.removeAllPlots(); } public void cleanUp() { m_VisualizePanel.removeAllPlots(); } }; if (token != null) result.display(token); return result; }
From source file:adams.flow.sink.WekaCostBenefitAnalysis.java
License:Open Source License
/** * Plots the token (the panel and dialog have already been created at * this stage)./*w w w . j a v a 2 s . c om*/ * * @param token the token to display */ @Override protected void display(Token token) { Evaluation eval; Attribute classAtt; Attribute classAttToUse; int classValue; ThresholdCurve tc; Instances result; ArrayList<String> newNames; CostBenefitAnalysis cbAnalysis; PlotData2D tempd; boolean[] cp; int n; try { if (token.getPayload() instanceof WekaEvaluationContainer) eval = (Evaluation) ((WekaEvaluationContainer) token.getPayload()) .getValue(WekaEvaluationContainer.VALUE_EVALUATION); else eval = (Evaluation) token.getPayload(); if (eval.predictions() == null) { getLogger().severe("No predictions available from Evaluation object!"); return; } classAtt = eval.getHeader().classAttribute(); m_ClassIndex.setData(classAtt); classValue = m_ClassIndex.getIntIndex(); tc = new ThresholdCurve(); result = tc.getCurve(eval.predictions(), classValue); // Create a dummy class attribute with the chosen // class value as index 0 (if necessary). classAttToUse = eval.getHeader().classAttribute(); if (classValue != 0) { newNames = new ArrayList<>(); newNames.add(classAtt.value(classValue)); for (int k = 0; k < classAtt.numValues(); k++) { if (k != classValue) newNames.add(classAtt.value(k)); } classAttToUse = new Attribute(classAtt.name(), newNames); } // assemble plot data tempd = new PlotData2D(result); tempd.setPlotName(result.relationName()); tempd.m_alwaysDisplayPointsOfThisSize = 10; // specify which points are connected cp = new boolean[result.numInstances()]; for (n = 1; n < cp.length; n++) cp[n] = true; tempd.setConnectPoints(cp); // add plot m_CostBenefitPanel.setCurveData(tempd, classAttToUse); } catch (Exception e) { handleException("Failed to display token: " + token, e); } }
From source file:adams.flow.sink.WekaCostBenefitAnalysis.java
License:Open Source License
/** * Creates a new panel for the token.//www . ja v a 2 s . com * * @param token the token to display in a new panel, can be null * @return the generated panel */ public AbstractDisplayPanel createDisplayPanel(Token token) { AbstractDisplayPanel result; String name; if (token != null) name = "Cost curve (" + getEvaluation(token).getHeader().relationName() + ")"; else name = "Cost curve"; result = new AbstractComponentDisplayPanel(name) { private static final long serialVersionUID = -3513994354297811163L; protected CostBenefitAnalysis m_VisualizePanel; @Override protected void initGUI() { super.initGUI(); setLayout(new BorderLayout()); m_VisualizePanel = new CostBenefitAnalysis(); add(m_VisualizePanel, BorderLayout.CENTER); } @Override public void display(Token token) { try { Evaluation eval = getEvaluation(token); Attribute classAtt = eval.getHeader().classAttribute(); m_ClassIndex.setData(classAtt); int classValue = m_ClassIndex.getIntIndex(); ThresholdCurve tc = new ThresholdCurve(); Instances result = tc.getCurve(eval.predictions(), classValue); // Create a dummy class attribute with the chosen // class value as index 0 (if necessary). Attribute classAttToUse = eval.getHeader().classAttribute(); if (classValue != 0) { ArrayList<String> newNames = new ArrayList<>(); newNames.add(classAtt.value(classValue)); for (int k = 0; k < classAtt.numValues(); k++) { if (k != classValue) newNames.add(classAtt.value(k)); } classAttToUse = new Attribute(classAtt.name(), newNames); } // assemble plot data PlotData2D tempd = new PlotData2D(result); tempd.setPlotName(result.relationName()); tempd.m_alwaysDisplayPointsOfThisSize = 10; // specify which points are connected boolean[] cp = new boolean[result.numInstances()]; for (int n = 1; n < cp.length; n++) cp[n] = true; tempd.setConnectPoints(cp); // add plot m_VisualizePanel.setCurveData(tempd, classAttToUse); } catch (Exception e) { getLogger().log(Level.SEVERE, "Failed to display token: " + token, e); } } @Override public JComponent supplyComponent() { return m_VisualizePanel; } @Override public void clearPanel() { } public void cleanUp() { } }; if (token != null) result.display(token); return result; }
From source file:adams.flow.sink.WekaCostCurve.java
License:Open Source License
/** * Plots the token (the panel and dialog have already been created at * this stage).//from w w w. ja v a 2 s .c om * * @param token the token to display */ @Override protected void display(Token token) { weka.classifiers.evaluation.CostCurve curve; Evaluation eval; PlotData2D plot; boolean[] connectPoints; int cp; Instances data; int[] indices; try { if (token.getPayload() instanceof WekaEvaluationContainer) eval = (Evaluation) ((WekaEvaluationContainer) token.getPayload()) .getValue(WekaEvaluationContainer.VALUE_EVALUATION); else eval = (Evaluation) token.getPayload(); if (eval.predictions() == null) { getLogger().severe("No predictions available from Evaluation object!"); return; } m_ClassLabelRange.setData(eval.getHeader().classAttribute()); indices = m_ClassLabelRange.getIntIndices(); for (int index : indices) { curve = new weka.classifiers.evaluation.CostCurve(); data = curve.getCurve(eval.predictions(), index); plot = new PlotData2D(data); plot.setPlotName(eval.getHeader().classAttribute().value(index)); plot.m_displayAllPoints = true; connectPoints = new boolean[data.numInstances()]; for (cp = 1; cp < connectPoints.length; cp++) connectPoints[cp] = true; plot.setConnectPoints(connectPoints); m_VisualizePanel.addPlot(plot); } } catch (Exception e) { handleException("Failed to display token: " + token, e); } }
From source file:adams.flow.sink.WekaCostCurve.java
License:Open Source License
/** * Creates a new panel for the token./* ww w .ja v a 2 s. co m*/ * * @param token the token to display in a new panel, can be null * @return the generated panel */ public AbstractDisplayPanel createDisplayPanel(Token token) { AbstractDisplayPanel result; String name; if (token != null) name = "Cost curve (" + getEvaluation(token).getHeader().relationName() + ")"; else name = "Cost curve"; result = new AbstractComponentDisplayPanel(name) { private static final long serialVersionUID = -3513994354297811163L; protected VisualizePanel m_VisualizePanel; @Override protected void initGUI() { super.initGUI(); setLayout(new BorderLayout()); m_VisualizePanel = new VisualizePanel(); add(m_VisualizePanel, BorderLayout.CENTER); } @Override public void display(Token token) { try { Evaluation eval = getEvaluation(token); m_ClassLabelRange.setMax(eval.getHeader().classAttribute().numValues()); int[] indices = m_ClassLabelRange.getIntIndices(); for (int index : indices) { weka.classifiers.evaluation.CostCurve curve = new weka.classifiers.evaluation.CostCurve(); Instances data = curve.getCurve(eval.predictions(), index); PlotData2D plot = new PlotData2D(data); plot.setPlotName(eval.getHeader().classAttribute().value(index)); plot.m_displayAllPoints = true; boolean[] connectPoints = new boolean[data.numInstances()]; for (int cp = 1; cp < connectPoints.length; cp++) connectPoints[cp] = true; plot.setConnectPoints(connectPoints); m_VisualizePanel.addPlot(plot); } } catch (Exception e) { getLogger().log(Level.SEVERE, "Failed to display token: " + token, e); } } @Override public JComponent supplyComponent() { return m_VisualizePanel; } @Override public void clearPanel() { m_VisualizePanel.removeAllPlots(); } public void cleanUp() { m_VisualizePanel.removeAllPlots(); } }; if (token != null) result.display(token); return result; }
From source file:adams.flow.sink.WekaInstancesPlot.java
License:Open Source License
/** * Plots the token (the panel and dialog have already been created at * this stage)./*from w ww .j a va 2 s .co m*/ * * @param token the token to display */ @Override protected void display(Token token) { PlotData2D plot; Instances data; try { data = (Instances) token.getPayload(); m_AttributeX.setData(data); m_AttributeY.setData(data); plot = new PlotData2D(data); if ((m_AttributeX.getIntIndex() != -1) && (m_AttributeY.getIntIndex() != -1)) plot.setPlotName(data.attribute(m_AttributeX.getIntIndex()).name() + " vs " + data.attribute(m_AttributeX.getIntIndex()).name()); plot.m_displayAllPoints = true; m_VisualizePanel.addPlot(plot); if (m_AttributeX.getIntIndex() != -1) m_VisualizePanel.setXIndex(m_AttributeX.getIntIndex()); if (m_AttributeY.getIntIndex() != -1) m_VisualizePanel.setYIndex(m_AttributeY.getIntIndex()); } catch (Exception e) { handleException("Failed to display token: " + token, e); } }
From source file:adams.flow.sink.WekaInstancesPlot.java
License:Open Source License
/** * Creates a new panel for the token.//from w ww. j ava 2s . c o m * * @param token the token to display in a new panel, can be null * @return the generated panel */ public AbstractDisplayPanel createDisplayPanel(Token token) { AbstractDisplayPanel result; String name; name = "Instances plot"; result = new AbstractComponentDisplayPanel(name) { private static final long serialVersionUID = -7362768698548152899L; protected VisualizePanel m_VisualizePanel; @Override protected void initGUI() { super.initGUI(); setLayout(new BorderLayout()); m_VisualizePanel = new VisualizePanel(); add(m_VisualizePanel, BorderLayout.CENTER); } @Override public void display(Token token) { PlotData2D plot; Instances data; try { data = (Instances) token.getPayload(); m_AttributeX.setData(data); m_AttributeY.setData(data); plot = new PlotData2D(data); if ((m_AttributeX.getIntIndex() != -1) && (m_AttributeY.getIntIndex() != -1)) plot.setPlotName(data.attribute(m_AttributeX.getIntIndex()).name() + " vs " + data.attribute(m_AttributeX.getIntIndex()).name()); plot.m_displayAllPoints = true; m_VisualizePanel.addPlot(plot); if (m_AttributeX.getIntIndex() != -1) m_VisualizePanel.setXIndex(m_AttributeX.getIntIndex()); if (m_AttributeY.getIntIndex() != -1) m_VisualizePanel.setYIndex(m_AttributeY.getIntIndex()); } catch (Exception e) { handleException("Failed to display token: " + token, e); } } @Override public JComponent supplyComponent() { return m_VisualizePanel; } @Override public void clearPanel() { m_VisualizePanel.removeAllPlots(); } public void cleanUp() { m_VisualizePanel.removeAllPlots(); } }; if (token != null) result.display(token); return result; }
From source file:adams.flow.sink.WekaThresholdCurve.java
License:Open Source License
/** * Plots the token (the panel and dialog have already been created at * this stage)./*from w w w. j ava 2 s . c o m*/ * * @param token the token to display */ @Override protected void display(Token token) { ThresholdCurve curve; Evaluation eval; PlotData2D plot; boolean[] connectPoints; int cp; Instances data; int[] indices; try { if (token.getPayload() instanceof WekaEvaluationContainer) eval = (Evaluation) ((WekaEvaluationContainer) token.getPayload()) .getValue(WekaEvaluationContainer.VALUE_EVALUATION); else eval = (Evaluation) token.getPayload(); if (eval.predictions() == null) { getLogger().severe("No predictions available from Evaluation object!"); return; } m_ClassLabelRange.setData(eval.getHeader().classAttribute()); indices = m_ClassLabelRange.getIntIndices(); for (int index : indices) { curve = new ThresholdCurve(); data = curve.getCurve(eval.predictions(), index); plot = new PlotData2D(data); plot.setPlotName(eval.getHeader().classAttribute().value(index)); plot.m_displayAllPoints = true; connectPoints = new boolean[data.numInstances()]; for (cp = 1; cp < connectPoints.length; cp++) connectPoints[cp] = true; plot.setConnectPoints(connectPoints); m_VisualizePanel.addPlot(plot); if (data.attribute(m_AttributeX.toDisplay()) != null) m_VisualizePanel.setXIndex(data.attribute(m_AttributeX.toDisplay()).index()); if (data.attribute(m_AttributeY.toDisplay()) != null) m_VisualizePanel.setYIndex(data.attribute(m_AttributeY.toDisplay()).index()); } } catch (Exception e) { handleException("Failed to display token: " + token, e); } }