我有一个回归问题,我交叉验证结果和评估性能。我事先知道,基本事实不能小于零。因此,我想截取预测,在它们被输入到分数度量之前,将预测剪辑为零。我认为使用make\u 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:我知道有约束估计,但我想看看这样的启发式方法会有什么效果。你知道吗
您可以做的一件事是按照您的建议,在使用
make_scorer()
的自定义记分器函数中包装您要使用的那些记分器(r2_score
,mean_squared_error
)。你知道吗看看this part of the sklearn documentation和this Stack Overflow post中的一些例子。特别是,您的函数可以执行以下操作:
这允许您在调用记分函数(在本例中是
r2_score
或mean_squared_error
)之前在记分器中进行后处理。然后要使用它,只需像上面那样使用make\u scorer,根据scorer是评分函数(如r2,越大越好)还是损失函数(均方误差为0,即越小)来设置greater_is_better
:相关问题 更多 >
编程相关推荐