Section I: Brief Introduction on Upsampling/Downsampling
Class imbalance is a quite common problem when working with real-world data-samples from one class or multiple classes are over-represented in a dataset. Intuitively, we can think of several domains where this may occur, such as spam filtering, fraud detection, or screening for diseases.
Here, be warned that one way to deal with imbalanced class proportions during model fitting is a assign a larger penalty to wrong predictions on the minority class . Via scikit-learn, adjusting such a penalty is as convenient as setting the class_weight parameter to class_weight=“balanced”, which is implemented for most classifiers.
FROM
Sebastian Raschka, Vahid Mirjalili. Python机器学习第二版. 南京:东南大学出版社,2018.
Section II: Code and Analyses
第一部分:代码
from sklearn import datasets
from sklearn.model_selection import train_test_split
import numpy as np
from sklearn.utils import resample
import warnings
warnings.filterwarnings("ignore")
#Section 1: Load Breast data, i.e., Benign and Mal