Waikato / meka

Multi-label classifiers and evaluation procedures using the Weka machine learning framework.
http://waikato.github.io/meka/
GNU General Public License v3.0
200 stars 76 forks source link

distributionForInstance #56

Closed Mali-DS closed 5 years ago

Mali-DS commented 5 years ago

Hi, I am trying to call Evaluation from the last version of Meka like this:

Result result = Evaluation.evaluateModel(classifier, testInstances, top, vop);

Finally I found this calling ends to "distributionForInstance" method in CR.class but I don't understand why this method create the array of Double with length of 2 times of class index
and put the prediction values at the end of array?

public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); double[] y = new double[L * 2];

    for(int j = 0; j < L; ++j) {
        Instance x_j = (Instance)x.copy();
        x_j.setDataset((Instances)null);
        x_j = MLUtils.keepAttributesAt(x_j, new int[]{j}, L);
        x_j.setDataset(this.m_Templates[j]);
        double[] w = this.m_MultiClassifiers[j].distributionForInstance(x_j);
        y[j] = (double)Utils.maxIndex(w);
        y[L + j] = w[(int)y[j]];
    }
    return y;
}

in my case I have 7 class indexes, this method creates y[14] and put the 7 prediction values at end of y, then the first 7 value in the y is zero and the result of evaluation showed zero....

image

jmread commented 5 years ago

Hi,

You can ignore the extra numbers if you want. It is simply the information regarding the argmax, for example. y[7] = P(Y_0 = y[0]) (where y[0] = 0 in your case; Y_0 is the 0-th label).

Mali-DS commented 5 years ago

Hi, I know I can ignore the first 7 numbers but Actually the result of prediction is not important for me, the result of evaluation is important, which is based on this array, and because the first 7 are zero the result of evaluation zero....

joergwicker commented 5 years ago

The problem was in the Evaluation, it should not use the first few array entries, but the last ones. The last commit should fix that.