Skip to content

[MRG] TST use global_random_seed in sklearn/ensemble/tests/test_gradient_boosting_loss_functions.py #23559

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

13 changes: 6 additions & 7 deletions sklearn/ensemble/tests/test_gradient_boosting_loss_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ def test_sample_weight_deviance():


@pytest.mark.parametrize("n_classes, n_samples", [(3, 100), (5, 57), (7, 13)])
def test_multinomial_deviance(n_classes, n_samples):
def test_multinomial_deviance(n_classes, n_samples, global_random_seed):
# Check multinomial deviance with and without sample weights.
rng = np.random.RandomState(13)
rng = np.random.RandomState(global_random_seed)
sample_weight = np.ones(n_samples)
y_true = rng.randint(0, n_classes, size=n_samples)
y_pred = np.zeros((n_samples, n_classes), dtype=np.float64)
Expand Down Expand Up @@ -230,10 +230,10 @@ def test_init_raw_predictions_shapes():
assert raw_predictions.dtype == np.float64


def test_init_raw_predictions_values():
def test_init_raw_predictions_values(global_random_seed):
# Make sure the get_init_raw_predictions() returns the expected values for
# each loss.
rng = np.random.RandomState(0)
rng = np.random.RandomState(global_random_seed)

n_samples = 100
X = rng.normal(size=(n_samples, 5))
Expand Down Expand Up @@ -294,15 +294,14 @@ def test_init_raw_predictions_values():
assert_allclose(raw_predictions[:, k], np.log(p))


@pytest.mark.parametrize("seed", range(5))
@pytest.mark.parametrize("alpha", [0.4, 0.5, 0.6])
def test_lad_equals_quantiles(seed, alpha):
def test_lad_equals_quantiles(global_random_seed, alpha):
# Make sure quantile loss with alpha = .5 is equivalent to LAD
lad = LeastAbsoluteError()
ql = QuantileLossFunction(alpha=alpha)

n_samples = 50
rng = np.random.RandomState(seed)
rng = np.random.RandomState(global_random_seed)
raw_predictions = rng.normal(size=(n_samples))
y_true = rng.normal(size=(n_samples))

Expand Down