TransWikia.com

ValueError: bad input shape

Data Science Asked by Rajan Lagah on December 5, 2020

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

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP