Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Issue with the RidgeCV diagram representation with non-default alphas #31525

Closed
@glemaitre

Description

@glemaitre

It seems that we introduced a regression in the HTML representation. The following code is failing:

import numpy as np
from sklearn.linear_model import RidgeCV

RidgeCV(np.logspace(-3, 3, num=10)

leads to the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File ~/Documents/teaching/demo_data_science_agent/.pixi/envs/default/lib/python3.13/site-packages/IPython/core/formatters.py:406, in BaseFormatter.__call__(self, obj)
    404     method = get_real_method(obj, self.print_method)
    405     if method is not None:
--> 406         return method()
    407     return None
    408 else:

File ~/Documents/teaching/demo_data_science_agent/.pixi/envs/default/lib/python3.13/site-packages/sklearn/utils/_repr_html/base.py:145, in ReprHTMLMixin._repr_html_inner(self)
    140 def _repr_html_inner(self):
    141     """This function is returned by the @property `_repr_html_` to make
    142     `hasattr(estimator, "_repr_html_") return `True` or `False` depending
    143     on `get_config()["display"]`.
    144     """
--> 145     return self._html_repr()

File ~/Documents/teaching/demo_data_science_agent/.pixi/envs/default/lib/python3.13/site-packages/sklearn/utils/_repr_html/estimator.py:480, in estimator_html_repr(estimator)
    469 html_template = (
    470     f"<style>{style_with_id}</style>"
    471     f"<body>"
   (...)    476     '<div class="sk-container" hidden>'
    477 )
    479 out.write(html_template)
--> 480 _write_estimator_html(
    481     out,
    482     estimator,
    483     estimator.__class__.__name__,
    484     estimator_str,
    485     first_call=True,
    486     is_fitted_css_class=is_fitted_css_class,
    487     is_fitted_icon=is_fitted_icon,
    488 )
    489 with open(str(Path(__file__).parent / "estimator.js"), "r") as f:
    490     script = f.read()

File ~/Documents/teaching/demo_data_science_agent/.pixi/envs/default/lib/python3.13/site-packages/sklearn/utils/_repr_html/estimator.py:386, in _write_estimator_html(out, estimator, estimator_label, estimator_label_details, is_fitted_css_class, is_fitted_icon, first_call, param_prefix)
    384 elif est_block.kind == "single":
    385     if hasattr(estimator, "_get_params_html"):
--> 386         params = estimator._get_params_html()._repr_html_inner()
    387     else:
    388         params = ""

File ~/Documents/teaching/demo_data_science_agent/.pixi/envs/default/lib/python3.13/site-packages/sklearn/base.py:310, in BaseEstimator._get_params_html(self, deep)
    306 ordered_out = {name: out[name] for name in init_default_params if name in out}
    307 ordered_out.update({name: out[name] for name in remaining_params})
    309 non_default_ls = tuple(
--> 310     [name for name, value in ordered_out.items() if is_non_default(name, value)]
    311 )
    313 return ParamsDict(ordered_out, non_default=non_default_ls)

File ~/Documents/teaching/demo_data_science_agent/.pixi/envs/default/lib/python3.13/site-packages/sklearn/base.py:296, in BaseEstimator._get_params_html.<locals>.is_non_default(param_name, param_value)
    291 if isinstance(param_value, BaseEstimator) and type(param_value) is not type(
    292     init_default_params[param_name]
    293 ):
    294     return True
--> 296 if param_value != init_default_params[param_name] and not (
    297     is_scalar_nan(init_default_params[param_name])
    298     and is_scalar_nan(param_value)
    299 ):
    300     return True
    301 return False

ValueError: operands could not be broadcast together with shapes (10,) (3,) 

@DeaMariaLeon Would you mind to look at it. If I get the time, I can look at it a bit more in details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions