Implementation:Scikit learn contrib Imbalanced learn classification report imbalanced
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Machine_Learning, Model_Evaluation, Imbalanced_Learning |
| Last Updated | 2026-02-09 03:00 GMT |
Overview
Concrete tool for generating a comprehensive imbalanced classification report provided by the imbalanced-learn library.
Description
The classification_report_imbalanced function generates a text or dict report with per-class precision, recall, specificity, f1, geometric mean, IBA, and support. Supports custom target names, label subsets, and dict output mode.
Usage
Import this function as a replacement for sklearn's classification_report when working with imbalanced datasets.
Code Reference
Source Location
- Repository: imbalanced-learn
- File: imblearn/metrics/_classification.py
- Lines: L865-1143
Signature
def classification_report_imbalanced(
y_true,
y_pred,
*,
labels=None,
target_names=None,
sample_weight=None,
digits=2,
alpha=0.1,
output_dict=False,
zero_division="warn",
):
"""
Args:
y_true: array-like - Ground truth labels.
y_pred: array-like - Predicted labels.
labels: array-like or None - Label indices to include.
target_names: list of str or None - Display names for labels.
sample_weight: array-like or None - Sample weights.
digits: int - Decimal precision (default: 2).
alpha: float - IBA alpha parameter (default: 0.1).
output_dict: bool - Return dict instead of string (default: False).
zero_division: 'warn' or 0 or 1 - Zero division behavior.
Returns:
str or dict - Formatted classification report.
"""
Import
from imblearn.metrics import classification_report_imbalanced
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| y_true | array-like of shape (n_samples,) | Yes | Ground truth labels |
| y_pred | array-like of shape (n_samples,) | Yes | Predicted labels |
| target_names | list of str or None | No | Display names per class |
| output_dict | bool | No | Return dict (default: False, returns string) |
Outputs
| Name | Type | Description |
|---|---|---|
| report | str or dict | Report with pre, rec, spe, f1, geo, iba, sup per class plus averages |
Usage Examples
from imblearn.metrics import classification_report_imbalanced
y_true = [0, 1, 2, 2, 2]
y_pred = [0, 0, 2, 2, 1]
target_names = ["class 0", "class 1", "class 2"]
print(classification_report_imbalanced(y_true, y_pred, target_names=target_names))
# As dictionary
report_dict = classification_report_imbalanced(
y_true, y_pred, output_dict=True
)
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment