Skip to content

MAINT Parameters validation for sklearn.tree.export_graphviz #26034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 16, 2023

Conversation

Charlie-XIAO
Copy link
Contributor

Reference Issues/PRs

Towards #24862.

What does this implement/fix? Explain your changes.

Automatic parameter validation for sklearn.tree.export_graphviz

@glemaitre glemaitre added No Changelog Needed Validation related to input validation labels Apr 1, 2023
@glemaitre glemaitre self-requested a review April 1, 2023 17:58
Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove the code that checks for the precision parameter (l.445 - l.457):

        # validate
        if isinstance(precision, Integral):
            if precision < 0:
                raise ValueError(
                    "'precision' should be greater or equal to 0."
                    " Got {} instead.".format(precision)
                )
        else:
            raise ValueError(
                "'precision' should be an integer. Got {} instead.".format(
                    type(precision)
                )
            )

Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @Charlie-XIAO. Here are some comments

@Charlie-XIAO
Copy link
Contributor Author

Hi @jeremiedbb, I have made the changes you suggested. Would you mind taking a look?

@Charlie-XIAO
Copy link
Contributor Author

Charlie-XIAO commented Apr 27, 2023

A few questions here:

@adrinjalali
Copy link
Member

probably better to actually accept array-like.

  • Should we make the validation of decision_tree in export_text to be "no_validation" as well? (maybe in another PR)

sounds good.

@jeremiedbb
Copy link
Member

Should we make the validation of decision_tree in export_text to be "no_validation" as well? (maybe in another PR)

export_text is different because it actually checks that the tree is an instance of DecisionTreeClassifier

@Charlie-XIAO
Copy link
Contributor Author

Will update validation of feature_names and class_names to "array-like" after #26289 is merged (in which we decided to call check_array on those).

@Charlie-XIAO
Copy link
Contributor Author

Charlie-XIAO commented May 16, 2023

#26289 has been merged so I think this PR is ready for review again. Can maintainers take a look? @glemaitre @adrinjalali @jeremiedbb Thank you very much.

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thomasjpfan thomasjpfan merged commit be892f5 into scikit-learn:main May 16, 2023
@Charlie-XIAO Charlie-XIAO deleted the param-val-export_graphviz branch September 23, 2023 13:28
REDVM pushed a commit to REDVM/scikit-learn that referenced this pull request Nov 16, 2023
…learn#26034)

Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants