【发布时间】: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