In this code, I get nan for the test result, what is the reason?
Average Train R^2: 0.504
Average Test R^2: nan
loo = LeaveOneOut()
train_r2_scores = []
test_r2_scores = []
for train_index, test_index in loo.split(X):
X_train, X_test = X.iloc[train_index], X.iloc[test_index]
y_train, y_test = y.iloc[train_index], y.iloc[test_index]
model = LinearRegression()
model.fit(X_train, y_train)
y_train_pred = model.predict(X_train)
train_r2 = r2_score(y_train, y_train_pred)
train_r2_scores.append(train_r2)
y_test_pred = model.predict(X_test)
test_r2 = r2_score(y_test, y_test_pred)
test_r2_scores.append(test_r2)
print("Average Train R^2:", np.mean(train_r2_scores))
print("Average Test R^2:", np.mean(test_r2_scores))```