public class ClassifierErrorsPlotInstances extends AbstractPlotInstances
Instances train = ... // from somewhere
Instances test = ... // from somewhere
Classifier cls = ... // from somewhere
// build classifier
cls.buildClassifier(train);
// evaluate classifier and generate plot instances
ClassifierPlotInstances plotInstances = new ClassifierPlotInstances();
plotInstances.setClassifier(cls);
plotInstances.setInstances(train);
plotInstances.setClassIndex(train.classIndex());
plotInstances.setUp();
Evaluation eval = new Evaluation(train);
for (int i = 0; i < test.numInstances(); i++)
plotInstances.process(test.instance(i), cls, eval);
// generate visualization
VisualizePanel visPanel = new VisualizePanel();
visPanel.addPlot(plotInstances.getPlotData("plot name"));
visPanel.setColourIndex(plotInstances.getPlotInstances().classIndex()+1);
// clean up
plotInstances.cleanUp();
| Modifier and Type | Field and Description |
|---|---|
protected Classifier |
m_Classifier
the classifier being used.
|
protected int |
m_ClassIndex
the class index.
|
protected Evaluation |
m_Evaluation
the Evaluation object to use.
|
protected int |
m_MaximumPlotSizeNumeric
the maximum plot size for numeric errors.
|
protected int |
m_MinimumPlotSizeNumeric
the minimum plot size for numeric errors.
|
protected java.util.ArrayList<java.lang.Integer> |
m_PlotShapes
for storing the plot shapes.
|
protected java.util.ArrayList<java.lang.Object> |
m_PlotSizes
for storing the plot sizes.
|
protected boolean |
m_pointSizeProportionalToMargin |
protected boolean |
m_SaveForVisualization
whether to save the instances for visualization or just evaluate the
instance.
|
m_FinishUpCalled, m_Instances, m_PlotInstances| Constructor and Description |
|---|
ClassifierErrorsPlotInstances() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addPredictionIntervals()
Adds the prediction intervals as additional attributes at the end.
|
protected void |
check()
Checks whether classifier, class index and evaluation are provided.
|
void |
cleanUp()
For freeing up memory.
|
protected PlotData2D |
createPlotData(java.lang.String name)
Assembles and returns the plot.
|
protected void |
determineFormat()
Sets up the structure for the plot instances.
|
protected void |
finishUp()
Performs optional post-processing.
|
Classifier |
getClassifier()
Returns the currently set classifier.
|
int |
getClassIndex()
Returns the 0-based class index.
|
Evaluation |
getEvaluation()
Returns the Evaluation object in use.
|
java.util.ArrayList<java.lang.Integer> |
getPlotShapes()
Get the vector of plot shapes (see weka.gui.visualize.Plot2D).
|
java.util.ArrayList<java.lang.Object> |
getPlotSizes()
Get the vector of plot sizes (see weka.gui.visualize.Plot2D).
|
boolean |
getPointSizeProportionalToMargin()
Get whether the point size should be proportional to the prediction margin
(classification only).
|
boolean |
getSaveForVisualization()
Returns whether the instances are saved for visualization for only
evaluation of the prediction is to happen.
|
protected void |
initialize()
Initializes the members.
|
void |
process(Instance toPredict,
Classifier classifier,
Evaluation eval)
Process a classifier's prediction for an instance and update a set of
plotting instances and additional plotting info. m_PlotShape for nominal
class datasets holds shape types (actual data points have automatic shape
type assignment; classifier error data points have box shape type).
|
void |
process(Instances batch,
double[][] predictions,
Evaluation eval) |
protected void |
scaleNumericPredictions()
Scales numeric class predictions into shape sizes for plotting in the
visualize panel.
|
void |
setClassifier(Classifier value)
Sets the classifier used for making the predictions.
|
void |
setClassIndex(int index)
Sets the 0-based class index.
|
void |
setEvaluation(Evaluation value)
Sets the Evaluation object to use.
|
void |
setPlotShapes(java.util.ArrayList<java.lang.Integer> plotShapes)
Set the vector of plot shapes to use;
|
void |
setPlotSizes(java.util.ArrayList<java.lang.Object> plotSizes)
Set the vector of plot sizes to use
|
void |
setPointSizeProportionalToMargin(boolean b)
Set whether the point size should be proportional to the prediction margin
(classification only).
|
void |
setSaveForVisualization(boolean value)
Sets whether the instances are saved for visualization or only evaluation
of the prediction is to happen.
|
canPlot, getInstances, getOptions, getPlotData, getPlotInstances, listOptions, setInstances, setOptions, setUpprotected int m_MinimumPlotSizeNumeric
protected int m_MaximumPlotSizeNumeric
protected boolean m_SaveForVisualization
protected boolean m_pointSizeProportionalToMargin
protected java.util.ArrayList<java.lang.Integer> m_PlotShapes
protected java.util.ArrayList<java.lang.Object> m_PlotSizes
protected Classifier m_Classifier
protected int m_ClassIndex
protected Evaluation m_Evaluation
protected void initialize()
initialize in class AbstractPlotInstancespublic java.util.ArrayList<java.lang.Integer> getPlotShapes()
public java.util.ArrayList<java.lang.Object> getPlotSizes()
public void setPlotShapes(java.util.ArrayList<java.lang.Integer> plotShapes)
plotShapes - public void setPlotSizes(java.util.ArrayList<java.lang.Object> plotSizes)
plotSizes - the plot sizes to usepublic void setClassifier(Classifier value)
value - the classifier to usepublic Classifier getClassifier()
public void setClassIndex(int index)
index - the class indexpublic int getClassIndex()
public void setEvaluation(Evaluation value)
value - the evaluation to usepublic Evaluation getEvaluation()
public void setSaveForVisualization(boolean value)
value - if true then the instances will be savedpublic boolean getSaveForVisualization()
public void setPointSizeProportionalToMargin(boolean b)
b - true if the point size should be proportional to the marginpublic boolean getPointSizeProportionalToMargin()
protected void check()
check in class AbstractPlotInstancesprotected void determineFormat()
determineFormat in class AbstractPlotInstancesgetSaveForVisualization()public void process(Instances batch, double[][] predictions, Evaluation eval)
public void process(Instance toPredict, Classifier classifier, Evaluation eval)
toPredict - the actual data pointclassifier - the classifiereval - the evaluation object to use for evaluating the classifier on
the instance to predictm_PlotShapes,
m_PlotSizes,
AbstractPlotInstances.m_PlotInstancesprotected void scaleNumericPredictions()
protected void addPredictionIntervals()
protected void finishUp()
finishUp in class AbstractPlotInstancesscaleNumericPredictions(),
addPredictionIntervals()protected PlotData2D createPlotData(java.lang.String name) throws java.lang.Exception
createPlotData in class AbstractPlotInstancesname - the name of the plotjava.lang.Exception - if plot generation failspublic void cleanUp()
cleanUp in class AbstractPlotInstances