bonjour;
je traite un problème de classification de symboles mathématiques
j'ai une base d'apprentissage avec laquelle j'ai entraîner un classifieur Bayes network de Weka. à partir du modèle de classification sauvegardé, je veux prédire la classe à laquelle appartient une instance de test avec un pourcentage d'appartenance à la classe. j'explique, supposant que j'ai 4 classes de symboles: plus, moins, fraction, multiplication, en introduisant un symbole unconnu, je veux avoir la probabilité d'appartenance de ce symbole à chaque classe. ce que j'ai actuellement. mon code me retourne uniquement une classe à laquelle appartient mon symbole avec une probabilité égale à 1 et 0 pour le reste des classes.
voici mon code java pour la classification
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import weka.classifiers.Classifier;
 
import weka.classifiers.bayes.BayesNet;
import weka.core.Instances;
import java.io.BufferedReader;
import java.io.FileReader;
 
public class myClassifierPrinted 
{
	public String[] test;
	public myClassifierPrinted()throws Exception
	{
		 // *** reading instances from a file
 
		Instances training_data = new Instances(new BufferedReader(
	            new FileReader("D:/MATLAB/Interface_ReFMA/dataRL.arff"))); //change it when you change the version
 
		training_data.setClassIndex(training_data.numAttributes() - 1);
 
		Instances testing_data = new Instances(new BufferedReader(
	            new FileReader("D:/MATLAB/Interface_ReFMA/dataRL_FS.arff")));
 
		testing_data.setClassIndex(testing_data.numAttributes() - 1);
 
		Classifier fc = (Classifier)new BayesNet();  
 
		fc.buildClassifier(training_data);
 
		test=new String[testing_data.numInstances()/50];
 
		for (int i = 0; i < testing_data.numInstances()/50; i++)  //50 le nombre de classe que j'ai 
	    {
	    	double pred = fc.classifyInstance(testing_data.instance(i));
	        //double[] proba= fc.distributionForInstance(testing_data.instance(i));
	        if(testing_data.classAttribute().value((int) pred)!=null)
	        {
	         	// Get the predicted class label from the predictionIndex.
	            test[i]= testing_data.classAttribute().value((int) pred);
	            // Get the prediction probability distribution.
	            double[] predictionDistribution = 
	                fc.distributionForInstance(testing_data.get(i)); 
	        	//System.out.println(". predicted value: "
	              //  + test[i]);
	        	// Print out the true label, predicted label, and the distribution.
	        	System.out.printf("%5d: predicted=%-10s, distribution=",
	                          i,test); 
	        	// Loop over all the prediction labels in the distribution.
	        	for (int predictionDistributionIndex = 0;predictionDistributionIndex < predictionDistribution.length;predictionDistributionIndex++)
	        	{
	        		// Get this distribution index's class label.
	        		String predictionDistributionIndexAsClassLabel = 
	            	testing_data.classAttribute().value(predictionDistributionIndex);
	        		// Get the probability.
	        		double predictionProbability = predictionDistribution[predictionDistributionIndex];
	        		System.out.printf("[%10s : %6.3f]", predictionDistributionIndexAsClassLabel, predictionProbability );
	        	}
 
	        	System.out.printf("\n");
	        }
	    }
	}
}