我这样做:
from scipy.stats import linregress
slope, intercept, r_value, p_value, std_err =linregress(df_diesel['DEXUSAL'],df_diesel['price'])
from matplotlib import pyplot as plt
%matplotlib inline
plt.title("linear regression on diesel price vs exchange")
plt.ylabel("price")
plt.xlabel("DEXUSAL")
line = [slope*xi + intercept for xi in df_diesel['DEXUSAL']]
plt.plot(df_diesel['DEXUSAL'],line,'r-', linewidth=3)
plt.scatter(df_diesel['DEXUSAL'], df_diesel['price'])
plt.gcf().autofmt_xdate()
plt.show()
数据框是这样的:
> DATE DEXUSAL Fuel price
1543795200000000000 0.736柴油1529
1543795200000000000 0.736柴油1599
1543795200000000000 0.736柴油1457
1543795200000000000 0.736柴油1559
1543795200000000000 0.736柴油1479
有图,但是没有回归线?
此外,当我这样做时:
x = 0.75
y = slope * (x) + intercept
y
结果也很奇怪。
如何解决这个问题?