January 2020
Beginner to intermediate
432 pages
11h 24m
English
Execute the following steps to investigate different approaches to handling class imbalance.
import pandas as pdimport seaborn as snsfrom imblearn.over_sampling import RandomOverSampler, SMOTE, ADASYNfrom imblearn.under_sampling import RandomUnderSamplerfrom sklearn.model_selection import train_test_splitfrom sklearn.ensemble import RandomForestClassifierfrom collections import Counterfrom chapter_9_utils import performance_evaluation_report
df = pd.read_csv('credit_card_fraud.csv')X = df.copy()y = X.pop('Class')RANDOM_STATE = 42X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, stratify=y)
rf = RandomForestClassifier(random_state=RANDOM_STATE) ...
Read now
Unlock full access