我的代碼對2組數據執行線性迴歸。它工作正常,但我不知道我怎麼可以打印圖形本身的線條方程式與scipy或numpy。如何使用scipy stats打印行方程
這裏是我的代碼:
y=np.array([15,1489,859,336,277,265,229,285,391,372,5,345])
x=np.array([196.16,17762.47,28542.19,30170.5,9384.06,.29,21819.2,16978.2,45767.54,12328.78,113.71,19257.6])
print x
print y
slope, intercept, r_value, p_value, slope_std_error = stats.linregress(x, y)
print "slope = "+ str(slope)
print "r_value = "+ str(r_value)
print "r_squared = " + str(r_value**2)
print "p_value = "+str(p_value)
# Calculate some additional outputs
predict_y = intercept + slope * x
print predict_y
pred_error = y - predict_y
degrees_of_freedom = len(x) - 2
residual_std_error = np.sqrt(np.sum(pred_error**2)/degrees_of_freedom)
# Plotting
pylab.xlabel('cost')
pylab.ylabel('signups')
pylab.plot(x, y, 'o')
pylab.plot(x, predict_y, 'k-')
pylab.show()
$ y或%3.7s是什麼意思? – jxn
@jenn,'$'告訴'matplotlib'繪製'mathtext'。 http://matplotlib.org/users/mathtext.html。 '%'是字符串格式化的一種方法,請參閱https://docs.python.org/2/library/stdtypes.html,第5.6.2節。 –
我怎麼寫一個指數方程? – FaCoffee