Skip to content

Fix check_decision_proba_consistency random failure #19225

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions sklearn/utils/estimator_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2907,16 +2907,19 @@ def check_decision_proba_consistency(name, estimator_orig):
centers = [(2, 2), (4, 4)]
X, y = make_blobs(n_samples=100, random_state=0, n_features=4,
centers=centers, cluster_std=1.0, shuffle=True)
X_test = np.random.randn(20, 2) + 4
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=0)
estimator = clone(estimator_orig)

if (hasattr(estimator, "decision_function") and
hasattr(estimator, "predict_proba")):

estimator.fit(X, y)
estimator.fit(X_train, y_train)
# Since the link function from decision_function() to predict_proba()
# is sometimes not precise enough (typically expit), we round to the
# 10th decimal to avoid numerical issues.
# 10th decimal to avoid numerical issues: we compare the rank
# with deterministic ties rather than get platform specific rank
# inversions in case of machine level differences.
a = estimator.predict_proba(X_test)[:, 1].round(decimals=10)
b = estimator.decision_function(X_test).round(decimals=10)
assert_array_equal(rankdata(a), rankdata(b))
Expand Down