0

我创建了一个DataFrame( df_kfolds) 有 2 列:kfolds& Mean_ScorewhereKfolds的值从 3 到 5 不等。我试图计算mean_score从以下派生的每个 kfold 的:

cross_val_score(lr, X, y, cv=3, error_score = 1).mean()

在哪里 :

lr = LinearRegression()
X are the feature variables
y is the target
cv = # of kfolds

我知道您可以使用来自另一列的值基于简单的数学计算创建列,但不确定您是否可以使用统计函数。这是我的代码:

df_kfolds['Mean_Score'] = cross_val_score(lr, X, y, cv=(df_kfolds['kfolds']), error_score = 1).mean()

抛出此错误:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

感谢您对此的任何帮助!

4

0 回答 0