Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cordon-thiago/766c2d25a6e6d483ba20062a1d2b23bc to your computer and use it in GitHub Desktop.
Save cordon-thiago/766c2d25a6e6d483ba20062a1d2b23bc to your computer and use it in GitHub Desktop.
def oversampleSMOTE(X, y):
'''
Resample a dataset using SMOTE oversample
Input:
X = dataframe with x variables (explanatory variables)
y = dataframe with y variable (variable to predict)
Output:
df[0] = X dataframe resampled
df[1] = y dataframe resampled
'''
from imblearn.over_sampling import SMOTE
import pandas as pd
sm = SMOTE(random_state=123)
X_resampled, y_resampled = sm.fit_resample(X, y.ravel())
# Get column names
X_cols = X.columns.values
y_cols = [y.name]
return pd.DataFrame(X_resampled, columns=X_cols) , pd.DataFrame(y_resampled, columns=y_cols)
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment