Repository navigation
ENH Display fitted attributes in HTML representation - #31442
DeaMariaLeon wants to merge 92 commits into
Conversation
| if hasattr(self, "_remainder"): | ||
| remainder_columns = self._remainder[2] | ||
| if ( | ||
| hasattr(self, "feature_names_in_") | ||
| and remainder_columns | ||
| and not all(isinstance(col, str) for col in remainder_columns) | ||
| ): | ||
| remainder_columns = self.feature_names_in_[ | ||
| remainder_columns | ||
| ].tolist() |
There was a problem hiding this comment.
Is there a case where _remainder is not defined ? I've the impression that it's always defined when fitted
| if hasattr(self, "_remainder"): | |
| remainder_columns = self._remainder[2] | |
| if ( | |
| hasattr(self, "feature_names_in_") | |
| and remainder_columns | |
| and not all(isinstance(col, str) for col in remainder_columns) | |
| ): | |
| remainder_columns = self.feature_names_in_[ | |
| remainder_columns | |
| ].tolist() | |
| remainder_columns = self._remainder[2] | |
| if ( | |
| hasattr(self, "feature_names_in_") | |
| and remainder_columns | |
| and not all(isinstance(col, str) for col in remainder_columns) | |
| ): | |
| remainder_columns = self.feature_names_in_[remainder_columns].tolist() |
There was a problem hiding this comment.
I have to find the example where it was showing "unwanted boxes" if I didn't add the part of drop.
Besides that, on the original code there is the drop check (line 1227 of _column_transformer.py on main) :
if isinstance(self.remainder, str) and self.remainder == "drop":
I think that if I don't add it, it always shows remainder or something. And because the first if changed, I had to write this differently.
Let me check.
There was a problem hiding this comment.
I'm not talking about drop, but about the if hasattr(self, "_remainder"): condition. Since this block of code is in a if branch where the columntransformer is fitter, I think that this check is not necessary because it will always evaluate to True, unless I missed something.
|
|
||
| def _get_fitted_attr_html(self, doc_link=""): | ||
| """Get fitted attributes of the estimator.""" | ||
|
|
There was a problem hiding this comment.
nitpick: I'd move this method next to _get_params_html
There was a problem hiding this comment.
I wonder if I should add more to the docstring.
| # We can find remainder and its column only when it's fitted | ||
|
|
||
| remainder_columns = self._remainder[2] | ||
| if ( | ||
| hasattr(self, "feature_names_in_") | ||
| and remainder_columns | ||
| and not all(isinstance(col, str) for col in remainder_columns) | ||
| ): | ||
| remainder_columns = self.feature_names_in_[remainder_columns].tolist() |
There was a problem hiding this comment.
I just noticed that remainder_columns is not used. A good side effect of relying on the fitted transformers :)
| # We can find remainder and its column only when it's fitted | |
| remainder_columns = self._remainder[2] | |
| if ( | |
| hasattr(self, "feature_names_in_") | |
| and remainder_columns | |
| and not all(isinstance(col, str) for col in remainder_columns) | |
| ): | |
| remainder_columns = self.feature_names_in_[remainder_columns].tolist() |
There was a problem hiding this comment.
why didn't I think of it? 😐
There was a problem hiding this comment.
I found what it was used for: when we fit on a dataframe we get the feature names and list the ones corresponding to the remainder instead of integer indices.
So we need to get that back in and replace the remainder in the transformers list (using chain like it previously was).
Sorry for the back and forth.
There was a problem hiding this comment.
I need to take notes of what I find while it's still fresh in my head: my issue is my own workflow.
There was a problem hiding this comment.
We could also expand the inline comments in the code to make that more explicit.
There was a problem hiding this comment.
I found what it was used for: when we fit on a dataframe we get the feature names and list the ones corresponding to the remainder instead of integer indices.
It's weird that the tests do not break as a result. But I suppose that such a test will only be included once we merge #31937 (check that pandas column names appear in the HTML diagram of a fitted pipeline).
There was a problem hiding this comment.
|
I don't find the current table display for fitted attributes user-friendly: It displays too much information and not in a compact readable way. I get the need to have more information for array like fitted attributes (their shape at least, maybe dtype, maybe container, maybe some summary statistics). But for these we could do it in a follow up PR ? Option 1 (minimal)I think a good way forward for this PR would be to have a minimal layout (for now):
I like the idea to have a harmonized display for Parameters / Fitted Attributes as they play a similar role (list of input stuff, list of output stuff). We can get the shape of an array attribute through the docstring when hovering. We can guess the type from the value (but we may need to improve the prettry printing in a follow up PR). WDTY @jeremiedbb @DeaMariaLeon @glemaitre ? |
Option 2 (tree view list)For a more advanced layout (in a follow up PR ), I think a tree view list of the fitted attributes could be nice ? Each fitted attribute name is a togglable list item, if we want more information we click on the fitted attribute name. We can customize the displayed information based on the attribute type. |
Option 3 (simplified type)If we really want to display the "type" along the name / value, I would use a simplified type. We can keep int, float, dict etc and use array(*shape) for arrays [for example array(2, 10) for a n array of shape (2,10)]. |
I expressed the same concern a couple of times. We have a lot of information and the fact that it's not the same kind of info for all the attributes results in many empty cells which doesn't render very nicely.
It may mess up with the fact that names are already clickable to send you the online doc. It would mean adding an extra button to expand the details, which itself may not interact well with the tooltip that shows up on hovering over the name, and overwhelm the table.
I thought about that alternative but wanted to also show the dtype. I figured that it would be too long, or at least as long as the current version. And I didn't find a nice way to represent both the shape and the dtype. |
I think I was expecting a definitive instruction to remove stuff, plus I was busy implementing the rest. I didn't mean to ignore your concerns.
Ok |
don't worry, they were not targeted at you. I was hoping to get the attention of another core dev :) |
|
Indeed sorry @DeaMariaLeon that the instructions aren't clear yet on the desired display of the Fitted attributes, it seems to change as the PR evolves. We can maybe wait on some feedback of the core devs before moving on ? IMO, the minimal option 1 seems the most promising for a fast merge. We just replicate what has been done for Parameters (without the copy button) and "voila". I feel it's good enough for a first version. @jeremiedbb what's your feeling about the minimal option 1 ? |
|
If you guys want to look at #33399 - like I wrote there, I'm not sure that I understood correctly. Regarding Option 1: Hover effects don't work on tablets or "touch-based" devices, do they?? |
|
@antoinebaker - I did the PR before seeing you last comment, that's why I didn't wait. 😬 EDIT: and don't worry, no hurt feelings. :) |
|
Oh that's great you already implemented option 3 ! Would you mind trying out option 1 in yet another draft PR ?
I don't know in general, but the hover effect works on my laptop (mac os) trackpad. |
That's a pragmatic solution indeed. However, I like a lot the alternative in #33399 and I think it could be pretty much as fast to review as the minimal one. |
I think @DeaMariaLeon refers to mobile devices with a touch screen only (no mouse / trackpad). In this case it's not possible to display extra info when hovering. It's only possible to display things when clicking/tapping on stuff. |
|
I think we have a consensus that #33399 is better. Let's close this one. |

Reference Issues/PRs
Towards #26595
What does this implement/fix? Explain your changes.
Display the (public) fitted attributes with their type. Shows also shape for array-valued attributes.
Any other comments?
Continuation of work started on this PR: #30763
cc @glemaitre
edit: