x = np.random.uniform(0,1,100)
y = 5 + 3 * x + np.random.normal(loc=0,scale=1,size=100)
b, m = polyfit(x, y, 1)
I am using least-squares linear regression to get the estimator b,m. How can I repeat above calculations by 10000 times and then store 10000 different values of b,m to a list?
You can use a dictionary:
vals = {}
for i in range(10**4):
x = np.random.uniform(0,1,100)
y = 5 + 3 * x + np.random.normal(loc=0,scale=1,size=100)
b, m = polyfit(x, y, 1)
vals[f'Regression {i+1}'] = (b, m)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.