使用sklearn GMM计算概率
发布时间:2020-12-20 13:46:25 所属栏目:Python 来源:网络整理
导读:我想确定数据点属于一组数据的概率.我读到sklearn GMM可以做到这一点.我试过以下…… import numpy as npfrom sklearn.mixture import GMMtraining_data = np.hstack(( np.random.normal(500,100,2000).reshape(-1,1),np.random.normal(500,))# train the cl
我想确定数据点属于一组数据的概率.我读到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,)) # 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] 这个数字似乎并不合理,但我真的离开了我的舒适区,所以我想我会问.谢谢! 解决方法
您使用的candidate_probability在统计上不正确.
我认为你需要做的是计算样本点只是其中一个单独高斯的成员的概率(来自权重和多变量累积分布函数(CDF))并总结这些概率.最大的问题是我找不到可以计算多变量CDF的好的python包.除非你能找到一个,否则本文将是一个很好的起点 https://upload.wikimedia.org/wikipedia/commons/a/a2/Cumulative_function_n_dimensional_Gaussians_12.2013.pdf (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |