Issue
I have the following code,
train = data[:training_data_len]
valid = data[training_data_len:]
valid ['Prediction'] = predictions
plt.figure(figsize = (16,8))
plt.title('Model')
plt.xlabel('Date', fontsize=18)
plt.ylabel('Close Price USD ($)', fontsize=18)
plt.plot(train['Close'])
plt.plot(valid[['Close', 'Predictions']])
plt.legend(['Train','Val', 'Predictions'], loc= 'lower right')
plt.show()
I'll get the following error:
KeyError: "['Predictions'] not in index"
It seems to have a very easy fix, but I'm just too new to Python to know how to fix it.
Solution
This question is a little vague so if you could tell us which line is throwing the error you might get better responses. But based on what you wrote here, I noticed that you named the field in the valid
dataframe 'Prediction' (singular) and later in the code you start referring to 'Predictions' (plural). Maybe that's your problem.
Answered By - Fiona De La Fuente
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.