Last active
December 22, 2019 23:22
-
-
Save cordon-thiago/766c2d25a6e6d483ba20062a1d2b23bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment