将 Logistic Regression 与 SMOTE 结合
在本练习中,您将把上一个练习中的 Logistic Regression 模型与一个 SMOTE 重采样方法 结合使用。我们将向您展示如何通过使用一个流水线(pipeline),把重采样方法与模型一次性组合起来,以高效完成这一过程。首先,您需要定义要使用的流水线。
本练习是课程的一部分
Python 中的欺诈检测
练习说明
- 从
imblearn导入Pipeline模块,这一步已经为您完成。 - 然后定义要放入流水线的内容,将
SMOTE()方法赋给resampling,并将LogisticRegression()赋给model。 - 在
Pipeline()函数中组合两个步骤。您需要在参数的相应位置声明要将resampling与model组合在一起。下面示范如何完成。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# This is the pipeline module we need for this from imblearn
from imblearn.pipeline import Pipeline
# Define which resampling method and which ML model to use in the pipeline
resampling = ____
model = ____
# Define the pipeline, tell it to combine SMOTE with the Logistic Regression model
pipeline = Pipeline([('SMOTE', resampling), ('Logistic Regression', model)])