How to get regression interception using Statsmodels.api

I am trying to compute the regression output using the Python library, but I cannot get the interception value when I use the library:

import statsmodels.api as sm

He prints the entire regression analysis except interception.

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 an interception with a warning that this library will be deprecated in the future, so I am trying to use Statsmodels.

warning i get when using pandas.stats.api:

( ): "C:\Python27\lib\idlelib\run.py", 325 self.locals. FutureWarning: pandas.stats.ols ., , statsmodels, . : http://statsmodels.sourceforge.net/stable/regression.html

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

sm_model = sm.OLS(Sorted_Data3['net_realization_rate'],Sorted_Data3[['Cohort_2','Cohort_3']])
results = sm_model.fit()
print '\n'
print results.summary()

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()

:

TypeError: init() 2 (1 )

: 1- , 2- .... , : enter image description here

+6
2

, statsmodels add_constant, . IMHO, , R, .

:

import statsmodels.api as sm
endog = Sorted_Data3['net_realization_rate']
exog = sm.add_constant(Sorted_Data3[['Cohort_2','Cohort_3']])

# Fit and summarize OLS model
mod = sm.OLS(endog, exog)
results = mod.fit()
print results.summary()

, , True ( ) False prepend kwag in sm.add_constant


, , Numpy :

exog = np.concatenate((np.repeat(1, len(Sorted_Data3))[:, None], 
                       Sorted_Data3[['Cohort_2','Cohort_3']].values),
                       axis = 1)
+10

- :

df['intercept'] = 1

.

sm.OLS :

lm = sm.OLS(df['y_column'], df[['intercept', 'x_column']])
results = lm.fit()
results.summary()
0

Source: https://habr.com/ru/post/1650586/


All Articles