Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
k-diagram v1.2.2
Logo
k-diagram v1.2.2

Documentation Contents:

  • Installation
  • Quick Start
  • Motivation and Background
  • User Guide
    • Visualizing Forecast Uncertainty
    • Visualizing Forecast Errors
    • Evaluating Probabilistic Forecasts
    • Model Comparison Visualization
    • Visualizing Relationships
    • Feature Importance Visualization
    • Evaluating Classification Models
    • Taylor Diagrams
    • Contextual Diagnostic Plots
    • Visualizing 1D Distributions
    • Forecast Utilities
    • Working with Quantile Data
    • Mathematical Utilities
    • Datasets
    • Case Study: Zhongshan Land Subsidence Uncertainty
  • Command-Line Interface (CLI)
    • Introduction - CLI
    • Context plots
    • Evaluation Plots
    • Comparison & Calibration
    • Taylor Diagram
    • Probabilistic Diagnostics
    • Uncertainty & Diagnostics
    • Relationship Commands
    • Error Diagnostics
    • Feature-Based Plots
  • Gallery
    • Uncertainty Visualizations
    • Error Visualizations
    • Probabilistic Diagnostics Gallery
    • Model Comparison Gallery
    • Relationship Visualization
    • Feature-Based Visualization Gallery
    • Model Evaluation Gallery
    • Taylor Diagrams
    • Contextual Diagnostic Plots
    • Histogram Gallery
  • API Reference
    • kdiagram.plot.uncertainty.plot_actual_vs_predicted
    • kdiagram.plot.uncertainty.plot_anomaly_magnitude
    • kdiagram.plot.uncertainty.plot_coverage
    • kdiagram.plot.uncertainty.plot_coverage_diagnostic
    • kdiagram.plot.uncertainty.plot_interval_consistency
    • kdiagram.plot.uncertainty.plot_interval_width
    • kdiagram.plot.uncertainty.plot_model_drift
    • kdiagram.plot.uncertainty.plot_temporal_uncertainty
    • kdiagram.plot.uncertainty.plot_uncertainty_drift
    • kdiagram.plot.uncertainty.plot_velocity
    • kdiagram.plot.uncertainty.plot_radial_density_ring
    • kdiagram.plot.uncertainty.plot_polar_heatmap
    • kdiagram.plot.uncertainty.plot_polar_quiver
    • kdiagram.plot.errors.plot_error_bands
    • kdiagram.plot.errors.plot_error_violins
    • kdiagram.plot.errors.plot_error_ellipses
    • kdiagram.plot.probabilistic.plot_pit_histogram
    • kdiagram.plot.probabilistic.plot_polar_sharpness
    • kdiagram.plot.probabilistic.plot_crps_comparison
    • kdiagram.plot.probabilistic.plot_credibility_bands
    • kdiagram.plot.probabilistic.plot_calibration_sharpness
    • kdiagram.plot.comparison.plot_model_comparison
    • kdiagram.plot.comparison.plot_reliability_diagram
    • kdiagram.plot.comparison.plot_polar_reliability
    • kdiagram.plot.comparison.plot_horizon_metrics
    • kdiagram.plot.relationship.plot_relationship
    • kdiagram.plot.relationship.plot_conditional_quantiles
    • kdiagram.plot.relationship.plot_error_relationship
    • kdiagram.plot.relationship.plot_residual_relationship
    • kdiagram.plot.feature_based.plot_feature_fingerprint
    • kdiagram.plot.feature_based.plot_feature_interaction
    • kdiagram.plot.context.plot_time_series
    • kdiagram.plot.context.plot_scatter_correlation
    • kdiagram.plot.context.plot_error_distribution
    • kdiagram.plot.context.plot_qq
    • kdiagram.plot.context.plot_error_autocorrelation
    • kdiagram.plot.context.plot_error_pacf
    • kdiagram.plot.evaluation.plot_polar_roc
    • kdiagram.plot.evaluation.plot_polar_pr_curve
    • kdiagram.plot.evaluation.plot_polar_confusion_matrix
    • kdiagram.plot.evaluation.plot_polar_confusion_matrix_in
    • kdiagram.plot.evaluation.plot_polar_classification_report
    • kdiagram.plot.evaluation.plot_pinball_loss
    • kdiagram.plot.evaluation.plot_regression_performance
    • kdiagram.plot.taylor_diagram.taylor_diagram
    • kdiagram.plot.taylor_diagram.plot_taylor_diagram_in
    • kdiagram.plot.taylor_diagram.plot_taylor_diagram
    • kdiagram.utils.bin_by_feature
    • kdiagram.utils.build_cdf_interpolator
    • kdiagram.utils.build_q_column_names
    • kdiagram.utils.calculate_calibration_error
    • kdiagram.utils.calculate_probabilistic_scores
    • kdiagram.utils.compute_coverage_score
    • kdiagram.utils.compute_crps
    • kdiagram.utils.compute_forecast_errors
    • kdiagram.utils.compute_interval_width
    • kdiagram.utils.compute_pinball_loss
    • kdiagram.utils.compute_pit
    • kdiagram.utils.compute_winkler_score
    • kdiagram.utils.detect_quantiles_in
    • kdiagram.utils.get_forecast_arrays
    • kdiagram.utils.melt_q_data
    • kdiagram.utils.minmax_scaler
    • kdiagram.utils.pivot_forecasts_long
    • kdiagram.utils.pivot_q_data
    • kdiagram.utils.plot_hist_kde
    • kdiagram.utils.reshape_quantile_data
    • kdiagram.datasets.load_uncertainty_data
    • kdiagram.datasets.load_zhongshan_subsidence
    • kdiagram.datasets.make_cyclical_data
    • kdiagram.datasets.make_fingerprint_data
    • kdiagram.datasets.make_multi_model_quantile_data
    • kdiagram.datasets.make_regression_data
    • kdiagram.datasets.make_classification_data
    • kdiagram.datasets.make_taylor_data
    • kdiagram.datasets.make_uncertainty_data
  • Contributing
  • Code of Conduct
  • Citing k-diagram
  • Release Notes
    • Version 1.2.2
    • Version 1.2.0
    • Version 1.1.0
    • Version 1.0.3
    • Version 1.0.0
  • License
  • Glossary
  • References
