내 코드는 2 세트의 데이터에 대해 선형 회귀를 수행합니다. 그것은 잘 작동하지만 scipy 또는 numpy 함께 그래프 자체에 선 방정식을 인쇄 할 수있는 방법을 모르겠습니다.scipy 통계를 사용하여 행 방정식을 인쇄하는 방법
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