我想像下面这样在 sklearn 中进行交叉验证,但是仍然需要对 X 的预测结果进行转换以减少与 y 的距离。如何通过添加自定义功能来做到这一点?
model = XGBRegressor(n_estimator = 500,
learn_rate = 0.05,
random_state = 0)
pipeline = Pipeline( steps = [('preprocessor', preprocessor),
('model', model)
])
scores = -1 * cross_val_score(pipeline, X, y,
cv = 3,
scoring = 'neg_mean_absolute_error',
verbose = 0)
y 中只有 0 和 1,所以我想在 X 的预测步骤之后对 X 的结果进行四舍五入并去掉小数。
将来我可能需要对 y 进行其他操作。例如,拟合正确的结果只包括像 0.5、1.5、2.5 ...
例子:
X - 输入
ID Column_1 Column_2 Column_3
0 'A' 10 True
1 'A' 20 False
2 'B' 30 True
y - 正确的结果
ID Result
0 1
1 0
2 1
当前输出
ID Result
0 0.899
1 -0.001
2 1.102
预期输出
ID Result
0 1
1 0
2 1
我已经在 Stack Overflow 上发布了这个问题,但也没有得到任何答案。