Implementation:DistrictDataLabs Yellowbrick Rank2D Visualizer
| Knowledge Sources | |
|---|---|
| Domains | Machine_Learning, Feature_Analysis, Visualization |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
Concrete tools for feature ranking visualization provided by the Yellowbrick library, comprising the Rank1D (univariate bar chart) and Rank2D (bivariate heatmap) visualizers and their shared base class RankDBase.
Description
The Rank1D visualizer scores each feature independently using a univariate algorithm (default: Shapiro-Wilk) and renders the results as a horizontal or vertical bar chart. The Rank2D visualizer computes pairwise scores between every pair of features using algorithms such as Pearson correlation, Spearman rank correlation, Kendall tau, or covariance, and renders the result as a lower-left triangle heatmap. Both classes inherit from RankDBase, which provides the shared transform and rank methods that compute and cache the ranking scores.
Usage
Use Rank1D when you need a quick overview of the distributional quality of each individual feature. Use Rank2D when you want to detect multicollinearity, redundant features, or feature clusters through pairwise comparison. Both visualizers follow the scikit-learn transformer interface: call fit() to discover feature names, then transform() to compute rankings and draw the plot.
Code Reference
Source Location
- Repository: yellowbrick
- File: yellowbrick/features/rankd.py
- Lines: Rank1D at L231-341, Rank2D at L349-465, RankDBase at L64-224, quick methods at L472-638
Signatures
RankDBase (base class):
class RankDBase(MultiFeatureVisualizer):
def __init__(
self,
ax=None,
fig=None,
algorithm=None,
features=None,
show_feature_names=True,
**kwargs
):
Rank1D:
class Rank1D(RankDBase):
def __init__(
self,
ax=None,
algorithm="shapiro",
features=None,
orient="h",
show_feature_names=True,
color=None,
**kwargs
):
Rank2D:
class Rank2D(RankDBase):
def __init__(
self,
ax=None,
algorithm="pearson",
features=None,
colormap="RdBu_r",
show_feature_names=True,
**kwargs
):
Import
from yellowbrick.features import Rank1D, Rank2D
I/O Contract
Inputs (Rank1D)
| Name | Type | Required | Description |
|---|---|---|---|
| ax | matplotlib Axes | No | The axis to plot on. If None, the current axes are used. |
| algorithm | str | No | Ranking algorithm. Default "shapiro" (Shapiro-Wilk).
|
| features | list | No | Feature names. Inferred from DataFrame columns if not given. |
| orient | str | No | Bar orientation: "h" (horizontal, default) or "v" (vertical).
|
| show_feature_names | bool | No | Whether to label ticks with feature names. Default True.
|
| color | str | No | Color for the bar chart. |
Inputs (Rank2D)
| Name | Type | Required | Description |
|---|---|---|---|
| ax | matplotlib Axes | No | The axis to plot on. If None, the current axes are used. |
| algorithm | str | No | Ranking algorithm: "pearson" (default), "covariance", "spearman", or "kendalltau".
|
| features | list | No | Feature names. Inferred from DataFrame columns if not given. |
| colormap | str or cmap | No | Colormap for the heatmap. Default "RdBu_r".
|
| show_feature_names | bool | No | Whether to label ticks with feature names. Default True.
|
Outputs
| Name | Type | Description |
|---|---|---|
| ranks_ | ndarray | Rank1D: array of shape (n_features,). Rank2D: array of shape (n_features, n_features).
|
| X (return) | ndarray | The transform() method returns the original input data X unmodified.
|
| ax | matplotlib Axes | The axes object containing the rendered visualization. |
Usage Examples
Basic Usage (Rank1D)
from yellowbrick.features import Rank1D
from sklearn.datasets import load_iris
X, y = load_iris(return_X_y=True)
visualizer = Rank1D(algorithm="shapiro")
visualizer.fit(X, y)
visualizer.transform(X)
visualizer.show()
Basic Usage (Rank2D)
from yellowbrick.features import Rank2D
from sklearn.datasets import load_iris
X, y = load_iris(return_X_y=True)
visualizer = Rank2D(algorithm="pearson")
visualizer.fit(X, y)
visualizer.transform(X)
visualizer.show()
Quick Methods
from yellowbrick.features import rank1d, rank2d
from sklearn.datasets import load_iris
X, y = load_iris(return_X_y=True)
# One-liner for 1D ranking
rank1d(X, y, algorithm="shapiro", orient="h")
# One-liner for 2D ranking
rank2d(X, y, algorithm="pearson", colormap="RdBu_r")