id date load Instant DayType Month Day sort
0 2013-02-02 4667.341595 46 6 2 2 4667.341595
1 2013-02-02 4620.702889 47 6 2 2 4620.702889
2 2013-05-12 -4439.333624 3 0 5 12 4439.333624
3 2013-05-12 -4409.947044 4 0 5 12 4409.947044
4 2013-05-12 -4369.322473 5 0 5 12 4369.322473
Hi I have a function rmse:
def RMSE2(x):
return(np.sqrt(np.mean(x**2)))
Load is our x I want to plot the return of rmse for each instant for each day type is mean I want to have in x instant and in y the return of my function AND 7 different plot (a plot for each daytype).
Is that what you want ?
df.groupby('DayType')['load'].apply(lambda x:np.sqrt(np.mean(x**2)))
output :
DayType
0 4406.294544
6 4644.080789
Name: load, dtype: float64
columns = np.unique(final.DayType)
b = []
for i in columns:
daytype = final[final['DayType'] == i]
a = daytype[['load']].groupby(daytype['Instant']).apply(RMSE2)
b.append(a)
import matplotlib.pyplot as plt
plt.xticks(rotation=70)
fig_size = plt.rcParams["figure.figsize"]
fig_size[0] = 8
fig_size[1] = 8
for i in range(9):
x = range(48)
y = b[i]['load']
plt.plot(x,y)
plt.ylabel("Rmse")
plt.xlabel("Day")
plt.legend(range(9),loc="upper left", bbox_to_anchor=[0, 1],
ncol=2, shadow=True, title="Legend", fancybox=True)
plt.show()
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.