gpt4 book ai didi

python - MLP分类

转载 作者:行者123 更新时间:2023-11-30 09:09:33 30 4
gpt4 key购买 nike

我是机器学习的新手,正在开发一个 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))

以下是我分别使用的训练和测试数据的数据集片段:列车数据 enter image description here测试数据 enter image description here

该程序基本上可以工作,我正在设法预测扑克牌,如下所示: enter image description here

我想知道的是显示某种准确率或某种函数,例如分类报告。引导我走向正确的方向将会有很大的帮助!

最佳答案

我认为您在这里收到错误是因为您错误地使用了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作为第一个参数(不是一维数组)。相反,您需要传递测试数据的真实手牌,并将其与经过训练的分类器的预测手牌进行比较。因此,这可能有效:

print(classification_report(test_data["hand"], predictions))

关于python - MLP分类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43294745/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com