Q:

Naive Bayesian Classification score in percentage

I need a solution for text classification into multiple categories. This approach seems to work well: http://www.codeproject.com/Articles/14270/A-Naive-Bayesian-Classifier-in-C
There is only one issue I have with the returned scores. At the moment the highest score means the best fit into the category.
But I would like to get the percentage values of each category.
This is the part of the score calculation:    
/// <summary>
/// Classifies a text<\summary>
/// <returns>
/// returns classification values for the text, the higher, the better is the match.</returns>
public Dictionary<string, double> Classify(System.IO.StreamReader tr)
{
    Dictionary<string, double> score = new Dictionary<string, double>();
    foreach (KeyValuePair<string, ICategory> cat in m_Categories)
    {
        score.Add(cat.Value.Name, 0.0);
    }

    EnumerableCategory words_in_file = new EnumerableCategory("", m_ExcludedWords);
    words_in_file.TeachCategory(tr);

    foreach (KeyValuePair<string, PhraseCount> kvp1 in words_in_file)
    {
        PhraseCount pc_in_file = kvp1.Value;
        foreach (KeyValuePair<string, ICategory> kvp in m_Categories)
        {
            ICategory cat = kvp.Value;
            int count = cat.GetPhraseCount(pc_in_file.RawPhrase);
            if (0 < count)
            {
                score[cat.Name] += System.Math.Log((double)count / (double)cat.TotalWords);
            }
            else
            {
                score[cat.Name] += System.Math.Log(0.01 / (double)cat.TotalWords);
            }
            System.Diagnostics.Trace.WriteLine(pc_in_file.RawPhrase.ToString() + "(" +
                cat.Name + ")" + score[cat.Name]);
        }

    }
    foreach (KeyValuePair<string, ICategory> kvp in m_Categories)
    {
        ICategory cat = kvp.Value;
        score[cat.Name] += System.Math.Log((double)cat.TotalWords / (double)this.CountTotalWordsInCategories());
    }
    return score;
}

Thanks for any help!

A:

If I understand you correctly, you need to sum all Values in the Dictionary, it will give you 100%. Then divide each Value on the received sum.
Insert this code before return score;:
double sum = score.Values.Sum();
foreach (var name in score.Keys)
{
    score[name] /= sum;
}

