2014-05-13 3 views
0

나는 Excel에서와 같이 간단한 선형 회귀 차트를 만들고 싶습니다. 가능한 한 최단 경로로.팬더 주식 회귀 차트

pandas .plot을 사용하여 회귀선이있는 주식 수익률 차트를 플로팅하는 가장 쉬운 방법은 무엇입니까?

답변

1

그것이 있어야하지 statsmodels

import statsmodels.api as sm 
mod = sm.OLS.from_formula('y ~ x', data=df) # y and x are column names in the DataFrame 
res = mod.fit() 
fig, ax = plt.subplots() 
sm.graphics.abline_plot(model_results=res, ax=ax) 
df.plot(kind='scatter', x='x', y='y', ax=ax) 
+1

꽤 간단 할 것'model_results = res' (안'model_results = mod') 귀하의'sm.graphics.abline_plot()에서'전화? –

+0

그래, 나는 그것을 고쳤다 고 생각했다. 감사! – TomAugspurger

+0

오류가 발생하고 다음과 같이 표시됩니다. raise ValueError ('% s'% 종류의 잘못된 차트 유형이 지정되었습니다.) ValueError : 잘못된 차트 유형이 분산되어 있습니다. –

관련 문제