파이썬 질문 드려요!
조회수 494회
안녕하세요. rolling regression 이라는 것을 파이썬으로 하고 있는데,a,b,c, r2의 숫자가 변하지 않습니다. 뭐가 잘못된 걸까요?
import matplotlib.pyplot as plt
import statsmodels.api as sm
import statsmodels.formula.api as sm1
start = 0
end = 60
timeseries = {"period":[],
"A": [],
"B":[],
"C":[],
"R2":[]}
while end <= len(d):
df = d.iloc[start:end]
period = str(df.index[0].to_timestamp().to_period('M')) + " to " + str(df.index[-1].to_timestamp().to_period('M'))
model= sm1.ols(formula = 'Q("KS11") ~ Q("000001.SS") +Q("GSPC") ',data= d).fit()
model_result = model.summary()
x = df['000001.SS','GSPC']
y = df['KS11']
x = sm.add_constant(x)
model = sm.OLS(y,x).fit()
model_result = model.summary()
timeseries["period"].append(period)
timeseries["R2"].append(model.rsquared)
results_as_html = model_result.tables[1].as_html()
timeseries["A"].append(pd.read_html(results_as_html, header=0, index_col=0)[0]["coef"][0])
timeseries["B"].append(pd.read_html(results_as_html, header=0, index_col=0)[0]["coef"][1])
timeseries["C"].append(pd.read_html(results_as_html, header=0, index_col=0)[0]["coef"][2])
start+=1
end+=1
timeseries_result = pd.DataFrame.from_dict(timeseries)
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력