結合 SMOTE 的邏輯斯迴歸
在這個練習中,你要把前一題的邏輯斯迴歸(Logistic Regression)模型,與 SMOTE 重取樣方法結合。我們會示範如何用一個把重取樣方法和模型一次整合的 pipeline,有效率地完成這件事。首先,你需要先定義要使用的 pipeline。
本練習屬於課程
Fraud Detection in Python
練習說明
- 從
imblearn匯入Pipeline模組,這一步已經替你完成。 - 接著定義要放進 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)])