【问题标题】:Maximum number of iterations has been exceeded in Logistic RegressionLogistic 回归中已超过最大迭代次数
【发布时间】:2019-05-16 10:03:08
【问题描述】:

我正在运行数据文件 load_breast_cancer() 来对肿瘤进行分类。 运行statsmodels检查每个变量的p值后,出现错误:

Warning: Maximum number of iterations has been exceeded.
         Current function value: inf
         Iterations: 35 

LinAlgError: Singular matrix

希望你能帮助我! 谢谢! 我在stackoverflow上尝试了一些关于这个问题的解决方案,但它不起作用!

这是我的代码:

from sklearn.datasets import load_breast_cancer

df = load_breast_cancer()
df_cancer = pd.DataFrame(np.c_[df['data'], df['target']], columns = np.append(df['feature_names'], ['target']))


import statsmodels.api as sm
import scipy.stats as st
from statsmodels.tools import add_constant as add_constant
df_constant = add_constant(df_cancer)
df_constant.head()

st.chisqprob = lambda chisq, df_cancer: st.chi2.sf(chisq, df_cancer)
cols=df_constant.columns[:-1]

model=sm.Logit(df_cancer['target'],df_constant[cols])
result = model.fit()

预期值是显示 Logit 回归结果的结果!

【问题讨论】:

  • 您好,请提供 df_constant 样本数据
  • 嗨,我已经添加了!希望你能帮忙。谢谢!

标签: python statistics logistic-regression


【解决方案1】:

只需通过这些线

result = model.fit(method='bfgs')
print(result.summary())

【讨论】:

  • 但是有一个警告
猜你喜欢
  • 2019-09-25
  • 1970-01-01
  • 2019-03-13
  • 2019-07-04
  • 2013-12-25
  • 1970-01-01
  • 2016-11-15
  • 2020-09-26
  • 2012-11-11
相关资源
最近更新 更多