Back to top
View this page
Edit this page

Feature-Based Visualization Gallery¶

This gallery page showcases plots from k-diagram focused on understanding feature influence and importance. Currently, it features the Feature Importance Fingerprint plot.

Note

You need to run the code snippets locally to generate the plot images referenced below (e.g., images/gallery_feature_fingerprint.png). Ensure the image paths in the .. image:: directives match where you save the plots (likely an images subdirectory relative to this file).

Feature Importance Fingerprint¶

Uses plot_feature_fingerprint(). This radar chart compares the importance profiles (“fingerprints”) of several features across different groups or layers (e.g., different years or models). This example shows raw (unnormalized) importance values comparing feature influence across three years.

 1# Assuming plot function is in kd.plot.feature_based
 2import kdiagram.plot.feature_based as kdf
 3import numpy as np
 4import matplotlib.pyplot as plt
 5
 6# --- Data Generation ---
 7features = ['Rainfall', 'Temperature', 'Wind Speed',
 8            'Soil Moisture', 'Solar Radiation', 'Topography']
 9n_features = len(features)
10years = ['2022', '2023', '2024']
11n_layers = len(years)
12
13# Generate importance scores (rows=years, cols=features)
14# Make them slightly different per year
15np.random.seed(123)
16importances = np.random.rand(n_layers, n_features) * 0.5
17importances[0, 0] = 0.8 # Rainfall important in 2022
18importances[1, 3] = 0.9 # Soil Moisture important in 2023
19importances[2, 1] = 0.7 # Temperature important in 2024
20importances[2, 4] = 0.75# Solar Radiation also important in 2024
21
22# --- Plotting ---
23kdf.plot_feature_fingerprint(
24    importances=importances,
25    features=features,
26    labels=years,
27    normalize=False, # Show raw importance scores
28    fill=True,
29    cmap='Pastel1',
30    title="Gallery: Feature Importance Fingerprint (Yearly)",
31    # Save the plot relative to this file's location
32    savefig="images/gallery_feature_fingerprint.png"
33)
34plt.close()
Feature Importance Fingerprint Plot Example

🧠 Analysis and Interpretation

The Feature Importance Fingerprint (a radar plot) visually represents the importance of various features across different groups or “layers”. Each axis corresponds to a feature, and each colored polygon represents a layer (here, different years). The distance from the center along an axis indicates that feature’s importance for that specific layer.

