I am trying calculate a regression output using python library but I am unable to get the intercept value when I use the library:
import statsmodels.api as sm
It prints all the regression analysis except the intercept.
but when I use:
from pandas.stats.api import ols
My code for pandas:
Regression = ols(y= Sorted_Data3['net_realization_rate'],x = Sorted_Data3[['Cohort_2','Cohort_3']])
print Regression
I get the the intercept with a warning that this librabry will be deprecated in the future so I am trying to use Statsmodels.
the warning that I get while using pandas.stats.api:
Warning (from warnings module): File "C:\Python27\lib\idlelib\run.py", line 325 exec code in self.locals FutureWarning: The pandas.stats.ols module is deprecated and will be removed in a future version. We refer to external packages like statsmodels, see some examples here: http://statsmodels.sourceforge.net/stable/regression.html
My code for Statsmodels:
import pandas as pd
import numpy as np
from pandas.stats.api import ols
import statsmodels.api as sm
Data1 = pd.read_csv('C:\Shank\Regression.csv') #Importing CSV
print Data1
running some cleaning code
sm_model = sm.OLS(Sorted_Data3['net_realization_rate'],Sorted_Data3[['Cohort_2','Cohort_3']])
results = sm_model.fit()
print '\n'
print results.summary()
I even tried statsmodels.formula.api: as:
sm_model = sm.OLS(formula ="net_realization_rate ~ Cohort_2 + Cohort_3", data = Sorted_Data3)
results = sm_model.fit()
print '\n'
print result.params
print '\n'
print results.summary()
but I get the error:
TypeError: init() takes at least 2 arguments (1 given)
Final output: 1st is from pandas 2nd is from Stats.... I want the intercept vaule as the one from pandas from stats also:
ols
but didn't use it. try:sm_model = ols(...
– Higgledypiggledy