#plotting values
x_max = np.max(X) + 100
x_min = np.min(X) - 100#calculating line values of x and y
x = np.linspace(x_min,x_max,1000)
y = b0 + b1 * x #plotting line
plt.plot(x,y,color='#00ff00',label='Linear Regression')#plot the data point
plt.scatter(X,Y,color='#ff0000',label='Data Point')# x-axis label
plt.xlabel('Time')#y-axis label
plt.ylabel('Signal Strength MHz')
plt.legend()
plt.show()
我无法将多项式回归线拟合到数据中。
coefs = np.polyfit(X,4)
x_new = np.linspace(X[0],X[-1],num=len(X)*10)
ffit = poly.polyval(x_new,coefs)
plt.plot(x_new,ffit,label = 'Polynomial Regression')
plt.scatter(X,label='Data Point')# x-axis label
plt.xlabel('Time')#y-axis label
plt.ylabel('Signal Strength MHz')
plt.show()