Last active
September 4, 2021 03:14
-
-
Save betterdatascience/34171f83ddd9c8eba71e121c05b0a429 to your computer and use it in GitHub Desktop.
007_smote
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
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 |
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) * 100AttributeError: '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
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'