Python sklearn:GMM模型产生了糟糕的结果

Python sklearn:GMM模型产生了糟糕的结果,python,scikit-learn,artificial-intelligence,Python,Scikit Learn,Artificial Intelligence,我试图使用GMM模型对虹膜数据集进行分类。我的模型似乎产生了不一致的结果,有些运行的准确率为90%,有些运行的准确率为33%(有些甚至一直到0%)。我不确定错误是否发生在分类阶段,或者我对准确性的预处理或打印声明不正确 在定义分类器时,我尝试过更改迭代次数和init_参数。我正在使用scikit学习版0.21.3和Python 3.7.0 import numpy as np from sklearn.model_selection import StratifiedKFold from skl

我试图使用GMM模型对虹膜数据集进行分类。我的模型似乎产生了不一致的结果,有些运行的准确率为90%,有些运行的准确率为33%(有些甚至一直到0%)。我不确定错误是否发生在分类阶段,或者我对准确性的预处理或打印声明不正确

在定义分类器时,我尝试过更改迭代次数和init_参数。我正在使用scikit学习版0.21.3和Python 3.7.0

import numpy as np
from sklearn.model_selection import StratifiedKFold
from sklearn.mixture import GaussianMixture as GMM


def data_processor(input_file):
    data = []
    with open(input_file, 'r') as f:
        for line in f:
            line = line.strip().split(',')
            if line[-1] == 'Iris-setosa':
                line[-1] = 0
            elif line[-1] == 'Iris-versicolor':
                line[-1] = 1
            elif line[-1] == 'Iris-virginica':
                line[-1] = 2
            data.append(line)

    return np.array(data, dtype=float)


x, y = data_processor('iris.txt')[:, :-1], data_processor('iris.txt')[:, -1]
# split data into 5 chucnks, 80% used for training and 20% for testing
skf = StratifiedKFold(n_splits=5)
train_index, test_index = next(iter(skf.split(x, y)))
x_train, y_train = x[train_index], y[train_index]
x_test, y_test = x[test_index], y[test_index]
# calculate number of components in data set using number of classes
num_classes = len(np.unique(y_train))
# build classifier and fit model
classifier = GMM(n_components=num_classes, covariance_type='full',
                 max_iter=200)
classifier.fit(x_train)

# Make predictions and print accuracy
y_train_pred = classifier.predict(x_train)
accuracy_training = np.mean(y_train_pred.ravel() == y_train.ravel()) * 100
print('Accuracy on training data =', accuracy_training)

y_test_pred = classifier.predict(x_test)
accuracy_testing = np.mean(y_test_pred.ravel() == y_test.ravel()) * 100
print('Accuracy on testing data =', accuracy_testing)
测试数据的数量为150行,每类50行。以前在同一数据集中使用不同的模型时,我得到的准确率约为90-93%

输入文件包含以下格式的数据:5.9,3.0,5.1,1.8,Iris virginica

我还尝试使用以下方法缩放数据:
x=预处理。比例(x)

现在的数据如下所示:

x[0] = [-0.90068117  1.03205722 -1.3412724  -1.31297673] 
y[0] = 0.0
然而,这并不影响精度