dipanjanS / practical-machine-learning-with-python

Master the essential skills needed to recognize and solve complex real-world problems with Machine Learning and Deep Learning by leveraging the highly popular Python Machine Learning Eco-system.
Apache License 2.0
2.28k stars 1.65k forks source link

CH 11 Sequence Modeling issue #5

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hello Dipanjan, I just want to congratulate you for your book. It is one of the best out there. Altough, I have a small issue:

on chapter 11 at Sequence Modeling when I call get_seq_train_test function I get an error on this line: scaled_stock_series = scaler.fit_transform(time_series)

saying : ValueError: Expected 2D array, got 1D array instead: array=[1115.099976 1115.099976 1115.099976 ... 2711.929932 2643.689941 2634.800049]. Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

Can you help me with this? Thanks

raghavbali commented 6 years ago

Hi @Noctem123 , Thank you for the feedback, we are glad the book is helpful.

Regarding the error, it is most probably due to difference in pandas/numpy version. You must be on a more latest version. The issue can be fixed by replacing the error line by the following :

time_series = np.array(time_series).reshape(-1,1)
scaled_stock_series = scaler.fit_transform(time_series)

Let us know if this fix solves the issue, meanwhile we will work towards updating the code /documentation as per feasibility.

ghost commented 6 years ago

It worked! Thank you guys, you are the best!

ghost commented 6 years ago

I got the same type of error a little further in the code of sequence modeling, to be exact on this line:

trainPredict = scaler.inverse_transform(trainPredict.reshape(trainPredict.shape[1]))

saying:

ValueError: Expected 2D array, got 1D array instead: array=[0.19647571 0.22339799 0.23686117 ... 0.22503245 0.22467923 0.22415847]. Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

Probably I will get it at the next line too:

testPredict = scaler.inverse_transform(testPredict.reshape(testPredict.shape[1]))

raghavbali commented 6 years ago

Hey @Noctem123 , Thanks for pointing out. As noted in the earlier comment, the fix would be similar and the error is coming up due to different pandas versions in place.

We would update the code/documentation to note the versions used to avoid confusion.

Closing this for now.