初学者使用Python循环

时间:2018-07-25 13:57:26

标签: python loops

我是编码和寻找在python中实现循环的简单方法的新手。这是我的代码示例!我需要定义从1到12的变量u,v,w等,以进行回归分析,因此为什么循环是理想的。谢谢!

import numpy as np
import pandas as pd
import statsmodels.formula.api as sm
dataset = pd.read_csv("MultipleRegression.csv")

x1 = np.append(arr = np.ones((4, 1)).astype(int), values = x1, axis = 1)
x_opt1 = x1[:, [0, 1, 2, 3, 4, 5, 6]]
regressor_OLS1 = sm.OLS(endog = y1, exog = x_opt1).fit()
regressor_OLS1.summary()
u1 = regressor_OLS1.params[1]
v1 = regressor_OLS1.params[2]
w1 = regressor_OLS1.params[3]
x1 = regressor_OLS1.params[4]
y1 = regressor_OLS1.params[5]
z1 = regressor_OLS1.params[6]

1 个答案:

答案 0 :(得分:1)

在Python中,您无需循环即可完成操作,只需解压缩参数即可:

u1,v1 ,w1 ,x1 ,y1 ,z1, *rest = regressor_OLS1.params