0

I have created dummy variables using label encoder and i run my model but when i am checking accuracy of my model using K Fold and Cross validation i am getting Bad Input shape error. Please help to fix it

I have tried reshaping the model and also I have change my dummy variables creation using LabelEncoder

from sklearn.model_selection import train_test_split 

columns = df_train.drop('default_ind',axis =1).columns 

X_train, X_test, y_train, y_test = train_test_split(df_train[columns], 
df_train, test_size = 0.3) 

from sklearn.linear_model import LogisticRegression 

from sklearn.tree import DecisionTreeClassifier 

from sklearn.svm import SVC 

from sklearn.neighbors import KNeighborsClassifier 

from sklearn.naive_bayes import GaussianNB 

from sklearn.ensemble import RandomForestClassifier 

models=[]

 models.append(("logreg",LogisticRegression(solver='liblinear')))
 models.append(("tree",DecisionTreeClassifier())) 
 models.append(("forest",RandomForestClassifier(n_estimators=20))) 
 models.append(("svc",SVC())) 
 models.append(("knn",KNeighborsClassifier()))
 models.append(("nb",GaussianNB())) 
 seed=7 
 scoring='accuracy' 

from sklearn.model_selection import KFold 

from sklearn.model_selection import cross_val_score 
result=[] 
names=[] 

for name,model in models: 
    kfold=KFold(n_splits=5,random_state=seed)
    cv_result=cross_val_score(model,X_train,y_train,cv=kfold,scoring=scoring) 
    result.append(cv_result) 
    names.append(name) 
print("%s %f %f" % (name,cv_result.mean(),cv_result.std()))

I am not able to check the accuracy and getting below error

ValueError: bad input shape (335427, 32)

Itamar Mushkin
  • 2,803
  • 2
  • 16
  • 32
emi pathak
  • 29
  • 2

1 Answers1

0

Error message suggests that you are trying to pass more than one column (32 from error message) in LabelEncoder()? If yes then note that it supports single columns, you need to iterate your columns in order to encode them, see the answer at Sklearn Label Encoding multiple columns pandas dataframe

ManojK
  • 1,570
  • 2
  • 9
  • 17