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

from sklearn import linear_model

lm = linear_model.LinearRegression()

from sklearn.model_selection import cross_val_score

cvs=cross_val_score(lm, X_train, y_train, cv=21)

mean_cross_val_score = cvs.mean()

mean_cross_val_score

but it gives a mistake: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples.

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

More Andrey А. Buglak's questions See All
Similar questions and discussions