開始使用免費開始

結合 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)])
編輯並執行程式碼