Title: CV linear regression KeyError: "Passing list-likes to .loc or [] with any missing labels is no longer supported
Tags: python;cross-validation
Question: I trying to compare the linear regression R squared with the gradient boosting’s one using k-fold cross-validation, a procedure that consists in splitting the data k times into train and validation sets and for each split, the model is trained and tested
```## call model
model = linear_model.LinearRegression()
## K fold validation
scores = []
cv = model_selection.KFold(n_splits=5, shuffle=True)
fig = plt.figure()
i = 1
for train, test in cv.split(X_train, y_train):
    prediction = model.fit(X_train[train],
                 y_train[train]).predict(X_train[test])
    true = y_train[test]
    score = metrics.r2_score(true, prediction)
    scores.append(score)
    plt.scatter(prediction, true, lw=2, alpha=0.3, 
                label='Fold %d (R2 = %0.2f)' % (i,score))
    i = i+1
plt.plot([min(y_train),max(y_train)], [min(y_train),max(y_train)], 
         linestyle='--', lw=2, color='black')
plt.xlabel('Predicted')
plt.ylabel('True')
plt.title('K-Fold Validation')
plt.legend()
plt.show()
```
But I'm not able to avoid:
KeyError: &quot;Passing list-likes to .loc or [] with any missing labels is no longer supported. The following labels were missing: Int64Index([   6,    9,   13,   32,   40,\n            ...\n            4221, 4223, 4224, 4226, 4233],\n           dtype='int64', length=679

Comment: Yes, I hope, I did:X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.05, random_state=1234, stratify=df['q
'])

Comment: It doesnt work for me because X, y are panda arrays

Comment: Are you sure your X_train and y_train have the same number of samples and same row indexes?

Comment: Please look at this [link](https://stackoverflow.com/questions/60459218/pandas-passing-list-likes-to-loc-or-with-any-missing-labels-is-no-longer-su). Try using .iloc to access the rows



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:11/13/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><cross-validation>', 'Title': 'CV linear regression KeyError: "Passing list-likes to .loc or [] with any missing labels is no longer supported', 'ViewCount': 93, 'id': 64820222, 'user_AboutMe': '', 'user_AccountId': 19708470.0, 'user_DisplayName': 'Ana Martin', 'user_Reputation': 1.0, 'user_Views': 1.0, 'user_id': 14429553.0}}