Scikit-learn - Convert Pipeline Forecast to Initial Value / Scale

I create the pipeline as follows (using the Keras Scikit-Learn API )

estimators = [] estimators.append(('standardize', StandardScaler())) estimators.append(('mlp', KerasRegressor(build_fn=baseline_model, nb_epoch=50, batch_size=5, verbose=0))) pipeline = Pipeline(estimators) 

and install it with

 pipeline.fit(trainX,trainY) 

If I predict using pipline.predict(testX) , I (believe) get standardized forecasts.

How can I predict on testX that predictedY is on the same scale as the actual (untouched) testY (i.e. NOT a standardized prediction, but instead of the actual values)? I see that there is an inverse_transform method for Pipeline , however, it seems to return only converted X

+5
source share
1 answer

That's right. The Scaler () standard in the pipeline displays only inputs (trainX) pipe.fit (trainX, trainY).

So, if you approach your model to get closer to training, and you also need to standardize it, you should display your training 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 displays its values ​​taking into account the standard deviation and the average value calculated in the standard standard (). fit ().

You can always fit your model without scaling Y, as you mentioned, but it can be dangerous depending on your data, as it can lead your model to redo. You should check this out;)

+4
source

Source: https://habr.com/ru/post/1263281/


All Articles