Analysis and Interpretation:

  • Axes: Represent Rainfall, Temperature, Wind Speed, Soil Moisture, Solar Radiation, and Topography.

  • Layers (Colors/Polygons): Represent the years 2022, 2023, and 2024, showing how feature importance changes annually.

  • Radius: Since normalize=False, the radius shows the raw importance score. Larger extensions along an axis mean higher importance.

  • Shape (“Fingerprint”): The overall shape of each polygon gives a unique “fingerprint” of feature influence for that year.

🔍 Key Insights from this Example:

  • 2022: The polygon extends furthest along the Rainfall axis, indicating it was the dominant feature in that year’s model or context.

  • 2023: The Soil Moisture axis shows the largest value, suggesting a shift in primary drivers compared to 2022.

  • 2024: Temperature and Solar Radiation show the highest importance, indicating another change in the factors influencing the outcome for this year.

  • Comparison: We can easily see that the relative importance of features is not static but changes from year to year.

💡 When to Use This Plot:

  • Compare Feature Importance: Visualize differences between models, time periods, or groups (e.g., spatial zones).

  • Identify Dominant Features: Quickly see which features have the most impact for each layer.

  • Analyze Importance Drift: Track how feature influence evolves over time, as shown in this yearly example.

  • Model Interpretation: Understand and communicate the key drivers behind model predictions for different scenarios.


Polar Feature Interaction¶

Visualizes the interaction between two features by plotting a target variable’s aggregated value on a polar heatmap. This plot is designed to reveal complex, non-linear relationships that are not apparent from 1D feature-importance plots.

 1import kdiagram as kd
 2import pandas as pd
 3import numpy as np
 4import matplotlib.pyplot as plt
 5
 6# --- Data Generation ---
 7
 8np.random.seed(0)
 9n_points = 5000
10
11# Feature 1 (Angle): Hour of day
12hour_of_day = np.random.uniform(0, 24, n_points)
13
14# Feature 2 (Radius): Cloud cover
15cloud_cover = np.random.rand(n_points)
16
17# Target (Color): Solar panel output, which depends on the
18# interaction between daylight and cloud cover.
19daylight_factor = np.sin(hour_of_day * np.pi / 24) ** 2
20cloud_factor = (1 - cloud_cover ** 0.5)
21panel_output = 100 * daylight_factor * cloud_factor + np.random.rand(n_points) * 5
22panel_output[(hour_of_day < 6) | (hour_of_day > 18)] = 0
23
24df_solar = pd.DataFrame({
25    'hour': hour_of_day,
26    'cloud_cover': cloud_cover,
27    'panel_output': panel_output,
28})
29
30# --- Plotting ---
31
32kd.plot_feature_interaction(
33    df=df_solar,
34    theta_col='hour',
35    r_col='cloud_cover',
36    color_col='panel_output',
37    theta_period=24,
38    theta_bins=24,  # One bin per hour
39    r_bins=8,
40    cmap='inferno',
41    title='Solar Panel Output by Hour and Cloud Cover',
42    savefig='gallery/images/plot_feature_based_interaction.png',
43)
44plt.close()
Example of a Polar Feature Interaction Plot

🧠 Analysis and Interpretation

The Polar Feature Interaction plot provides a powerful diagnostic for understanding how two features jointly influence a target variable.

Key Features:

  • Angle (θ): First feature, often cyclical (here, hour of day).

  • Radius (r): Second feature (here, cloud cover, with 0 at the center).

  • Color: Mean value of the target for points within each angle–radius bin.

🔍 In this Example:

  • Interaction “Hot Spot”: Bright region at low radius (low cloud cover) and angle ~90° (midday) shows output is high only when it is noon AND cloud cover is low.

  • No-Interaction Zones: Night hours are dark (zero output) regardless of cloud cover; outer rings (high cloud cover) remain dark even during the day.

💡 When to Use:

  • Move beyond simple feature importance to diagnose pairwise feature interactions affecting predictions or errors.

  • Identify non-linear relationships and conditional patterns.

  • Visually confirm expected interaction effects learned by a model.


Next
Model Evaluation Gallery
Previous
Relationship Visualization
Copyright © 2025, Laurent Kouadio
Made with Sphinx and @pradyunsg's Furo
On this page
  • Feature-Based Visualization Gallery
    • Feature Importance Fingerprint
    • Polar Feature Interaction