Search code examples
javaweka

Probability distribution of naieve bayes in weka


I want to run the naieve bayes classifier. I have trained this model in weka. Now for each testing instances I want to find the predicted class and the probability distribution so that with this value I can rank the instances as well. I am running the weka from java. How can i get the probability distribution in weka java?


Solution

  • double[] predictionDistribution = null;
        try {
            double clsLabel = classifier.classifyInstance(Test Instance Here);
            predictionDistribution = classifier.distributionForInstance(Test Instance Here);
        } catch (Exception e) {
            System.out.println("Unable to classify item\n");
        }
    

    Use a double[] array and then use your classifier's distributionForInstance() method.