curiousily / Getting-Things-Done-with-Pytorch

Jupyter Notebook tutorials on solving real-world problems with Machine Learning & Deep Learning using PyTorch. Topics: Face detection with Detectron 2, Time Series anomaly detection with LSTM Autoencoders, Object Detection with YOLO v5, Build your first Neural Network, Time Series forecasting for Coronavirus daily cases, Sentiment Analysis with BER
https://mlexpert.io
Apache License 2.0
2.36k stars 639 forks source link

How to handle imbalanced classes ? #3

Open smi45 opened 4 years ago

smi45 commented 4 years ago

Hi, I have a use case wherein there are two classes and are hugely imbalanced. How can i fix this issue.

I have used the source code.

Sentiment Analysis with BERT

ashfarhangi commented 3 years ago

You can use my code and replace the cat1 and cat2 for your imbalance classes from sklearn.utils import resample cat_1= df[df.school_handle == 'ourmedschool'] cat_2= df[df.school_handle == 'ucfcah']

cat_large = df[df.school_handle == 'UCFCECS'] cat_1 = resample(cat_1, replace=True, n_samples=len(cat_large), random_state=RANDOM_SEED) cat_2 = resample(cat_2, replace=True, n_samples=len(cat_large), random_state=RANDOM_SEED)

df1 = pd.merge(cat_1,cat_large,how='outer') df1 = pd.merge(df1,cat_2,how='outer') df1 sns.countplot(df1.school_handle) plt.xlabel('College')