[英]Is the score from TransformedTargetRegressor of scikit-learn correct?
I made a short Jupyter notebook to go with my question regarding the TransformedTargetRegressor.我制作了一个简短的Jupyter 笔记本来回答我关于 TransformedTargetRegressor 的问题。
I wanted to put a transformer inside a pipeline to play with a parameter grid but the scores didn't match.我想在管道中放置一个变压器来使用参数网格,但分数不匹配。
...
model = linear_model.LinearRegression()
lg_tr = preprocessing.FunctionTransformer(func=np.log, inverse_func=np.exp, check_inverse=True)
y_log = lg_tr.transform(y)
score_0 = model.fit(X, y_log).score(X, y_log)
...
model = compose.TransformedTargetRegressor(func=np.log, inverse_func=np.exp, check_inverse=True,
regressor=linear_model.LinearRegression())
score_1 = model.fit(X, y).score(X, y)
The score_0
value is correct. score_0
值是正确的。 Why is the one from score_1
not?为什么不是来自
score_1
?
I don't have problem with the prediction that works fine, only the score.我对工作正常的预测没有问题,只有分数。
Did I miss something?我错过了什么?
Thank you =)谢谢你=)
Typically, you should be interested on how good your model performs (or scores) when predicting the actual values in their original range or scale.通常,在预测原始范围或尺度中的实际值时,您应该对模型的表现(或得分)感兴趣。 This is however what you are measuring with
score_1
and not with score_0
.但是,这是您使用
score_1
而不是score_0
测量的score_0
。
score_0
represents the model's performance when the target variable is in log scale which is in most cases not very useful. score_0
表示当目标变量处于对数刻度时模型的性能,这在大多数情况下不是很有用。
score_1
however uses the score
method of TransformedTargetRegressor
which makes sure the target variable is in its original scale before computing any performance metric.然而,
score_1
使用TransformedTargetRegressor
的score
方法,该方法在计算任何性能指标之前确保目标变量处于其原始规模。 Thus, judgements should be made based on score_1
.因此,应根据
score_1
进行判断。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.