skills/tabular/l1-coefficient-interaction-map/SKILL.md
Extract and visualize per-subgroup feature coefficient signs from L1-regularized models as an interaction heatmap for EDA
npx skillsauth add wenmin-wu/ds-skills tabular-l1-coefficient-interaction-mapInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
When data has a partitioning variable (group/category) with many values, understanding which features matter per group is hard. Train an L1-regularized model per group, extract coefficient signs (+1/0/-1), and assemble into a groups×features matrix. Visualized as a heatmap, this reveals: which features are universally important, which are group-specific, and whether feature interactions flip direction across groups.
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LogisticRegression
n_groups = df['group'].nunique()
n_features = len(feature_cols)
interactions = np.zeros((n_groups, n_features))
for i, g in enumerate(sorted(df['group'].unique())):
subset = df[df['group'] == g]
clf = LogisticRegression(solver='liblinear', penalty='l1', C=0.05)
clf.fit(subset[feature_cols], subset['target'])
interactions[i] = np.sign(clf.coef_[0])
plt.figure(figsize=(15, 8))
plt.matshow(interactions.T, fignum=1, aspect='auto', cmap='RdBu')
plt.xlabel('Group index')
plt.ylabel('Feature index')
plt.colorbar(label='Coefficient sign')
plt.title('Feature × Group Interaction Map')
plt.show()
clf.coef_[0] → apply np.sign() to get +1/0/-1data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF