定义分类器和参数
在这一步中,我们将定义在特征离散化过程中要使用的分类器和参数。我们将创建一个分类器列表,其中包括逻辑回归、线性支持向量机(SVM)、梯度提升分类器以及带有径向基函数核的 SVM。我们还将为每个分类器定义一组参数,以便在 GridSearchCV 算法中使用。
## (估计器,参数网格) 列表,其中参数网格用于 GridSearchCV
## 此示例中的参数空间限制在一个较窄的范围内,以减少运行时间。在实际应用中,
## 应该为算法使用更广泛的搜索空间。
classifiers = [
(
make_pipeline(StandardScaler(), LogisticRegression(random_state=0)),
{"logisticregression__C": np.logspace(-1, 1, 3)},
),
(
make_pipeline(StandardScaler(), LinearSVC(random_state=0, dual="auto")),
{"linearsvc__C": np.logspace(-1, 1, 3)},
),
(
make_pipeline(
StandardScaler(),
KBinsDiscretizer(encode="onehot"),
LogisticRegression(random_state=0),
),
{
"kbinsdiscretizer__n_bins": np.arange(5, 8),
"logisticregression__C": np.logspace(-1, 1, 3),
},
),
(
make_pipeline(
StandardScaler(),
KBinsDiscretizer(encode="onehot"),
LinearSVC(random_state=0, dual="auto"),
),
{
"kbinsdiscretizer__n_bins": np.arange(5, 8),
"linearsvc__C": np.logspace(-1, 1, 3),
},
),
(
make_pipeline(
StandardScaler(), GradientBoostingClassifier(n_estimators=5, random_state=0)
),
{"gradientboostingclassifier__learning_rate": np.logspace(-2, 0, 5)},
),
(
make_pipeline(StandardScaler(), SVC(random_state=0)),
{"svc__C": np.logspace(-1, 1, 3)},
),
]
names = [get_name(e).replace("StandardScaler + ", "") for e, _ in classifiers]