不知道为什么,但我得到了" 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()