Attributeerror: 'tuple' Object has no attribute 'reshape'

Asked

Viewed 611 times

1

Error:

AttributeError: 'tuple' object has no attribute 'reshape'

Code:

xx, yy = np.meshgrid(np.arange(x_min, x_max, h),np.arange(y_min, y_max, h))
y_pred = y_pred.reshape(xx.shape)
plt.figure()

In y_pred = y_pred.reshape(xx.shape) there is this mistake, what to do?

  • Apparently y_pred is a tuple and you hoped it wasn’t. So what you can do is investigate why y_pred is a tuple.

1 answer

2


It is because . reshape is a method only of the Numpy array. So for some reason you stored the predictions of the algorithm within a tuple instead of a numpy array. you can do the following procedure and try again.

y_pred = np.array(y_pred)

To check the type of object you are dealing with you can use for example:

type(y_pred)

In case of any problem note how you are making the prediction with the algorithm.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.