LoslegenKostenlos loslegen

Applying SMOTE

In this exercise, you're going to re-balance our data using the Synthetic Minority Over-sampling Technique (SMOTE). Unlike ROS, SMOTE does not create exact copies of observations, but creates new, synthetic, samples that are quite similar to the existing observations in the minority class. SMOTE is therefore slightly more sophisticated than just copying observations, so let's apply SMOTE to our credit card data. The dataset df is available and the packages you need for SMOTE are imported. In the following exercise, you'll visualize the result and compare it to the original data, such that you can see the effect of applying SMOTE very clearly.

Diese Übung ist Teil des Kurses

Fraud Detection in Python

Kurs anzeigen

Anleitung zur Übung

  • Use the prep_data function on df to create features X and labels y.
  • Define the resampling method as SMOTE of the regular kind, under the variable method.
  • Use .fit_resample() on the original X and y to obtain newly resampled data.
  • Plot the resampled data using the plot_data() function.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

from imblearn.over_sampling import SMOTE

# Run the prep_data function
X, y = ____(df)

# Define the resampling method
method = ____()

# Create the resampled feature set
X_resampled, y_resampled = method.____(____, ____)

# Plot the resampled data
plot_data(____, ____)
Code bearbeiten und ausführen