0
$\begingroup$

I have multilabel problem.
I was using onevsrestclassifier and now i want to use onevsoneclassifier.

from sklearn.svm import SVC
classifire = SVC(gamma='auto')
accuracy = []

skf = StratifiedKFold(n_splits=10,random_state=None)
kf = KFold(n_splits=5)

skf.get_n_splits(X_train,y_train)

for train_index,test_index in kf.split(X_train,y_train):
    X1_train,X1_test = X_train.iloc[train_index],X_train.iloc[test_index]
    y1_train,y1_test = y_train.iloc[train_index],y_train.iloc[test_index]
    clf = OneVsOneClassifier(classifire)
#     clf = OneVsRestClassifier(classifire)
    clf.fit(X1_train,y1_train)
    prediction = clf.predict(X1_test)
    
    score = accuracy_score(prediction,y1_test)
    print(score)

But i am getting error only in OneVsOneClassifier

<ipython-input-47-91b351c58c24> in <module>
     11     clf = OneVsOneClassifier(classifire)
     12 #     clf = OneVsRestClassifier(classifire)
---> 13     clf.fit(X1_train,y1_train)
     14     prediction = clf.predict(X1_test)
     15 
..
ValueError: bad input shape (19051, 206)

I am new here. Can you help me ?


print(X1_train.shape)
print(y1_train.shape)
print(X1_test.shape)
print(y1_test.shape)

o/p

(19051, 875)
(19051, 206)
(4763, 206)
(4763, 875)

UPDATE

accuracy = []

skf = StratifiedKFold(n_splits=10,random_state=None)
kf = KFold(n_splits=5)

skf.get_n_splits(X_train,y_train)

for train_index,test_index in kf.split(X_train,y_train):
    X1_train,X1_test = X_train.iloc[train_index],X_train.iloc[test_index]
    y1_train,y1_test = y_train.iloc[train_index],y_train.iloc[test_index]
    clf = OneVsOneClassifier(classifire)
#     clf = OneVsRestClassifier(classifire)
    print("X1_train",X1_train.shape)
    print("y1_train",y1_train.shape)
    print('X1_test',X1_test.shape)
    print('y1_test',y1_test.shape)
    clf.fit(X1_train,y1_train)
    prediction = clf.predict(X1_test)
    
    score = accuracy_score(prediction,y1_test)
    print(score)

And the output is

X1_train (19051, 875)
y1_train (19051, 206)
X1_test (4763, 875)
y1_test (4763, 206)

So X1_train and test have same columns. But the error is same

$\endgroup$
7
  • $\begingroup$ the rows of X1_train and y1_train should match, before the error line type this command and print the output - print(X1_train.shape,y1_train.shape) $\endgroup$ Sep 21, 2020 at 12:00
  • $\begingroup$ also print -> print(X_train.shape,y_train.shape) $\endgroup$ Sep 21, 2020 at 12:02
  • 1
    $\begingroup$ X train and test should have same number of columns and (X train and Y train) should have same number of rows and (Xtest and Ytest) should have same number of rows $\endgroup$ Sep 21, 2020 at 14:24
  • 1
    $\begingroup$ your x_train and X_test doesn't have same number of columns(input features) $\endgroup$ Sep 21, 2020 at 14:25
  • 1
    $\begingroup$ Vohoooo thankyou man. $\endgroup$ Sep 21, 2020 at 14:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.