Get startedGet started for free

Logistic regression combined with SMOTE

In this exercise, you're going to take the Logistic Regression model from the previous exercise, and combine that with a SMOTE resampling method. We'll show you how to do that efficiently by using a pipeline that combines the resampling method with the model in one go. First, you need to define the pipeline that you're going to use.

This exercise is part of the course

Fraud Detection in Python

View Course

Exercise instructions

  • Import the Pipeline module from imblearn, this has been done for you.
  • Then define what you want to put into the pipeline, assign the SMOTE() method to resampling, and assign LogisticRegression() to the model.
  • Combine two steps in the Pipeline() function. You need to state you want to combine resampling with the model in the respective place in the argument. I show you how to do this.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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)])
Edit and Run Code