来自 sklearn 的高斯混合模型分类器的精度不稳定

Unstable accuracy of Gaussian Mixture Model classifier from sklearn

我有一些数据(用于说话人识别的 MFCC 特征),来自两个不同的说话人。每个人 13 个特征的 60 个向量(总共 120 个)。他们每个人都有自己的标签(0 和 1)。我需要在混淆矩阵上显示结果。但是来自 sklearn 的 GaussianMixture 模型不稳定。对于每个程序 运行 我得到不同的分数(有时准确度是 0.4,有时是 0.7 ...)。我不知道我做错了什么,因为类比地我创建了 SVM 和 k-NN 模型并且它们工作正常(精度稳定在 0.9 左右)。你知道我做错了什么吗?

gmmclf = GaussianMixture(n_components=2, covariance_type='diag')
gmmclf.fit(X_train, y_train) #X_train are mfcc vectors, y_train are labels

ygmm_pred_class = gmmclf.predict(X_test)
print(accuracy_score(y_test, ygmm_pred_class))
print(confusion_matrix(y_test, ygmm_pred_class))

简短回答:您应该而不是使用 GMM 进行分类。


长答案...

来自相关话题的回答,Multiclass classification using Gaussian Mixture Models with scikit learn(强调原文):

Gaussian Mixture is not a classifier. It is a density estimation method, and expecting that its components will magically align with your classes is not a good idea. [...] GMM simply tries to fit mixture of Gaussians into your data, but there is nothing forcing it to place them according to the labeling (which is not even provided in the fit call). From time to time this will work - but only for trivial problems, where classes are so well separated that even Naive Bayes would work, in general however it is simply invalid tool for the problem.

以及受访者本人的评论(再次强调原文):

As stated in the answer - GMM is not a classifier, so asking if you are using "GMM classifier" correctly is impossible to answer. Using GMM as a classifier is incorrect by definition, there is no "valid" way of using it in such a problem as it is not what this model is designed to do. What you could do is to build a proper generative model per class. In other words construct your own classifier where you fit one GMM per label and then use assigned probability to do actual classification. Then it is a proper classifier. See github.com/scikit-learn/scikit-learn/pull/2468

(对于它的价值,您可能需要注意 SO 处的 respondent is a research scientist in DeepMind, and the very first person to be awarded the machine-learning gold badge

进一步阐述(这就是为什么我没有简单地将问题标记为重复的原因):

scikit-learn 文档中确实有一个 post 标题为 GMM classification:

Demonstration of Gaussian mixture models for classification.

我猜这在 2017 年写上述回复时还不存在。但是,深入研究提供的代码,您会发现 GMM 模型实际上是按照上面 lejlot 提出的方式使用的;有 no 形式的语句 classifier.fit(X_train, y_train) - all 用法是 classifier.fit(X_train) 的形式,即不使用实际标签。

这正是我们对类似 聚类 的算法(这确实是 GMM)所期望的,而不是对分类器的期望。 scikit-learn 确实提供了一个选项,用于在 GMM fit method:

中提供标签

fit (self, X, y=None)

你在这里实际使用过(同样,正如上面的回复所暗示的那样,2017 年可能不存在),但是,鉴于我们对 GMM 及其用法的了解,目前还不清楚这个参数是什么是为了(并且,请允许我说,scikit-learn 分享了一些实践,这些实践从纯粹的 编程 的角度来看可能看起来很合理,但从 scikit-learn 的角度来看却毫无意义=45=]建模透视)。

最后一句话:尽管修复随机种子(如评论中所建议的那样)可能 看起来 可以“工作”,但相信一个“分类器”可以提供介于0.4 和 0.7 取决于随机种子可以说 不是 一个好主意...

sklearn中,gmm中的簇标签没有任何意义。因此,每次您 运行 一个 gmm,标签可能会有所不同。这可能是结果不可靠的原因之一。