I have a training set consisting of 39 compounds. Here is a short code to calculate LOO q2 to SVR:

from sklearn.model_selection import GridSearchCV

from sklearn.metrics import make_scorer, r2_score

from sklearn.svm import SVR

clf_svr = SVR(C=1.0, gamma='scale', epsilon=0.1)

parameters = {'kernel':['linear'],

'gamma':['scale', 'auto'],

'C':[300000],

"epsilon":[0.001]}

grid_search_cv_clf = GridSearchCV(clf_svr, parameters, cv=len(X_train), n_jobs=-1)

grid_search_cv_clf.fit(X_train, y_train)

y_train_pred = grid_search_cv_clf.predict(X_train)

train_r2_LOO = r2_score(y_train, y_train_pred)

print("Train q^2 LOO:", train_r2_LOO)

but it gives a warning: C:\Users\plato\anaconda3\lib\site-packages\sklearn\model_selection\_search.py:952: UserWarning: One or more of the test scores are non-finite: [nan nan]

warnings.warn(

Then I have Train q^2 LOO: 0.8450423173708722

But regular R^2 with cv=5 output R^2: 0.8450423173708722

Please, help me to calculate q2 value for leave-one-out cross-validation using scikit-learn! I need to calculate q2 for SVR and RFR!

Similar questions and discussions