Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 控制预测是否为>;0正在使用GridSearchCV_Python_Scikit Learn_Xgboost_Gridsearchcv - Fatal编程技术网

Python 控制预测是否为>;0正在使用GridSearchCV

Python 控制预测是否为>;0正在使用GridSearchCV,python,scikit-learn,xgboost,gridsearchcv,Python,Scikit Learn,Xgboost,Gridsearchcv,我正在使用GridSearchCV来估计回归器的参数。 我使用计分功能(我想继续使用) y总是正的,但是发生的是,在5倍网格搜索中的一些预测恰好是负的(即使它不应该发生,因为我的目标变量总是正的),因此我得到了错误消息 ValueError: Mean Squared Logarithmic Error cannot be used when targets contain negative values. 因为记分员试图计算一个负数的对数(不幸的预测) 有没有办法控制GridSearchCV

我正在使用
GridSearchCV
来估计回归器的参数。 我使用计分功能(我想继续使用)

y总是正的,但是发生的是,在5倍网格搜索中的一些预测恰好是负的(即使它不应该发生,因为我的目标变量总是正的),因此我得到了错误消息

ValueError: Mean Squared Logarithmic Error cannot be used when targets contain negative values.
因为记分员试图计算一个负数的对数(不幸的预测)


有没有办法控制GridSearchCV中的预测?你将如何解决这个问题?

如果你知道你的依赖项(y值)总是正的,你可以使用损失函数来限制你的预测也在正的范围内


XGBoost中支持的一个示例是(参见reg:gamma),或者您可以使用均方对数误差,在这种情况下,您必须推导一阶和二阶导数。

您可以使用平均绝对误差(MAE)或者,您可以使用一个自定义包装器,它只包装
neg_mean_squared_log_error
,并将负值剪裁为0,然后再将其传递给记分器(如果有意义的话)。
ValueError: Mean Squared Logarithmic Error cannot be used when targets contain negative values.