这是我在 StackOverflow 上的第一篇文章!我正在使用MLPRegressor
为我的问题生成二进制类多输出预测。一旦我得到我的预测,我使用 对所有值进行四舍五入numpy.round()
,以便我可以使用accuracy_score
(因为准确度分数仅适用于分类问题)。sklearn.metrics.accuracy_score
在此之后,当我收到以下错误时,我尝试使用:
ValueError: Classification metrics can't handle a mix of multilabel-indicator and multiclass-multioutput targets
仅当我max_iter
在MLPRegressor
. 当我不手动设置时,回归器不会收敛但不会发生错误。
from sklearn.neural_network import MLPRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import numpy as np
from joblib import dump, load
data = np.loadtxt('tictac_multi.txt')
X = data[:,:9]
y = data[:,9:]
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size = 0.20,random_state=7)
regr = MLPRegressor(random_state=7,hidden_layer_sizes=(9,81,729,81,81,9),activation='tanh',learning_rate='invscaling',solver='adam',max_iter = 400).fit(X_train, y_train)
preds = regr.predict(X_test)
preds = np.round(preds)
print(accuracy_score(y_test,preds))
这是数据集的链接:http: //www.connellybarnes.com/work/class/2016/deep_learning_graphics/proj1/tictac_multi.txt
堆栈跟踪:
Traceback (most recent call last):
File "mlp.py", line 21, in <module>
scores.append(accuracy_score(y_test,preds))
File "C:\Users\animu\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\utils\validation.py", line 73, in inner_f
return f(**kwargs)
File "C:\Users\animu\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\metrics\_classification.py", line 187, in accuracy_score
y_type, y_true, y_pred = _check_targets(y_true, y_pred)
File "C:\Users\animu\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\metrics\_classification.py", line 91, in _check_targets
"and {1} targets".format(type_true, type_pred))
ValueError: Classification metrics can't handle a mix of multilabel-indicator and multiclass-multioutput targets