2

I try to fit SVC in skikit-learn, but got TypeError: fit() missing 1 required positional argument: 'self' in the line SVC.fit(X=Xtrain, y=ytrain)

from sklearn.svm import SVC
import seaborn as sns; sns.set()


from sklearn.datasets.samples_generator import make_circles
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score


X, y = make_circles(100, factor=.2, noise=.2)
Xtrain, Xtest, ytrain, ytest = train_test_split(X,y,random_state=42)

svc = SVC(kernel = "poly")
SVC.fit(X=Xtrain, y=ytrain)
predictions = SVC.predict(ytest)
mnm
  • 1,962
  • 4
  • 19
  • 46
Katya
  • 111
  • 3
  • 13

1 Answers1

2

The problem is that you are creating the model here svc = SVC(kernel = "poly"), but you're calling the fit with a non-instantiable model.

You must change the object to:

svc_model = SVC(kernel = "poly")
svc_model.fit(X=Xtrain, y=ytrain)
predictions = svc_model.predict(Xtest)

I suggest you to Indique the test size, normally the best practice is with 30% for test and 70% for training. So you can indicate.

Xtrain, Xtest, ytrain, ytest = train_test_split(X,y,test_size=0.30, random_state=42)
Kenry Sanchez
  • 1,703
  • 2
  • 18
  • 24
  • @KaterinaMelnikova Also note that you will need to supply the `Xtest` to the `predict` method and not `ytest`. – Vivek Kumar May 08 '19 at 15:12
  • Yes, you are right. Well, the idea is to get knowledge about how good is the model predicting new data. I'm gonna update the response for you – Kenry Sanchez May 08 '19 at 15:15