Get risk forecasts in WEKA using native Java code

I already checked in the WEKA documentation and contained explicit instructions for command line and GUI predictions.

I want to know how to get a prediction value like the one below that I got from the GUI using the dataset Agrawal( weka.datagenerators.classifiers.classification.Agrawal) in my own Java code:

inst#,  actual,     predicted,  error,  prediction
1,      1:0,        2:1,        +,      0.941
2,      1:0,        1:0,        ,       1
3,      1:0,        1:0,        ,       1
4,      1:0,        1:0,        ,       1
5,      1:0,        1:0,        ,       1
6,      1:0,        1:0,        ,       1
7,      1:0,        2:1,        +,      0.941
8,      2:1,        2:1,        ,       0.941
9,      2:1,        2:1,        ,       0.941
10,     2:1,        2:1,        ,       0.941
1,      1:0,        1:0,        ,       1
2,      1:0,        1:0,        ,       1
3,      1:0,        1:0,        ,       1

I cannot reproduce this result, although he said that:

Java

If you want to perform the classification in your own code, see the section on classifying instances in this article , explaining the Weka API in general.

I went to the link and said:

Instance classification

, , . /some/where/unlabeled.arff, /some/where/labeled.arff.

, , -- , .


Update

predictions

public FastVector predictions()

.

:

FastVector, , . , .

predictions() Evaluation :

Object[] preds = evaluation.predictions().toArray();
for(Object pred : preds) {
    System.out.println(pred);
}

:

...
NOM: 0.0 0.0 1.0 0.9466666666666667 0.05333333333333334
NOM: 0.0 0.0 1.0 0.8947368421052632 0.10526315789473684
NOM: 0.0 0.0 1.0 0.9934883720930232 0.0065116279069767444
NOM: 0.0 0.0 1.0 0.9466666666666667 0.05333333333333334
NOM: 0.0 0.0 1.0 0.9912575655682583 0.008742434431741762
NOM: 0.0 0.0 1.0 0.9934883720930232 0.0065116279069767444
...

, ?

+1
1

Google ( , ), .

, .

  • " WEKA" , , , .

    ,

    StringBuffer predictionSB = new StringBuffer();
    Range attributesToShow = null;
    Boolean outputDistributions = new Boolean(true);
    
    PlainText predictionOutput = new PlainText();
    predictionOutput.setBuffer(predictionSB);
    predictionOutput.setOutputDistribution(true);
    
    Evaluation evaluation = new Evaluation(data);
    evaluation.crossValidateModel(j48Model, data, numberOfFolds,
            randomNumber, predictionOutput, attributesToShow,
            outputDistributions);
    

    , StringBuffer, AbstractOutput, crossValidateModel .

    StringBuffer , java.lang.ClassCastException , PlainText StringBuffer java.lang.IllegalStateException.

    ManChon U (Kevin) " - ?" , , :

    ... , weka.classifiers.evaluation.output.prediction.AbstractOutput. weka.classifiers.evaluation.output.prediction.PlainText, , , .

    ... PlainText, AbstractOutput (, , output) output.setBuffer(forPredictionsPrinting), .

    PlainText, StringBuffer setOutput(boolean) .

    , , :

    System.out.println(predictionOutput.getBuffer());
    

    predictionOutput - AbstractOutput (PlainText, CSV, XML ..).).

  • , evaluation.predictions() , WEKA. , " "

    evaluation.predictions() a FastVector, NominalPrediction NumericPrediction weka.classifiers.evaluation. Evaluation.crossValidateModel() AbstractOutput , / Nominal/NumericPrediction StringBuffer , .

:

+5

All Articles