Я хочу использовать Скорректированная Rsquare в функции cross_val_score
.Я попытался с make_scorer
функцией, но она не работает.
from sklearn.cross_validation import train_test_split
X_tr, X_test, y_tr, y_test = train_test_split(X, Y, test_size=0.2, random_state=0)
regression = LinearRegression(normalize=True)
from sklearn.metrics.scorer import make_scorer
from sklearn.metrics import r2_score
def adjusted_rsquare(y_true,y_pred):
adjusted_r_squared = 1 - (1-r2_score(y_true, y_pred))*(len(y_pred)-1)/(len(y_pred)-X_test.shape[1]-1)
return adjusted_r_squared
my_scorer = make_scorer(adjusted_rsquare, greater_is_better=True)
score = np.mean(cross_val_score(regression, X_tr, y_tr, scoring=my_scorer,cv=crossvalidation, n_jobs=1))
Выдает ошибку:
IndexError: positional indexers are out-of-bounds
Есть ли способ использовать мою пользовательскую функцию т.е.adjusted_rsquare
с cross_val_score
?