相关疑难解决方法(0)

ConvergenceWarning: lbfgs 未能收敛 (status=1): STOP: TOTAL NO. 达到限制的迭代次数

我有一个由数字和分类数据组成的数据集,我想根据患者的医疗特征预测其不良结果。我为我的数据集定义了一个预测管道,如下所示:

X = dataset.drop(columns=['target'])
y = dataset['target']

# define categorical and numeric transformers
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'))])

#  dispatch object columns to the categorical_transformer and remaining columns to numerical_transformer
preprocessor = ColumnTransformer(transformers=[
    ('num', numeric_transformer, selector(dtype_exclude="object")),
    ('cat', categorical_transformer, selector(dtype_include="object"))
])

# Append classifier to preprocessing pipeline.
# Now we have a full prediction pipeline.
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, …
Run Code Online (Sandbox Code Playgroud)

python machine-learning scikit-learn logistic-regression

43
推荐指数
3
解决办法
7万
查看次数