我是Machine Learning的新手,我正在使用python应用程序,该应用程序使用我将发布片段的数据集对扑克手进行分类。它似乎不太好用。我收到以下错误:
File "C:Testing.py", line 32, in <module>
print(classification_report(training_data, predictions))
File "C:Anaconda3\lib\site-packages\sklearn\metrics\classification.py", line 1391, in classification_report
labels = unique_labels(y_true, y_pred)
File "C:\Anaconda3\lib\site-packages\sklearn\utils\multiclass.py", line 84, in unique_labels
raise ValueError("Mix type of y not allowed, got types %s" % ys_types)
ValueError: Mix type of y not allowed, got types {'multiclass-multioutput', 'multiclass'}
以下是我设法创建的代码:
import pandas as pnd
from sklearn.preprocessing import StandardScaler
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import classification_report,confusion_matrix
training_data = pnd.read_csv("train.csv")
print(training_data)
training_data['id'] = range(1, len(training_data) + 1) # For 1-base index
print(training_data)
test_data = pnd.read_csv("test.csv")
result = pnd.DataFrame(test_data['id'])
print(result)
test_data = test_data.drop(['id'], axis=1)
training_datafile = training_data
labels = training_datafile['hand']
features = training_datafile.drop(['id', 'hand'], axis=1)
scaler = StandardScaler()
# Fit only to the training data
scaler.fit(training_datafile)
X_train = scaler.transform(training_datafile)
X_test = scaler.transform(training_datafile)
mlp = MLPClassifier(hidden_layer_sizes=(100, 100, 100))
mlp.fit(features, labels)
predictions = mlp.predict(test_data)
len(mlp.coefs_)
len(mlp.coefs_[0])
len(mlp.intercepts_[0])
result.insert(1, 'hand', predictions)
result.to_csv("./ANNTEST.csv", index=False)
print(classification_report(training_data, predictions))
以下是我分别使用培训和测试数据的数据集的片段: 训练数据 测试数据
我希望知道的是显示某种准确度百分比或某种类型的功能,例如classification_report。引导我朝着正确的方向前进会有很大的帮助!
答案 0 :(得分:1)
我认为您在此处收到错误,因为您错误地使用了classification_report
。我们来看看documentation:
classification_report(y_true, y_pred, ...)
y_true : 1d array-like, or label indicator array / sparse matrix
Ground truth (correct) target values.
y_pred : 1d array-like, or label indicator array / sparse matrix
Estimated targets as returned by a classifier.
您传递training_data
作为第一个参数(不是1d数组)。相反,您需要将您想要比较的测试数据的 true 手传递给您训练有素的分类的预测手。因此,这可能有效:
print(classification_report(test_data["hand"], predictions))