【问题标题】:Calculating probability with sklearn GMM用 sklearn GMM 计算概率
【发布时间】:2015-02-13 03:10:06
【问题描述】:

我想确定一个数据点属于一组数据的概率。我读到 sklearn GMM 可以做到这一点。我尝试了以下....

import numpy as np
from sklearn.mixture import GMM

training_data = np.hstack((
    np.random.normal(500, 100, 2000).reshape(-1, 1),
    np.random.normal(500, 100, 2000).reshape(-1, 1),
))

# train the classifier and get max score
g = GMM(n_components=1)
g.fit(training_data)
scores = g.score(training_data)
max_score = np.amax(scores)

# create a candidate data point and calculate the probability
# it belongs to the training population
candidate_data = np.array([[490, 450]])
candidate_score = g.score(candidate_data)

从现在开始,我不知道该怎么办了。我正在阅读我必须标准化对数概率才能获得候选数据点属于总体的概率。会是这样吗……

candidate_probability = (np.exp(candidate_score)/np.exp(max_score)) * 100

print candidate_probability
>>> [ 87.81751913]

这个数字似乎不无道理,但我真的不在我的舒适区,所以我想我会问。谢谢!

【问题讨论】:

  • 你能想出解决办法吗?

标签: python statistics scikit-learn gaussian


【解决方案1】:

您使用的候选概率在统计上不正确。 我认为您需要做的是计算样本点仅属于单个高斯函数之一的概率(来自权重和多元累积分布函数 (CDF)),然后将这些概率相加。最大的问题是我找不到一个可以计算多元 CDF 的好的 python 包。除非你能找到一篇,否则这篇论文将是一个很好的起点https://upload.wikimedia.org/wikipedia/commons/a/a2/Cumulative_function_n_dimensional_Gaussians_12.2013.pdf

【讨论】:

    猜你喜欢
    • 2012-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-23
    • 1970-01-01
    • 2011-09-30
    相关资源
    最近更新 更多