How to get the regression intercept using Statsmodels.api
<p>I am trying calculate a regression output using python library but I am unable to get the intercept value when I use the library:</p>
<pre><code>import statsmodels.api as sm
</code></pre>
<p>It prints all the regression analysis except the intercept.</p>
<p>but when I use:</p>
<pre><code>from pandas.stats.api import ols
</code></pre>
<p>My code for pandas:</p>
<pre><code>Regression = ols(y= Sorted_Data3['net_realization_rate'],x = Sorted_Data3[['Cohort_2','Cohort_3']])
print Regression  
</code></pre>
<p>I get the the intercept with a warning that this librabry will be deprecated in the future so I am trying to use Statsmodels.</p>
<p>the warning that I get while using pandas.stats.api:</p>
<blockquote>
<p>Warning (from warnings module):
File &quot;C:\Python27\lib\idlelib\run.py&quot;, 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: <a href="http://statsmodels.sourceforge.net/stable/regression.html" rel="nofollow noreferrer">http://statsmodels.sourceforge.net/stable/regression.html</a></p>
</blockquote>
<p>My code for Statsmodels:</p>
<pre><code>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
</code></pre>
<p>running some cleaning code</p>
<pre><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()
</code></pre>
<p>I even tried statsmodels.formula.api:
as:</p>
<pre><code>sm_model = sm.OLS(formula =&quot;net_realization_rate ~ Cohort_2 + Cohort_3&quot;, data = Sorted_Data3)
results = sm_model.fit()
print '\n'
print result.params
print '\n'
print results.summary()
</code></pre>
<p>but I get the error:</p>
<blockquote>
<p>TypeError: <strong>init</strong>() takes at least 2 arguments (1 given)</p>
</blockquote>
<p>Final output:
1st is from pandas 2nd is from Stats.... I want the intercept vaule as the one from pandas from stats also:
<a href="https://i.stack.imgur.com/LpFIj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LpFIj.png" alt="enter image description here" /></a></p>