我有一个回归问题,正在进行交叉验证并评估性能。我事先知道,真实值不能小于零。因此,我想在预测传递到分数度量之前截断预测以将其限制为零。我认为使用make_scorer函数可以很好地完成这个任务。是否有可能在交叉验证之后,在应用评估指标之前对预测进行后处理?
from sklearn.metrics import mean_squared_error, r2_score, make_scorer
from sklearn.model_selection import cross_validate
# X = Stacked feature vectors
# y = ground truth vector
# regr = some regression estimator
#### How to indicate that the predictions need post-processing
#### before applying the score function???
scoring = {'r2': make_scorer(r2_score),
'neg_mse': make_scorer(mean_squared_error)}
scores = cross_validate(regr, X, y, scoring=scoring, cv=10)
PS:我知道有受限估计器,但我想看看这种启发式方法的表现。
cross_validate
函数内部发生的。如果您感兴趣,可以查看源代码,但是由于您必须在许多函数之间跳转以跟踪数据实际用于拟合和评分模型的位置,因此有点难以阅读。但是,是的,y_pred和y_test是每个交叉验证折叠的结果。 - Mihai Chelaru