K.level4
K.level4

Reputation: 11

LeaveOneOut() - Key Error in an SVM Classifier

I am working with a csv file: 39 participants (rows) each having values for 30 features (columns). I am trying to implement LeaveOneOut() using the below code. I am getting a key error... Any help would be appreciated!

# code
X = df.drop(labels=['Diagnosis'], axis=1) # dropped diagnosis 

Y = df['Diagnosis'].values
Y = Y.astype('int') 

loo = LeaveOneOut()
for train, test in loo.split(X, Y):
    X_train, X_test = X[train], X[test]
    Y_train, Y_test = Y[train], Y[test]

svm = SVC(kernel='linear')
svm.fit(X_train,Y_train)
pred_svm = svm.predict(X_test)
print(classification_report(Y_test, pred_svm))
print(confusion_matrix(Y_test, pred_svm))

Upvotes: 1

Views: 124

Answers (1)

alparslan mimaroğlu
alparslan mimaroğlu

Reputation: 1490

If you can share what is the result of the loo I can answer more accurately but as far as I understand it is a list of indexes instead of a boolean mask therefore you can change your code like this.

for train, test in loo.split(X, Y):
    X_train, X_test = X.loc[train].copy(), X.loc[test].copy()
    Y_train, Y_test = Y[train], Y[test]

Upvotes: 0

Related Questions