code: def test_value_difference_metric_property(
      dtype, k, r, y_type, encode_label
  ):
      # Check the property of the vdm distance. Let's check the property
      # described in "Improved Heterogeneous Distance Functions", D.R. Wilson and
      # T.R. Martinez, Journal of Artificial Intelligence Research 6 (1997) 1-34
      # https://arxiv.org/pdf/cs/9701101.pdf
      #
      # "if an attribute color has three values red, green and blue, and the
      # application is to identify whether or not an object is an apple, red and
      # green would be considered closer than red and blue because the former two
      # both have similar correlations with the output class apple."
  
      # defined our feature
      X = np.array(
          ["green"] * 10 + ["red"] * 10 + ["blue"] * 10
      ).reshape(-1, 1)
      # 0 - not an apple / 1 - an apple
      y = np.array([1] * 8 + [0] * 5 + [1] * 7 + [0] * 9 + [1])
      y_labels = np.array(["not apple", "apple"], dtype=object)
      y = y_labels[y]
      y = _convert_container(y, y_type)
      if encode_label:
          y = LabelEncoder().fit_transform(y)
  
      encoder = OrdinalEncoder(dtype=dtype)
      X_encoded = encoder.fit_transform(X)
  
      vdm = ValueDifferenceMetric(k=k, r=r)
      vdm.fit(X_encoded, y)
  
      sample_green = encoder.transform([["green"]])
      sample_red = encoder.transform([["red"]])
      sample_blue = encoder.transform([["blue"]])
  
      for sample in (sample_green, sample_red, sample_blue):
          # computing the distance between a sample of the same category should
          # give a null distance
          dist = vdm.pairwise(sample).squeeze()
          assert dist == pytest.approx(0)
  
      # check the property explained in the introduction example
      dist_1 = vdm.pairwise(sample_green, sample_red).squeeze()
      dist_2 = vdm.pairwise(sample_blue, sample_red).squeeze()
      dist_3 = vdm.pairwise(sample_blue, sample_green).squeeze()
  
      # green and red are very close
      # blue is closer to red than green
      assert dist_1 < dist_2
      assert dist_1 < dist_3
      assert dist_2 < dist_3
  
file_path: imbalanced-learn/imblearn/metrics/tests/test_pairwise.py
imports: import numpy
  import pytest
  from sklearn.exceptions import NotFittedError
  from sklearn.preprocessing import LabelEncoder, OrdinalEncoder
  from sklearn.utils._testing import _convert_container
  from imblearn.metrics.pairwise import ValueDifferenceMetric
label_desc: Use image node_id 3 for calling a global function with example usage: test_value_difference_metric_property(dtype, k, r, y_type, encode_label) without return types