Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python StatsModels中的Logit回归_Python_Logistic Regression_Statsmodels_Predict - Fatal编程技术网

Python StatsModels中的Logit回归

Python StatsModels中的Logit回归,python,logistic-regression,statsmodels,predict,Python,Logistic Regression,Statsmodels,Predict,我试图用一个自变量进行逻辑回归,将模型与数据拟合,然后用随机样本外输入返回概率输出 In [153]: df[['Diff1', 'Win']] Out[153]: Diff1 Win 0 100 1 1 110 1 2 20 0 3 80 1 4 200 1 5 25 0 In [154]: logit = sm.Logit(df['Win'], df['Diff1']) In [155]: res

我试图用一个自变量进行逻辑回归,将模型与数据拟合,然后用随机样本外输入返回概率输出

In [153]: df[['Diff1', 'Win']]
Out[153]: 
   Diff1  Win
0    100    1
1    110    1
2     20    0  
3     80    1
4    200    1
5     25    0

In [154]: logit = sm.Logit(df['Win'], df['Diff1'])

In [155]: result=logit.fit()
Optimization terminated successfully.
         Current function value: 0.451400
         Iterations 6

                            Logit Regression Results                           
==============================================================================
Dep. Variable:                    Win   No. Observations:                    8
Model:                          Logit   Df Residuals:                        7
Method:                           MLE   Df Model:                            0
Date:                Fri, 11 Dec 2015   Pseudo R-squ.:                  0.3177
Time:                        13:49:07   Log-Likelihood:                -3.6112
converged:                       True   LL-Null:                       -5.2925
                                        LLR p-value:                       nan
==============================================================================
                 coef    std err          z      P>|z|      [95.0% Conf. Int.]
------------------------------------------------------------------------------
Diff1          0.0207      0.014      1.435      0.151        -0.008     0.049
==============================================================================

In [158]: result.predict(0)
Out[158]: array([ 0.5])
很明显,我使用的预测函数不正确,因为在这种情况下输入0不应该产生0.5。该结果适用于逻辑模型的非拟合示例


我将使用简单的OLS回归,但希望我的模型以(0,1)为界

解释变量中没有常数。如果线性预测为零,则逻辑函数(即预测)映射为0.5概率。所以这是正确的。