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()