SMOTE Using Python1
SMOTE Using Python1
8$(')$' 9%/),/+6/%4
!"#$%&'()*+&,-./0*
!"#$%&$'()"*+,,)-+*+'"%).$/#)0%.)*$'%,)10)23/#1')"14%,
https://towardsdatascience.com/applying-smote-for-class-imbalance-with-just-a-few-lines-of-code-python-cdf603e58688 Page 1 of 9
SMOTE using Python. Achieving class balance with few lines… | by Dr. Saptarsi Goswami | Towards Data Science 28/5/21, 11:23 PM
#//2,GHHF',2*+,#7"1:H2#1/1,HI@%JKD@L@MN
https://towardsdatascience.com/applying-smote-for-class-imbalance-with-just-a-few-lines-of-code-python-cdf603e58688 Page 2 of 9
SMOTE using Python. Achieving class balance with few lines… | by Dr. Saptarsi Goswami | Towards Data Science 28/5/21, 11:23 PM
#//2,GHHF',2*+,#7"1:H2#1/1,H@OPQRI>(,I.
https://towardsdatascience.com/applying-smote-for-class-imbalance-with-just-a-few-lines-of-code-python-cdf603e58688 Page 3 of 9
SMOTE using Python. Achieving class balance with few lines… | by Dr. Saptarsi Goswami | Towards Data Science 28/5/21, 11:23 PM
K1'0F,$1')O+/6$S).$/#)"1*16,)+""164$'()/1)/#%)4%,$6+-$*$/3
K*+,,)$:-+*+'"%)8/6+/%(3)T)81F6"%G)!F/#16U
https://towardsdatascience.com/applying-smote-for-class-imbalance-with-just-a-few-lines-of-code-python-cdf603e58688 Page 4 of 9
SMOTE using Python. Achieving class balance with few lines… | by Dr. Saptarsi Goswami | Towards Data Science 28/5/21, 11:23 PM
Of course, the best thing is to have more data, but that’s too
ideal. Among the sampling-based and sampling-based
strategies, SMOTE comes under the generate synthetic sample
strategy.
V$,F+*$M$'()/#%)5+/+)T)W:+(%)81F6"%G)!F/#16U
https://towardsdatascience.com/applying-smote-for-class-imbalance-with-just-a-few-lines-of-code-python-cdf603e58688 Page 5 of 9
SMOTE using Python. Achieving class balance with few lines… | by Dr. Saptarsi Goswami | Towards Data Science 28/5/21, 11:23 PM
It can be understood the red class is the majority class and the
blue class is the minority class.
!"#$%&'(&")*$+,)-&.*
!,,/)D610)Y)K1:2)8"
Z+'(+-+,$)O16'$'()K*([)\%+4
]%,%+6"#%6)^'$&%6,$/3)10
K+*"F//+)5+/+)8"$%'"%)\+-[
B&+*F+/$1')1')X%,/)8%/):14%*)/6+$'%4)1')16$($'+*)$:-+*+'"%4)4+/+)TW:+(%)81F6"%G)!F/#16U
8>58)%S%"F/$&%)"1::$//%%
:%:-%6[)_58K)A1*E+/+
K#+2/%6)\%+4
The main issue over here we have a very poor recall rate for the
;1**1.
minority class when the original imbalanced data is used for
training the model.
>< <
Step 3: Create a dataset with Synthetic samples
https://towardsdatascience.com/applying-smote-for-class-imbalance-with-just-a-few-lines-of-code-python-cdf603e58688 Page 6 of 9
SMOTE using Python. Achieving class balance with few lines… | by Dr. Saptarsi Goswami | Towards Data Science 28/5/21, 11:23 PM
B&+*F+/$1')1')X%,/)8%/):14%*)/6+$'%4)1'):14$0$%4)-+*+'"%4)4+/+)TW:+(%)81F6"%G)!F/#16U
We can see directly, the recall has improved from .21 to .84.
Such is the power and beauty of the three lines code.
EndNote:
https://towardsdatascience.com/applying-smote-for-class-imbalance-with-just-a-few-lines-of-code-python-cdf603e58688 Page 7 of 9
SMOTE using Python. Achieving class balance with few lines… | by Dr. Saptarsi Goswami | Towards Data Science 28/5/21, 11:23 PM
In this article, we have outlined how with few lines of code, can
work like a miracle.
References:
[1] https://www.kaggle.com/saptarsi/smote-notebook
[2] https://machinelearningmastery.com/tactics-to-combat-
imbalanced-classes-in-your-machine-learning-dataset/
[3]https://www.kaggle.com/qianchao/smote-with-imbalance-
data
https://towardsdatascience.com/applying-smote-for-class-imbalance-with-just-a-few-lines-of-code-python-cdf603e58688 Page 8 of 9
SMOTE using Python. Achieving class balance with few lines… | by Dr. Saptarsi Goswami | Towards Data Science 28/5/21, 11:23 PM
%*/0$1'$2,"$345$6&"*&785
Z3)X1.+64,)5+/+)8"$%'"%
B&%63)X#F6,4+3[)/#%)V+6$+-*%)4%*$&%6,)/#%)&%63)-%,/)10)X1.+64,)5+/+
8"$%'"%G)061:)#+'4,I1')/F/16$+*,)+'4)"F//$'(I%4(%)6%,%+6"#)/1)16$($'+*
0%+/F6%,)31F)41'C/).+'/)/1):$,,7)X+E%)+)*11E7
9%/)/#$,)'%.,*%//%6
N1FC**)'%%4)/1),$(')$')16)"6%+/%)+')+""1F'/)/1)6%"%$&%)/#$,
'%.,*%//%67
5+/+)8"$%'"%
https://towardsdatascience.com/applying-smote-for-class-imbalance-with-just-a-few-lines-of-code-python-cdf603e58688 Page 9 of 9