File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 1616from skglm .solvers import GroupProxNewton
1717from skglm .utils .data import make_correlated_data , grp_converter
1818
19+ import matplotlib .pyplot as plt
20+
1921n_features = 30
2022X , y , _ = make_correlated_data (
2123 n_samples = 10 , n_features = 30 , random_state = 0 )
4244# %%
4345# Fit check that groups are either all 0 or all non zero
4446print (clf .coef_ .reshape (- 1 , grp_size ))
47+
48+ # %%
49+ # Visualise group-level sparsity
50+
51+ coef_by_group = clf .coef_ .reshape (- 1 , grp_size )
52+ group_norms = np .linalg .norm (coef_by_group , axis = 1 )
53+
54+ plt .figure (figsize = (8 , 4 ))
55+ plt .bar (np .arange (n_groups ), group_norms )
56+ plt .xlabel ("Group index" )
57+ plt .ylabel ("L2 norm of coefficients" )
58+ plt .title ("Group Sparsity Pattern" )
59+ plt .tight_layout ()
60+ plt .show ()
61+
62+ # %%
63+ # This plot shows the L2 norm of the coefficients for each group.
64+ # Groups with a zero norm have been set inactive by the model,
65+ # illustrating how Group Logistic Regression enforces sparsity at the group level.
66+ # (Note: This example uses a tiny synthetic dataset, so the pattern has limited interpretability.)
You can’t perform that action at this time.
0 commit comments