Python 逻辑回归中已超过最大迭代次数

Python 逻辑回归中已超过最大迭代次数,python,statistics,logistic-regression,Python,Statistics,Logistic Regression,我正在运行数据文件load_breast_cancer(),以将肿瘤分类。 运行statsmodels检查每个变量的p值后,出现错误: Warning: Maximum number of iterations has been exceeded. Current function value: inf Iterations: 35 LinAlgError: Singular matrix 希望你能帮助我! 非常感谢。 我在stackoverflow上尝

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

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

LinAlgError: Singular matrix
希望你能帮助我! 非常感谢。 我在stackoverflow上尝试了一些解决这个问题的方法,但它不起作用

这是我的代码:

从sklearn.datasets导入加载\u乳腺癌
df=乳腺癌的负荷()
df_cancer=pd.DataFrame(np.c_[df['data'],df['target'],columns=np.append(df['feature_names'],['target']))
将statsmodels.api作为sm导入
将scipy.stats导入为st
从statsmodels.tools导入add_常量作为add_常量
df_常数=加法_常数(df_)
df_常数头()
st.chisqprob=lambda chisq,df_癌症:st.chi2.sf(chisq,df_癌症)
cols=df_常量。列[:-1]
model=sm.Logit(df_cancer['target'],df_常量[cols])
结果=model.fit()

预期值为结果将显示Logit回归结果

只需通过这一行

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

你好,请提供df_常量样本数据,我已经添加了!希望你能帮忙。非常感谢。但有一个警告