code: def test_predictions(global_random_seed, use_feature_names):
      # Train a model with a POS constraint on the first feature and a NEG
      # constraint on the second feature, and make sure the constraints are
      # respected by checking the predictions.
      # test adapted from lightgbm's test_monotone_constraint(), itself inspired
      # by https://xgboost.readthedocs.io/en/latest/tutorials/monotonic.html
  
      rng = np.random.RandomState(global_random_seed)
  
      n_samples = 1000
      f_0 = rng.rand(n_samples)  # positive correlation with y
      f_1 = rng.rand(n_samples)  # negative correslation with y
      X = np.c_[f_0, f_1]
      columns_name = ["f_0", "f_1"]
      constructor_name = "dataframe" if use_feature_names else "array"
      X = _convert_container(
          X, constructor_name, columns_name=columns_name
      )
  
      noise = rng.normal(loc=0.0, scale=0.01, size=n_samples)
      y = (
          5 * f_0
          + np.sin(10 * np.pi * f_0)
          - 5 * f_1
          - np.cos(10 * np.pi * f_1)
          + noise
      )
  
      if use_feature_names:
          monotonic_cst = {"f_0": +1, "f_1": -1}
      else:
          monotonic_cst = [+1, -1]
  
      gbdt = HistGradientBoostingRegressor(monotonic_cst=monotonic_cst)
      gbdt.fit(X, y)
  
      linspace = np.linspace(0, 1, 100)
      sin = np.sin(linspace)
      constant = np.full_like(linspace, fill_value=0.5)
  
      # We now assert the predictions properly respect the constraints, on each
      # feature. When testing for a feature we need to set the other one to a
      # constant, because the monotonic constraints are only a "all else being
      # equal" type of constraints:
      # a constraint on the first feature only means that
      # x0 < x0' => f(x0, x1) < f(x0', x1)
      # while x1 stays constant.
      # The constraint does not guanrantee that
      # x0 < x0' => f(x0, x1) < f(x0', x1')
  
      # First feature (POS)
      # assert pred is all increasing when f_0 is all increasing
      X = np.c_[linspace, constant]
      X = _convert_container(
          X, constructor_name, columns_name=columns_name
      )
      pred = gbdt.predict(X)
      assert is_increasing(pred)
      # assert pred actually follows the variations of f_0
      X = np.c_[sin, constant]
      X = _convert_container(
          X, constructor_name, columns_name=columns_name
      )
      pred = gbdt.predict(X)
      assert np.all((np.diff(pred) >= 0) == (np.diff(sin) >= 0))
  
      # Second feature (NEG)
      # assert pred is all decreasing when f_1 is all increasing
      X = np.c_[constant, linspace]
      X = _convert_container(
          X, constructor_name, columns_name=columns_name
      )
      pred = gbdt.predict(X)
      assert is_decreasing(pred)
      # assert pred actually follows the inverse variations of f_1
      X = np.c_[constant, sin]
      X = _convert_container(
          X, constructor_name, columns_name=columns_name
      )
      pred = gbdt.predict(X)
      assert ((np.diff(pred) <= 0) == (np.diff(sin) >= 0)).all()
  
file_path: scikit-learn/sklearn/ensemble/_hist_gradient_boosting/tests/test_monotonic_contraints.py
imports: import re
  import numpy
  import pytest
  from sklearn.ensemble import HistGradientBoostingClassifier, HistGradientBoostingRegressor
  from sklearn.ensemble._hist_gradient_boosting.common import G_H_DTYPE, X_BINNED_DTYPE, MonotonicConstraint
  from sklearn.ensemble._hist_gradient_boosting.grower import TreeGrower
  from sklearn.ensemble._hist_gradient_boosting.histogram import HistogramBuilder
  from sklearn.ensemble._hist_gradient_boosting.splitting import Splitter, compute_node_value
  from sklearn.utils._openmp_helpers import _openmp_effective_n_threads
  from sklearn.utils._testing import _convert_container
label_desc: Use image node_id 7 for calling a global function with example usage: test_predictions(global_random_seed, use_feature_names) without return types