scikit-learn - Convert pipeline prediction to original value/scale

江枫思渺然 提交于 2019-12-05 11:31:23

Exactly. The StandardScaler() in a pipeline is only mapping the inputs (trainX) of pipeline.fit(trainX,trainY).

So, if you fit your model to approximate trainY and you need it to be standardized as well, you should map your trainY as

scalerY = StandardScaler().fit(trainY)  # fit y scaler
pipeline.fit(trainX, scalerY.transform(trainY))  # fit your pipeline to scaled Y
testY = scalerY.inverse_transform(pipeline.predict(testX))  # predict and rescale

The inverse_transform() function maps its values considering the standard deviation and mean calculated in StandardScaler().fit().

You can always fit your model without scaling Y, as you mentioned, but this can be dangerous depending on your data since it can lead your model to overfit. You have to test it ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!