物流模型摘要

时间:2020-06-26 18:51:34

标签: pandas statsmodels scipy.stats

此函数产生错误 我的代码:

import numpy as np
import pandas as pd
import statsmodels.api as sm
df = pd.read_csv('./fraud_dataset.csv')

df[['weekday','weekend']]= pd.get_dummies(df['day'])
df.drop(['weekend'],axis=1,inplace=True)


df[['notfraud','fraud']]= pd.get_dummies(df['fraud'])                                
df.drop(['notfraud'],axis=1,inplace=True)
df['intercept'] = 1


log_mod = sm.Logit(df['fraud'], df[['intercept', 'weekday', 'duration']])
results = log_mod.fit()
results.summary()

它给出了这个错误,我不明白为什么?

/opt/conda/lib/python3.6/site-packages/statsmodels/discrete/discrete_model.py in summary(self, yname, 
xname, title, alpha, yname_list)
2756                 yname_list=None):
2757         smry = super(BinaryResults, self).summary(yname, xname, title, alpha,
-> 2758                      yname_list)
2759         fittedvalues = self.model.cdf(self.fittedvalues)
2760         absprederror = np.abs(self.model.endog - fittedvalues)

/opt/conda/lib/python3.6/site-packages/statsmodels/discrete/discrete_model.py in summary(self, yname, 
xname, title, alpha, yname_list)
2548                      ('Log-Likelihood:', None),
2549                      ('LL-Null:', ["%#8.5g" % self.llnull]),
-> 2550                      ('LLR p-value:', ["%#6.4g" % self.llr_pvalue])
2551                      ]
2552 

/opt/conda/lib/python3.6/site-packages/statsmodels/tools/decorators.py in __get__(self, obj, type)
 95         if _cachedval is None:
 96             # Call the "fget" function
 ---> 97             _cachedval = self.fget(obj)
 98             # Set the attribute in obj
 99             # print("Setting %s in cache to %s" % (name, _cachedval))

/opt/conda/lib/python3.6/site-packages/statsmodels/discrete/discrete_model.py in llr_pvalue(self)
2403     @cache_readonly
2404     def llr_pvalue(self):
-> 2405         return stats.chisqprob(self.llr, self.df_model)
2406 
2407     @cache_readonly

AttributeError: module 'scipy.stats' has no attribute 'chisqprob'

我认为statsmodels中有某种更新,我确实找不到解决此问题的方法,尽管我发现一些帖子是针对相同错误但原因不同的。非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我在 Google 中查看了您的错误消息,并找到了建议 改为致电results.summary2()