ConvergenceWarning: lbfgs失败收敛(status=1):STOP: 总迭代次数达到限制

9 浏览
0 Comments

ConvergenceWarning: lbfgs失败收敛(status=1):STOP: 总迭代次数达到限制

我有一个包含数值和分类数据的数据集,我想根据患者的医疗特征预测不良结果。我为数据集定义了一个预测流程,如下所示:

X = dataset.drop(columns=['target'])
y = dataset['target']
# 定义数值和分类转换器
numeric_transformer = Pipeline(steps=[
    ('knnImputer', KNNImputer(n_neighbors=2, weights="uniform")),
    ('scaler', StandardScaler())])
categorical_transformer = Pipeline(steps=[
    ('imputer', SimpleImputer(strategy='constant', fill_value='missing')),
    ('onehot', OneHotEncoder(handle_unknown='ignore'))])
# 将对象列分配给分类转换器,将其余列分配给数值转换器
preprocessor = ColumnTransformer(transformers=[
    ('num', numeric_transformer, selector(dtype_exclude="object")),
    ('cat', categorical_transformer, selector(dtype_include="object"))
])
# 将分类器追加到预处理流程中
# 现在我们有一个完整的预测流程
clf = Pipeline(steps=[('preprocessor', preprocessor),
                      ('classifier', LogisticRegression())])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
clf.fit(X_train, y_train)
print("模型得分: %.3f" % clf.score(X_test, y_test))

然而,运行此代码时,我收到以下警告信息:

ConvergenceWarning: lbfgs failed to converge (status=1):
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
Increase the number of iterations (max_iter) or scale the data as shown in:
    https://scikit-learn.org/stable/modules/preprocessing.html
Please also refer to the documentation for alternative solver options:
    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression
  extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)
    模型得分: 0.988

有人能解释一下这个警告是什么意思吗?我对机器学习还是新手,对于如何改进预测模型还有些迷茫。正如你可以从numeric_transformer中看到的,我通过标准化对数据进行了缩放。我也对模型得分为何如此高而感到困惑,不知道这是好事还是坏事。

0