0
$\begingroup$

I am trying to do svm model training and it gives this error:

 ValueError: Found input variables with inconsistent numbers of samples: [91, 212]

Code:

target = data.target
target.head()

##splitiing data into training and test data
X_train, X_test, y_train, y_test = train_test_split(train, target, test_size=0.3, random_state=101)
print("X_train size ===>", X_train.shape)
print("y_train size ===>", y_train.shape)
print("X_test size ===>", X_test.shape)
print("y_test size ===>", y_test.shape)

#Create a svm Classifier

clf = svm.SVC(kernel='linear')

#training the model using the training sets

clf.fit(X_train, y_train)

#predict the response for test dataset

y_pred = clf.predict(X_train)
$\endgroup$
1
  • $\begingroup$ Please look at here. $\endgroup$
    – ebrahimi
    Jun 13, 2020 at 7:12

1 Answer 1

0
$\begingroup$

This error usually indicates your train and test in the train_test_split() function call are different sizes. You may need to reshape one to get them to match. Look at the shapes of train and test to see what is the problem.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.