8000 Making RNG deterministic · mjbommar/scikit-learn@6e9d254 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e9d254

Browse files
committed
Making RNG deterministic
1 parent 46a5aa5 commit 6e9d254

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

sklearn/tests/test_isotonic.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,17 @@ def test_isotonic_zero_weight_loop():
313313
# Test from @ogrisel's issue:
314314
# https://github.com/scikit-learn/scikit-learn/issues/4297
315315

316+
# Get deterministic RNG with seed
317+
rng = np.random.RandomState(42)
318+
319+
# Create regression and samples
316320
regression = IsotonicRegression()
317321
n_samples = 50
318322
x = np.linspace(-3, 3, n_samples)
319-
y = x + np.random.uniform(size=n_samples)
323+
y = x + rng.uniform(size=n_samples)
320324

321325
# Get some random weights and zero out
322-
w = np.random.uniform(size=n_samples)
326+
w = rng.uniform(size=n_samples)
323327
w[5:8] = 0
324328
regression.fit(x, y, sample_weight=w)
325329

0 commit comments

Comments
 (0)
0