code: def test_kneighbors_regressor():
      # Test chaining KNeighborsTransformer and classifiers/regressors
      rng = np.random.RandomState(0)
      X = 2 * rng.rand(40, 5) - 1
      X2 = 2 * rng.rand(40, 5) - 1
      y = rng.rand(40, 1)
  
      n_neighbors = 12
      radius = 1.5
      # We precompute more neighbors than necessary, to have equivalence between
      # k-neighbors estimator after radius-neighbors transformer, and vice-versa.
      factor = 2
  
      k_trans = KNeighborsTransformer(
          n_neighbors=n_neighbors, mode="distance"
      )
      k_trans_factor = KNeighborsTransformer(
          n_neighbors=int(n_neighbors * factor), mode="distance"
      )
  
      r_trans = RadiusNeighborsTransformer(
          radius=radius, mode="distance"
      )
      r_trans_factor = RadiusNeighborsTransformer(
          radius=int(radius * factor), mode="distance"
      )
  
      k_reg = KNeighborsRegressor(n_neighbors=n_neighbors)
      r_reg = RadiusNeighborsRegressor(radius=radius)
  
      test_list = [
          (k_trans, k_reg),
          (k_trans_factor, r_reg),
          (r_trans, r_reg),
          (r_trans_factor, k_reg),
      ]
  
      for trans, reg in test_list:
          # compare the chained version and the compact version
          reg_compact = clone(reg)
          reg_precomp = clone(reg)
          reg_precomp.set_params(metric="precomputed")
  
          reg_chain = make_pipeline(clone(trans), reg_precomp)
  
          y_pred_chain = reg_chain.fit(X, y).predict(X2)
          y_pred_compact = reg_compact.fit(X, y).predict(X2)
          assert_array_almost_equal(y_pred_chain, y_pred_compact)
  
file_path: scikit-learn/sklearn/neighbors/tests/test_neighbors_pipeline.py
imports: import numpy
  from sklearn.base import clone
  from sklearn.cluster import DBSCAN, SpectralClustering
  from sklearn.cluster.tests.common import generate_clustered_data
  from sklearn.datasets import make_blobs
  from sklearn.manifold import TSNE, Isomap, SpectralEmbedding
  from sklearn.neighbors import KNeighborsRegressor, KNeighborsTransformer, LocalOutlierFactor, RadiusNeighborsRegressor, RadiusNeighborsTransformer
  from sklearn.pipeline import make_pipeline
  from sklearn.utils._testing import assert_array_almost_equal
label_desc: Use image node_id 8 for calling a global function with example usage: test_kneighbors_regressor() without return types