Skip to content

Allow infinite values in tree and forest prediction - #34694

Closed
godofecht wants to merge 2 commits into
scikit-learn:mainfrom
godofecht:fix-34668-rf-infinite-predict-v2
Closed

godofecht wants to merge 2 commits into
scikit-learn:mainfrom
godofecht:fix-34668-rf-infinite-predict-v2

Conversation

@godofecht

Copy link
Copy Markdown

Reference Issue

Fixes #34668

What does this implement/fix?

Tree-based models use decision rules of the form x <= value which are well-defined for infinite values. Currently predict rejects inputs containing infinity, but this is overly conservative.

This PR adds an "allow-inf" option to ensure_all_finite in check_array / validate_data. When set, infinity is allowed but NaN is still rejected. It uses this option in Forest._validate_X_predict and BaseDecisionTree._validate_X_predict so that RandomForest, DecisionTree, and ExtraTree estimators accept infinite values at prediction time.

Reproducer

import numpy as np
rng = np.random.default_rng(seed=123)
X = rng.standard_normal(size=(10, 4))
y = rng.standard_normal(size=X.shape[0])

from sklearn.ensemble import RandomForestRegressor
model = RandomForestRegressor()
model.fit(X, y)

X_inf = X.copy()
X_inf[:, 2:3] = np.inf
pred = model.predict(X_inf)  # currently raises ValueError

This pull request includes code written with the assistance of AI.
The code has not yet been reviewed by a human.

Tree-based models use decision rules of the form `x <= value` which are
well-defined for infinite values. Currently `predict` rejects inputs
containing infinity, but this is overly conservative.

Add `"allow-inf"` option to `ensure_all_finite` in `check_array` /
`validate_data`. When set, infinity is allowed but NaN is still rejected.

Use `"allow-inf"` in `Forest._validate_X_predict` and
`BaseDecisionTree._validate_X_predict` so that `RandomForest`,
`DecisionTree`, and `ExtraTree` estimators accept infinite values at
prediction time.

This pull request includes code written with the assistance of AI.
The code has **not yet been reviewed** by a human.
@github-actions

Copy link
Copy Markdown

Thank you for opening your first pull request to scikit-learn! 🎉

To help get your contribution reviewed, please make sure that:

  • You have filled out the pull request template.
  • The pull request addresses an existing issue that is ready for
    contribution (e.g. not tagged as "Needs Triage", "Needs Decision", ...).
    If you are proposing a new feature, please open an issue to discuss it first.
  • There are no other open pull requests already targeting the same issue.
  • You have followed the pull request checklist.
    In particular, linting and tests should pass.

@github-actions github-actions Bot added module:ensemble module:utils CI:Linter failure The linter CI is failing on this PR labels Aug 10, 2026
@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Aug 10, 2026
@AnneBeyer

Copy link
Copy Markdown
Member

Hi @godofecht, thank you for your interest, but opening automated PRs for issues (without checking if they are actually ready for contribution yet) is not something we value in this community (see our automated contributions policy). If you want to help, please read our contribution guidelines, and after understanding our values maybe spend your credits on helping us with reviewing any of the >500 open PRs instead.
With that said, I'm closing this PR and the other 16 you opened in the last hour (and am very happy that #34506 just got merged).

@lesteve

lesteve commented Aug 10, 2026 •

Copy link
Copy Markdown
Member

I am going to ban this user, this seems like an automated thing that opens many PRs in scikit-learn and other repos, duplicates scikit-learn issues in a separate repo 😱.

See PRs opened in scikit-learn: https://github.com/scikit-learn/scikit-learn/pulls?q=sort%3Aupdated-desc+is%3Apr+author%3Agodofecht+is%3Aclosed

Duplicated scikit-learn issues in separate repo: https://github.com/flooooooooooow/flow/issues?q=sort%3Aupdated-desc%20is%3Aissue%20scikit-learn

Also has a scikit-learn fork that looks like it's going to be automatically updated by agents based on all the feed-back that is available in our issue tracker: https://github.com/godofecht/flow-scikit

@virchan virchan added the spam spam PR and issues label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RandomForest errors out with infinite values for predictions

4 participants