Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I trained a model with

java -Xmx6g -cp /usr/share/java/weka.jar weka.classifiers.bayes.NaiveBayes -t train.arff -d foo.nb

and I want to score a test file with it.

I tried

java -Xmx6g -cp /usr/share/java/weka.jar weka.classifiers.bayes.NaiveBayes -T test.arff -l foo.nb -p N

which produces no files but writes some text pasts of which can be construed to be scores to stdout (and is unbelievable slow):

 inst#     actual  predicted error prediction ()
     1        1:0        1:0       0.549 
     2        1:0        1:0       0.55 
     3        1:0        1:0       0.531 
     4        1:0        1:0       0.515 
     5        2:1        1:0   +   0.552 
     6        1:0        1:0       0.532 
     7        1:0        2:1   +   0.519 

If I read this correctly, the last column is the score and 3rd is the prediction based on it. Why does score 0.55 correspond to 0 (instance#2) but a smaller score 0.519 correspond to 1 (instance#7)?

Where is the output documented?

Is there a way to produce the csv score file?

Thanks!

share|improve this question
As far as I remember, the output of Naive Bayes is sum-normalized to fake probabilities. Given this and this piece of documentation, the prediction column represent the sum-normalized estimated probability that e.g. instance 1 belongs to class 1 (with label 0) or instance 7 belongs to class 2 (with label 1). Can you please post the output if you use -distribution (see again linked documentation) ? – steffen Sep 21 '12 at 13:45

1 Answer

First I recommend reading about Naive Bayes.

Why does score 0.55 correspond to 0 (instance#2) but a smaller score 0.519 correspond to 1 (instance#7)?

NaiveBayes decides according to values of two probability predictions not according to if they are near to one. For example class A probability is 0.1 and class B probability 0.12 then class B is the prediction. Here score means posterior probability of class given prior probabilities of features. In the above stack overflow example: Posterior probabilities (scores) was 1/20 and 1/60. Higher one is chosen.

Where is the output documented?

You may look to class source file. But not everything in weka is well documented. This output is fairly simple therefore I do not think you will find a documentation.

Is there a way to produce the csv score file?

Use following to get csv prediction output.

java_command=java -Xmx6g -cp /usr/share/java/weka.jar 
$java_command weka.classifiers.Evaluation weka.classifiers.bayes.NaiveBayes -l irisNaiveBayes.model -T test.arff -classifications weka.classifiers.evaluation.output.prediction.CSV

We use Evaluation class instead of using Naive Bayes directly. First argument to Evaluation class is classifier to use, here NaiveBayes. -classification switch allows to output CSV.

Another example with well known iris data set.

java_command=java -Xmx6g -cp /usr/share/java/weka.jar 
$java_command weka.classifiers.bayes.NaiveBayes -t iris.arff  -d irisNaiveBayes.model

$java_command weka.classifiers.Evaluation weka.classifiers.bayes.NaiveBayes -l irisNaiveBayes.model -T iris.arff -classifications weka.classifiers.evaluation.output.prediction.CSV

This command gives following output.

=== Predictions on test data ===

inst#,actual,predicted,error,prediction
1,1:Iris-setosa,1:Iris-setosa,,1
2,1:Iris-setosa,1:Iris-setosa,,1
3,1:Iris-setosa,1:Iris-setosa,,1
4,1:Iris-setosa,1:Iris-setosa,,1
5,1:Iris-setosa,1:Iris-setosa,,1
6,1:Iris-setosa,1:Iris-setosa,,1
7,1:Iris-setosa,1:Iris-setosa,,1
share|improve this answer
so, what does the score mean? – sds Sep 19 '12 at 17:03
Weka exception: Illegal options: -classifications myout.csv – sds Sep 19 '12 at 17:10
Which weka version are you using? 3.6 or 3.7 – Atilla Ozgur Sep 19 '12 at 18:52
@sds I updated my answer for score explanation. – Atilla Ozgur Sep 19 '12 at 19:06
ubuntu weka 3.6.6-1 – sds Sep 20 '12 at 4:48
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.