TypeError: scatter() got multiple values for argument 's' (Plot Logistic Regression)

user15601343

I am trying to plot a decision boundary for logistic regression but i got this error :

TypeError: scatter() got multiple values for argument 's'

Here is my code :

logreg = LogisticRegression()
logreg.fit(X_train,y_train)

b = logreg.intercept_[0]
w1, w2 = logreg.coef_.T
c = -b/w2
m = -w1/w2

# Plot the data and the classification with the decision boundary.
xmin, xmax = -1, 2
ymin, ymax = -1, 2.5
xd = np.array([xmin, xmax])
yd = m*xd + c
plt.plot(xd, yd, 'k', lw=1, ls='--')
plt.fill_between(xd, yd, ymin, color='tab:blue', alpha=0.2)
plt.fill_between(xd, yd, ymax, color='tab:orange', alpha=0.2)

plt.scatter(*X[y==0].T, s=8, alpha=0.5)
plt.scatter(*X[y==1].T, s=8,  alpha=0.5)
plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)
plt.show()

Since i am a beginner i would also like to know if there is possibility to plot my logistic regression including all features or something else (2 most important features). I had to choose only 2 columns here.

EDIT : I also got this error :

TypeError: scatter() takes from 2 to 13 positional arguments but 1715 were given

For your information :

X = df
X = X.drop(columns=['answer']) #features
y = df['answer'] #target 
X.shape # (4948, 2)
y.shape # (4948,)
X[y==0].shape # (1715,2)

Any help would be appreciated ! Thanks.

liorr

The problem is with the shape of what you are trying to plot, namely, X[y==0]. Here I recreate a 1715x2 matrix with the same shape, and try to scatter() it:

import numpy as np
from matplotlib import pyplot as plt

x = np.random.rand(1715, 2)
print(np.shape(x)) # (1715, 2)
plt.scatter(*x, s= 8)

I get a TypeError: scatter() got multiple values for argument 's'.

However, if I transpose it:

x = np.random.rand(1715, 2)
print(np.shape(x))
plt.scatter(*x.T, s= 8)

plt.show()

I get:

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related