简体   繁体   中英

sklearn MinMaxScaler inverse_transform “Found array with dim 3. Estimator expected <= 2” on Removing Keras LSTM block

I'm sorry for the ambiguity of the title, any suggestions to improve it will be gladly accepted.

I'm trying to understand an LSTM network that my lecturer wrote. He set us a few questions to help our understanding, one of which is to remove one of the LSTM blocks and see what effect it had on the outcome of the training.

The problem is that when I comment out the second block, after compiling the model, a line in which an inverse_transform scale of the output data is done no longer works, and it gives the error "Found array with dim 3. Estimator expected <= 2".

Can anyone help me understand why? The code is at this link: https://colab.research.google.com/drive/1FWku0TIk_9CRukUj7-v29qUYO29jxVEh?usp=sharing

I'm sorry that the comments etc. are not in English, but the model construction is done in the block after the text that describes the model ("Architettura del modello di RNN:") and the line that breaks is the last line in the block after the execution of the model.

I hope this is clear, for any more information please don't hesitate to ask!

this is because you are passing 3d sequences to minmaxscaler. it accepts 2d sequences. what you have to do is to transform your prediction in 2d and then return to 3d. this can be done in one line...

predicted_values = scaler.inverse_transform(predicted_values.reshape(-1,1)).reshape(predicted_values.shape)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM