code: def test_linearity_measure_reg(
      method, epsilon, res, nb_instances, agg
  ):
      diabetes = load_diabetes()
      X_train, y_train = diabetes.data, diabetes.target
      x = X_train[0:nb_instances].reshape(nb_instances, -1)
  
      lg = LinearRegression()
      lg.fit(X_train, y_train)
      svr = SVR(kernel="linear")
      svr.fit(X_train, y_train)
  
      def predict_fn_svr(x):
          return svr.predict(x)
  
      def predict_fn(x):
          return lg.predict(x)
  
      lin = linearity_measure(
          predict_fn,
          x,
          method=method,
          epsilon=epsilon,
          X_train=X_train,
          res=res,
          model_type="regressor",
          agg=agg,
      )
      assert lin.shape[0] == nb_instances, "Checking shapes"
      assert (lin >= 0).all(), "Linearity measure must be >= 0"
      assert np.allclose(lin, np.zeros(lin.shape))
  
      lin_svr = linearity_measure(
          predict_fn_svr,
          x,
          method=method,
          epsilon=epsilon,
          X_train=X_train,
          res=res,
          model_type="regressor",
          agg=agg,
      )
      assert lin_svr.shape[0] == nb_instances, "Checking shapes"
      assert (lin_svr >= 0).all(), "Linearity measure must be >= 0"
  
      feature_range = [[0, 1] for _ in range(X_train.shape[1])]
      lin_2 = linearity_measure(
          predict_fn,
          x,
          method="grid",
          epsilon=epsilon,
          feature_range=feature_range,
          res=res,
          model_type="regressor",
          agg=agg,
      )
      assert lin_2.shape[0] == nb_instances, "Checking shapes"
      assert (lin_2 >= 0).all(), "Linearity measure must be >= 0"
      assert np.allclose(lin_2, np.zeros(lin_2.shape))
  
      feature_range = [[0, 1] for _ in range(X_train.shape[1])]
      lin_2_svr = linearity_measure(
          predict_fn_svr,
          x,
          method="grid",
          epsilon=epsilon,
          feature_range=feature_range,
          res=res,
          model_type="regressor",
          agg=agg,
      )
      assert lin_2_svr.shape[0] == nb_instances, "Checking shapes"
      assert (lin_2_svr >= 0).all(), "Linearity measure must be >= 0"
  
      y_train_multi = np.stack((y_train, y_train), axis=1)
      lg_multi = LinearRegression()
      lg_multi.fit(X_train, y_train_multi)
  
      def predict_fn_multi(x):
          return lg_multi.predict(x)
  
      lm_multi = LinearityMeasure(
          method=method,
          epsilon=epsilon,
          res=res,
          model_type="regressor",
          agg=agg,
      )
      lm_multi.fit(X_train)
      lin_multi = lm_multi.score(predict_fn_multi, x)
      assert lin_multi.shape[0] == nb_instances, "Checking shapes"
      assert (lin_multi >= 0).all(), "Linearity measure must be >= 0"
      assert np.allclose(lin_multi, np.zeros(lin_multi.shape))
  
file_path: alibi/alibi/confidence/tests/test_model_linearity.py
imports: import pytest
  import numpy
  from sklearn.datasets import load_iris, load_diabetes
  from sklearn.linear_model import LogisticRegression, LinearRegression
  from sklearn.svm import SVR
  from alibi.confidence.model_linearity import linearity_measure, LinearityMeasure
  from alibi.confidence.model_linearity import _linear_superposition, _sample_grid, _sample_knn
  from functools import reduce
label_desc: Use image node_id 5 for calling a global function with example usage: test_linearity_measure_reg(method, epsilon, res, nb_instances, agg) and returns: svr, lg, lg_multi