Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unscale data after predictions?

I have a dataset with 2 features (price & volume) & 1 predicted variable (price) and use LTSM model to predict next price based on the previous set of prices.

First I scale the dataset:

#Scale the data
scaler = MinMaxScaler(feature_range=(0,1))
scaled_data = scaler.fit_transform(dataset)

Finally I want to unscale it:

#Get the models predicted price values
predictions = model.predict(x_test)
predictions = scaler.inverse_transform(predictions)

But this doesn't work and I get this error:

ValueError: non-broadcastable output operand with shape (400,1) doesn't match the broadcast shape (400,2)
like image 935
Dmitry Isakov Avatar asked Nov 30 '25 03:11

Dmitry Isakov


1 Answers

What this error means is that: you have scaled two features i.e. price and volume of shape (400,2), however, at the time of unscaling you are giving only the predicted price in shape (400,1)

A simple solution is to use two separate scalers - one that will unscale the response variable i.e. price (and the associated input feature, again the price), and second one for the rest of the features.

like image 126
jdsurya Avatar answered Dec 02 '25 15:12

jdsurya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!