1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import os import matplotlib.pyplot as plt import numpy as np os.chdir('/home/vg/Downloads/projects/ex9') os.getcwd() plt.figure(figsize=(10,8)) N = 100 start = 0 end = 1 A = np.random.rand() + 1 B = np.random.rand() x = np.linspace(start,end,N) y = A * x + B y = y + np.random.randn(N)/10 p = np.polyfit(x,y,1) plt.plot(x,y,'o',label='Given data: A=%.2f. B=%.2f' % (A,B)) plt.plot(x,np.polyval(p,x),'-',label='Linear regression: A=%.2f. B=%.2f' % tuple(p) ) plt.legend(loc='best') plt.grid() plt.title('Linear regression') plt.savefig("example9.png", dpi=100) plt.show() plt.close() <img class=" wp-image-66 aligncenter" src="https://gantovnik.com/bio-tips/wp-content/uploads/2018/12/example9.png" alt="example9" width="610" height="488" /> |
Recent Comments