Luuk van Gasteren
Luuk van Gasteren

Reputation: 111

Error using svc.fit(): ValueError: bad input shape

I have data about Parkinson patients stored in the dataframe X and whether a patient has Parkinson indicated by y (0 or 1). This is retrieved by:

X=pd.read_csv('parkinsons.data',index_col=0)
y=X['status']
X=X.drop(['status'],axis=1)

Then, I create training and test samples:

X_train, y_train, X_test, y_test = train_test_split(X,y,test_size=0.3,random_state=7)

I want to use SVC on this training data:

svc=SVC()
svc.fit(X_train,y_train)

Then, I get the error: ValueError: bad input shape (59, 22). What did I do wrong and how can I get rid of this error?

Upvotes: 1

Views: 69

Answers (2)

Srikar Manthatti
Srikar Manthatti

Reputation: 504

Either use this

X_train, y_train, X_test, y_test =train_test_split(X,y,test_size=0.3,random_state=7)
svc=SVC()
svc.fit(X_train,X_test)

Or this

X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3,random_state=7)
svc=SVC()
svc.fit(X_train,y_train)

I prefer using the second one

Upvotes: 0

Celius Stingher
Celius Stingher

Reputation: 18367

You have problems with the definition of train_test_split Careful! train_test_split outputs the X part first followed by the Y part. You are actually naming y_train what is X_test. Change this and it should work:

X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3,random_state=7)

Upvotes: 2

Related Questions