public virtual double Score <F>(IClassifier <L, F> classifier, GeneralDataset <L, F> data)
        {
            IList <L> guesses = new List <L>();
            IList <L> labels  = new List <L>();

            for (int i = 0; i < data.Size(); i++)
            {
                IDatum <L, F> d     = data.GetRVFDatum(i);
                L             guess = classifier.ClassOf(d);
                guesses.Add(guess);
            }
            int[] labelsArr = data.GetLabelsArray();
            labelIndex = data.labelIndex;
            for (int i_1 = 0; i_1 < data.Size(); i_1++)
            {
                labels.Add(labelIndex.Get(labelsArr[i_1]));
            }
            labelIndex = new HashIndex <L>();
            labelIndex.AddAll(data.LabelIndex().ObjectsList());
            labelIndex.AddAll(classifier.Labels());
            int numClasses = labelIndex.Size();

            tpCount  = new int[numClasses];
            fpCount  = new int[numClasses];
            fnCount  = new int[numClasses];
            negIndex = labelIndex.IndexOf(negLabel);
            for (int i_2 = 0; i_2 < guesses.Count; ++i_2)
            {
                L   guess      = guesses[i_2];
                int guessIndex = labelIndex.IndexOf(guess);
                L   label      = labels[i_2];
                int trueIndex  = labelIndex.IndexOf(label);
                if (guessIndex == trueIndex)
                {
                    if (guessIndex != negIndex)
                    {
                        tpCount[guessIndex]++;
                    }
                }
                else
                {
                    if (guessIndex != negIndex)
                    {
                        fpCount[guessIndex]++;
                    }
                    if (trueIndex != negIndex)
                    {
                        fnCount[trueIndex]++;
                    }
                }
            }
            return(GetFMeasure());
        }
Exemplo n.º 2
0
 public override double Score <F>(IClassifier <L, F> classifier, GeneralDataset <L, F> data)
 {
     labelIndex = new HashIndex <L>();
     labelIndex.AddAll(classifier.Labels());
     labelIndex.AddAll(data.labelIndex.ObjectsList());
     ClearCounts();
     int[] labelsArr = data.GetLabelsArray();
     for (int i = 0; i < data.Size(); i++)
     {
         IDatum <L, F> d     = data.GetRVFDatum(i);
         L             guess = classifier.ClassOf(d);
         AddGuess(guess, labelIndex.Get(labelsArr[i]));
     }
     FinalizeCounts();
     return(GetFMeasure());
 }
 public BiasedLogConditionalObjectiveFunction(GeneralDataset dataset, double[][] confusionMatrix, LogPrior prior)
     : this(dataset.NumFeatures(), dataset.NumClasses(), dataset.GetDataArray(), dataset.GetLabelsArray(), confusionMatrix, prior)
 {
 }