我正在研究 ML 專案,我正在嘗試roc_curve使用以下代碼繪制
plot_roc_curve(rfc,ord_train_t,y_train)
這rfc是我的模型,ord_train_t是我的輸入訓練資料,y_train是訓練資料的標簽。輸入和輸出的形狀如下所示

但我不確定從哪里引起以下錯誤(我的輸入和輸出在任何地方都沒有 200 行)
ValueError: x and y must have same first dimension, but have shapes (200,) and (732, 15)
完整的錯誤如下
----> 1 plot_roc_curve(rfc,ord_train_t,y_train)
C:\Users\abcd~1\AppData\Local\Temp/ipykernel_4180/1232546388.py in plot_roc_curve(fpr, tpr, label)
6 plt.figure(figsize=(8,8))
7 plt.title('ROC Curve')
----> 8 plt.plot(fpr, tpr, linewidth=2, label=label)
9 plt.plot([0, 1], [0, 1], 'k--')
10 plt.axis([-0.005, 1, 0, 1.005])
~\Anaconda3\lib\site-packages\matplotlib\pyplot.py in plot(scalex, scaley, data, *args, **kwargs) 3017 @_copy_docstring_and_deprecators(Axes.plot) 3018 def plot(*args, scalex=True, scaley=True, data=None, **kwargs):
-> 3019 return gca().plot( 3020 *args, scalex=scalex, scaley=scaley, 3021 **({"data": data} if data is not None else {}), **kwargs)
~\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in plot(self, scalex, scaley, data, *args, **kwargs) 1603 """ 1604 kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D)
-> 1605 lines = [*self._get_lines(*args, data=data, **kwargs)] 1606 for line in lines: 1607 self.add_line(line)
~\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in
__call__(self, data, *args, **kwargs)
313 this = args[0],
314 args = args[1:]
--> 315 yield from self._plot_args(this, kwargs)
316
317 def get_next_color(self):
~\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in
_plot_args(self, tup, kwargs, return_kwargs)
499
500 if x.shape[0] != y.shape[0]:
--> 501 raise ValueError(f"x and y must have same first dimension, but "
502 f"have shapes {x.shape} and {y.shape}")
503 if x.ndim > 2 or y.ndim > 2:
ValueError: x and y must have same first dimension, but have shapes (200,) and (732, 15)
uj5u.com熱心網友回復:
根據錯誤訊息,您將模型傳遞給plt.plotinplot_roc_curve函式。
def plot_roc_curve(fpr, tpr, label):
...
plt.plot(fpr, tpr, linewidth=2, label=label)
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/430603.html
標籤:Python 数据框 matplotlib 机器学习 scikit-学习
上一篇:按月-年的散點圖矩陣
下一篇:從字典中繪制餅圖?
