0
以下に基づいて回帰直線をプロットしようとしています。このコードは機能します。ただし、散布図の右側に回帰直線をプロットします。回帰直線プロットPython
私の質問は、回帰直線を正しくプロットする方法です。このウェブサイトからプロットコードを借りました。
http://matthiaseisen.com/pp/patterns/p0170/
import numpy.linalg
import matplotlib.pyplot as plt
def regression_model():
L_1 = numpy.array([38.83, 37.8, 34.41, 30.95, 23.00, 31.75, 36.59, 41.15])
y_d = [1,2,3,4,5,6,7,8]
n=len(L_1)
B=numpy.array(y_d)
A=numpy.array(([[L_1[j], 1] for j in range(n)]))
X=numpy.linalg.lstsq(A,B)[0]
a=X[0]; b=X[1]
print ("Line is: y=",a,"x+",b)
r_9 = a * L_1[7] + 4.92
print ('Predicited value at period 9 is ' + str(r_9) + ' using regression')
fig, ax = plt.subplots()
fit = numpy.polyfit(y_d, L_1, deg=1)
ax.plot(L_1, fit[0] * L_1 + fit[1], color='red')
ax.scatter(y_d, L_1)
plt.show()
を私は、あなたが' x軸上のy_d'をしたいと思いますfit [1]、color = 'red') ' – user2314737