statsmodels中的Logistic回归" LinAlgError:奇异矩阵"

时间:2018-04-21 09:41:58

标签: python statsmodels

不知道为什么,但我得到了" numpy.linalg.linalg.LinAlgError:奇异矩阵"拟合逻辑回归模型时出错。

from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
import statsmodels.api as sm

data = load_breast_cancer()
y = data.target
X = data.data

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, stratify=y, random_state=2)

X_train = sm.add_constant(X_train)
X_test = sm.add_constant(X_test)
model = sm.Logit(y_train, X_train)
fit = model.fit() # error appears on this line

fit.summary2()

0 个答案:

没有答案