August 2019
Intermediate to advanced
342 pages
9h 35m
English
The following examples are taken from the official Python library imbalanced-learn documentation, which implements undersampling and oversampling algorithms, among others.
Let's look at an example of the undersampling technique by using the RandomUnderSampler class:
# From the Imbalanced-Learn library documentation:# https://imbalanced-learn.readthedocs.io/en/stable/generated/imblearn.under_sampling.RandomUnderSampler.htmlfrom collections import Counterfrom sklearn.datasets import make_classificationfrom imblearn.under_sampling import RandomUnderSampler X, y = make_classification(n_classes=2, class_sep=2, weights=[0.1, 0.9], n_informative=3, n_redundant=1, flip_y=0,n_features=20, n_clusters_per_class=1, n_samples=1000, random_state=10) ...
Read now
Unlock full access