<jupyter_start><jupyter_text>Visualize an ensemble classifierThis example illustrates how to quickly visualize an :mod:`imbalanced_ensemble.ensemble` classifier withthe :mod:`imbalanced_ensemble.visualizer` module.This example uses:    - :class:`imbalanced_ensemble.ensemble.SelfPacedEnsembleClassifier`    - :class:`imbalanced_ensemble.visualizer.ImbalancedEnsembleVisualizer`<jupyter_code># Authors: <NAME> <<EMAIL>>
# License: MIT
print(__doc__)

# Import imbalanced_ensemble
import imbalanced_ensemble as imbens

# Import utilities
import sklearn
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split

RANDOM_STATE = 42

# sphinx_gallery_thumbnail_number = 2<jupyter_output><empty_output><jupyter_text>Prepare dataMake a toy 3-class imbalanced classification task.<jupyter_code># make dataset
X, y = make_classification(n_classes=3, class_sep=2,
    weights=[0.1, 0.3, 0.6], n_informative=3, n_redundant=1, flip_y=0,
    n_features=20, n_clusters_per_class=2, n_samples=2000, random_state=0)

# train valid split
X_train, X_valid, y_train, y_valid = train_test_split(
    X, y, test_size=0.5, stratify=y, random_state=RANDOM_STATE)<jupyter_output><empty_output><jupyter_text>Train an ensemble classifierTake ``SelfPacedEnsembleClassifier`` as example<jupyter_code># Initialize and train an SPE classifier
clf = imbens.ensemble.SelfPacedEnsembleClassifier(
    random_state=RANDOM_STATE
).fit(X_train, y_train)

# Store the fitted SelfPacedEnsembleClassifier
fitted_ensembles = {'SPE': clf}<jupyter_output><empty_output><jupyter_text>Fit an ImbalancedEnsembleVisualizer<jupyter_code># Initialize visualizer
visualizer = imbens.visualizer.ImbalancedEnsembleVisualizer(
    eval_datasets = {
        'training' : (X_train, y_train),
        'validation' : (X_valid, y_valid),
    },
)

# Fit visualizer
visualizer.fit(fitted_ensembles)<jupyter_output><empty_output><jupyter_text>Plot performance curve**performance w.r.t. number of base estimators**<jupyter_code>fig, axes = visualizer.performance_lineplot()<jupyter_output><empty_output><jupyter_text>Plot confusion matrix<jupyter_code>fig, axes = visualizer.confusion_matrix_heatmap(
    on_datasets=['validation'], # only on validation set
    sup_title=False,
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0954664341761116, 'fraction_numerical': 0.010897994768962511, 'mean_word_length': 7.895348837209302, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '220482', 'license': 'MIT', 'n_tokens_mistral': 832, 'n_tokens_neox': 789, 'n_words': 144, 'path': 'docs/source/auto_examples/basic/plot_basic_visualize.ipynb', 'repo_name': 'ZhiningLiu1998/imbalanced-ensemble', 'size': '2315'}