我想要确定一个数据点属于一组数据的概率。我读到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]这个数字似乎并不是不合理,但我真的超出了我的舒适区,所以我想我应该问一下。谢谢!
发布于 2014-12-16 04:10:51
您正在使用的candidate_probability在统计上可能不正确。我认为你需要做的是计算样本点只是一个独立高斯分布的成员的概率(根据权重和多变量累积分布函数(CDF)),并对这些概率进行求和。最大的问题是我找不到一个好的python包来计算多变量CDF。除非你能找到,否则这篇论文将是一个很好的起点https://upload.wikimedia.org/wikipedia/commons/a/a2/Cumulative_function_n_dimensional_Gaussians_12.2013.pdf
https://stackoverflow.com/questions/27476980
复制相似问题