I am working on ML project where I am trying to plot the roc_curve
using the below code
plot_roc_curve(rfc,ord_train_t,y_train)
Here rfc
is my model, ord_train_t
is my input train data and y_train
is the labels for training data. The shape of input and output is given below
But I am not sure from where the below error is caused (my input and output don't have 200 rows anywhere)
ValueError: x and y must have same first dimension, but have shapes (200,) and (732, 15)
The full error is given below
----> 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)
CodePudding user response:
According to the error message, you passed the model to plt.plot
in plot_roc_curve
function.
def plot_roc_curve(fpr, tpr, label):
...
plt.plot(fpr, tpr, linewidth=2, label=label)
...