Feature importance, permutation importance, and prediction diagnostics.
The inspection subpackage helps you understand which variables matter most and how well models predict the objective. These tools are useful both for analyzing optimization results and for general machine learning model diagnostics.
Mean Decrease in Impurity (MDI)
generate_mdi() trains a Random Forest and extracts feature importance scores based on impurity reduction:
import numpy as npimport pandas as pdfrom spotoptim.inspection.importance import generate_mdinp.random.seed(0)X = np.random.uniform(-5, 5, size=(100, 3))y = X[:, 0]**2+0.5* X[:, 1]**2+0.01* X[:, 2]**2df_mdi = generate_mdi(X, y, feature_names=["x1", "x2", "x3"], random_state=0)print(df_mdi.to_string())