Skip to content

Instantly share code, notes, and snippets.

@betterdatascience
Last active September 4, 2021 03:14
Show Gist options
  • Save betterdatascience/34171f83ddd9c8eba71e121c05b0a429 to your computer and use it in GitHub Desktop.
Save betterdatascience/34171f83ddd9c8eba71e121c05b0a429 to your computer and use it in GitHub Desktop.
007_smote
from imblearn.over_sampling import SMOTE
sm = SMOTE(random_state=42)
X_sm, y_sm = sm.fit_resample(X, y)
print(f'''Shape of X before SMOTE: {X.shape}
Shape of X after SMOTE: {X_sm.shape}''')
print('\nBalance of positive and negative classes (%):')
y_sm.value_counts(normalize=True) * 100
@erue
Copy link

erue commented Jul 29, 2021

line 11 didn't work.

Balance of positive and negative classes (%):

AttributeError Traceback (most recent call last)
in ()
1 print('\nBalance of positive and negative classes (%):')
----> 2 y_sm.value_counts(normalize=True) * 100

AttributeError: 'numpy.ndarray' object has no attribute 'value_counts'

@dearcharlyn
Copy link

line 11 didn't work.

Balance of positive and negative classes (%):

AttributeError Traceback (most recent call last)
in ()
1 print('\nBalance of positive and negative classes (%):')
----> 2 y_sm.value_counts(normalize=True) * 100

AttributeError: 'numpy.ndarray' object has no attribute 'value_counts'

Hi, you can use the following code.
print("After OverSampling, counts of label '1': {}".format(sum(y_sm==1)))
print("After OverSampling, counts of label '0': {}".format(sum(y_sm==0)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment