Issue
How do I make a moving average of y_pred_org and plot it? I have tried this in the following way but receive an error AttributeError: 'list' object has no attribute 'rolling' I am sure this is something small but I am new to this.
# Visualize the prediction with rolling average
from matplotlib import pyplot as plt
plt.figure()
['y_pred_org'].rolling(window=50).mean().plot()
plt.plot(y_test_t_org)
plt.title('Prediction vs Real Stock Price')
plt.ylabel('Price')
plt.xlabel('Days')
plt.legend(['Prediction', 'Real'], loc='upper left')
#plt.show()
How should I adjust this for it to function properly? The following code will function properly .shift(whatever shift you need) can also be added if a phase shift is needed
# Visualize the prediction with rolling average
from matplotlib import pyplot as plt
plt.figure()
df = DataFrame(data = y_pred_org)
df.rolling(30, center=True).mean().plot()
plt.plot(y_test_t_org)
plt.title('Prediction vs Real Stock Price')
plt.ylabel('Price')
plt.xlabel('Days')
plt.legend(['Prediction', 'Real'], loc='upper left')
#plt.show()
Solution
If your data is in a pandas DataFrame you can use a built in rolling average.
df['Y_Predict'] = df.iloc[:,col].rolling(window=5).mean()
Answered By - KillerToilet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.