Description
In the pcvl branch of alpha selection, transformed_range becomes an empty list when i_best_alpha == 0. This happens because pl_alphas[0] is the maximum value, causing np.argmax() to return 0. As a result, np.arange(i_best_alpha) generates an empty array, leading to a failure in np.argmax(transformed_pl_alphas).
Expected Behavior
The code should handle cases where i_best_alpha == 0 by skipping the transformation step and directly assigning best_alpha, best_l1_ratio, and best_pl_score from the original values.
Proposed Fix
Modify the code to check for i_best_alpha == 0 and handle it explicitly.
Code Reference
|
transformed_range = np.arange(i_best_alpha) |
|
transformed_pl_alphas = pl_alphas[transformed_range] - ( |
|
((pl_best_alpha - pl_alpha_max) / sparsity_best_alpha) |
|
* n_coefs[transformed_range] |
|
) |
|
transformed_i_best_alpha = np.argmax(transformed_pl_alphas) |
|
this_best_pl_transformed = transformed_pl_alphas[ |
|
transformed_i_best_alpha |
|
] |
|
if this_best_pl_transformed > best_pl_score: |
|
best_alpha = l1_alphas[transformed_i_best_alpha] |
|
best_l1_ratio = l1_ratio |
|
best_pl_score = this_best_pl_transformed |
Description
In the
pcvlbranch of alpha selection,transformed_rangebecomes an empty list wheni_best_alpha == 0. This happens becausepl_alphas[0]is the maximum value, causingnp.argmax()to return 0. As a result,np.arange(i_best_alpha)generates an empty array, leading to a failure innp.argmax(transformed_pl_alphas).Expected Behavior
The code should handle cases where
i_best_alpha == 0by skipping the transformation step and directly assigningbest_alpha,best_l1_ratio, andbest_pl_scorefrom the original values.Proposed Fix
Modify the code to check for
i_best_alpha == 0and handle it explicitly.Code Reference
sparsesurv/sparsesurv/cv.py
Lines 553 to 565 in 90b5292