【问题标题】:What does the value 0.5 represent here?值 0.5 在这里代表什么?
【发布时间】:2017-03-10 22:12:02
【问题描述】:

朴素贝叶斯分类器算法的This is an implementation

我听不懂score.Add(results[i].Name, finalScore * 0.5);这行。

这个值0.5从何而来?

为什么是 0.5?为什么没有其他值?

public string Classify(double[] obj)
{
    Dictionary<string,> score = new Dictionary<string,>();

    var results = (from myRow in dataSet.Tables[0].AsEnumerable()
                   group myRow by myRow.Field<string>(
                         dataSet.Tables[0].Columns[0].ColumnName) into g
                   select new { Name = g.Key, Count = g.Count() }).ToList();

    for (int i = 0; i < results.Count; i++)
    {
        List<double> subScoreList = new List<double>();
        int a = 1, b = 1;
        for (int k = 1; k < dataSet.Tables["Gaussian"].Columns.Count; k = k + 2)
        {
            double mean = Convert.ToDouble(dataSet.Tables["Gaussian"].Rows[i][a]);
            double variance = Convert.ToDouble(dataSet.Tables["Gaussian"].Rows[i][++a]);
            double result = Helper.NormalDist(obj[b - 1], mean, Helper.SquareRoot(variance));
            subScoreList.Add(result);
            a++; b++;
        }

        double finalScore = 0;
        for (int z = 0; z < subScoreList.Count; z++)
        {
            if (finalScore == 0)
            {
                finalScore = subScoreList[z];
                continue;
            }

            finalScore = finalScore * subScoreList[z];
        }



        score.Add(results[i].Name, finalScore * 0.5);



    }

    double maxOne = score.Max(c => c.Value);
    var name = (from c in score
                where c.Value == maxOne
                select c.Key).First();

    return name;
}

【问题讨论】:

  • 这在页面上的 cmets 中有讨论:codeproject.com/Articles/318126/… 显然你除以二,因为有两个班级(男性和女性)。
  • @Thilo,不正确。共有三个类。
  • 我认为这就是评论所说的:代码不正确(关于 .5 和其他一些计算,也是)。我不能说谁是对的。也许你也发表评论?如果问题更多是关于数学而不是编程,那么 Stackoverflow 可能是错误的论坛。

标签: c#-4.0 bayesian naivebayes


【解决方案1】:

我想通了。

0.5 是先验概率。

【讨论】:

    猜你喜欢
    • 2018-05-19
    • 1970-01-01
    • 1970-01-01
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多