我正在尝试绘制混淆矩阵。但它说预测语法无效

问题描述 投票:0回答:0

这是我的代码:

pred=14.predict(X_test)
pred=np.argmax(pred,axis=1)
y_test_new=np.argmax(y_test,axis=1)
print(classification_report(y_test_new,pred))
fig,ax=plt.subplots(1,1,figsize=(14,7))
sns.heatmap(confusion_matrix(y_test_new,pred), ax = ax, xticklabels = labels,yticklabels =
labels, annot=True,cmap=colors_green[::-1],alpha=0.7,linewidths=2,linecolor-colors_dark[3])
fig.text(s="Confusion Matrix", size = 18 
fontweight ="bold",fontname="monospace",color=colors_dark[1],y=0.92, x = 0.28, alpha = 0.8)

在上面的代码中,第一行 14.predict(X_test) 显示语法错误。请帮助我


AxisError                                 Traceback (most recent 
call last)
/tmp/ipykernel_27/3855250763.py in <module>
  1 pred=model.predict(X_test)
  2 pred=np.argmax(pred,axis=1)
----> 3 y_test_new=np.argmax(y_test,axis=1)
  4 print(classification_report(y_test_new,pred))
  5 fig,ax=plt.subplots(1,1,figsize=(14,7))

<__array_function__ internals> in argmax(*args, **kwargs)

/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py 
in argmax(a, axis, out)

1193 第1194章 -> 1195 返回 _wrapfunc(a, 'argmax', axis=axis, out=out) 1196 1197

/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py 
in _wrapfunc(obj, method, *args, **kwds)
 55 
 56     try:
---> 57         return bound(*args, **kwds)
 58     except TypeError:
 59         # A TypeError occurs if the object does have such a 
method in its

AxisError: axis 1 is out of bounds for array of dimension 1
python confusion-matrix ml
© www.soinside.com 2019 - 2024. All rights reserved.