Why n-split is not possible for a dataframe with KFold?

0

On running below code on python 3.7, I am getting the following response: 'DataFrame' object has no attribute 'n_splits'.
How to get rid of this?

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import sklearn.model_selection as train_test_split
from sklearn.tree import DecisionTreeClassifier
%matplotlib inline
import seaborn as sns
sns.set()
from sklearn.neighbors import KNeighborsClassifier

from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score

train=pd.read_csv(r"C:\Users\Pranjal Pathak\Desktop\kaggle-titanic-master\Digit recognizer kaggle\train.csv")
test=pd.read_csv(r"C:\Users\Pranjal Pathak\Desktop\kaggle-titanic-master\Digit recognizer kaggle\test.csv")

train1=train.drop('label',axis=1)
test1=train['label']

Kfold=KFold(n_splits=30,shuffle=True,random_state=0)

clf=KNeighborsClassifier(n_neighbors = 20)
scoring='accuracy'

score=cross_val_score(clf,train1,test1,cv=KFold,n_jobs=1,scoring=scoring)

Pranjal Pathak

Posted 2019-06-19T15:43:06.113

Reputation: 1

Answers

1

There is a typo error in the below line. Change KFold to Kfold below and try.

score=cross_val_score(clf,train1,test1,cv=KFold,n_jobs=1,scoring=scoring)

nag

Posted 2019-06-19T15:43:06.113

Reputation: 161