I have traffic dataset (number of accidents) that is obviously seasonal (weekly). When i try to use plotly trendline (OLS) using:
fig = px.scatter(df, x='Open date', y='Total Cases', trendline="ols", trendline_scope="overall")
fig.show()
I get this jagged line which returns non-sensical results in the summary plot (near 1 x1 coefficients)
This does not happen using plotly's example or switching to the 'lowess' method. Am i missing some smoothing parameter? or OLS assumptions? If i do:
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy as np
x = mdates.date2num(daily['Open date'])
y= daily['Total Cases']
z = np.polyfit(x, daily['Total Cases'], 1)
p = np.poly1d(z)
#then the plot
daily.plot('Open date', 'Total Cases')
plt.plot(x, p(x), "r--")
I get a perfectly logical trendline.
Any help appreciated. Thanks!
Data for reproduction first 30 days, index instead of datetime. (df['Total cases'].head(30):
{1: 580, 2: 585, 3: 1474, 4: 1100, 5: 966, 6: 986, 7: 1068, 8: 655, 9: 563, 10: 1130, 11: 956, 12: 863, 13: 840, 14: 809, 15: 657, 16: 470, 17: 1039, 18: 778, 19: 764, 20: 841, 21: 829, 22: 604, 23: 475, 24: 1041, 25: 785, 26: 690, 27: 711, 28: 823, 29: 616, 30: 462}

