docstr: Parameters
  ----------
  predict_fn
      Prediction function.
  x
      Instance of interest.
  
  Returns
  -------
  Linearity measure.
docstr_tok: ["Parameters","--","--","--","--","--","predict_fn","Prediction","function",".","x","Instance","of","interest",".","Returns","--","--","--","-","Linearity","measure","."]
code: def score(self, predict_fn: Callable, x: np.ndarray) -> np.ndarray:
      """
  
      Parameters
      ----------
      predict_fn
          Prediction function.
      x
          Instance of interest.
  
      Returns
      -------
      Linearity measure.
  
      """
      input_shape = x.shape[1:]
  
      if self.is_fit:
          assert input_shape == self.input_shape
  
      if self.method == "knn":
          if not self.is_fit:
              raise ValueError(
                  "Method 'knn' cannot be used without calling fit()."
              )
          lin = _linearity_measure(
              predict_fn,
              x,
              X_train=self.X_train,
              feature_range=None,
              method=self.method,
              nb_samples=self.nb_samples,
              res=self.res,
              epsilon=self.epsilon,
              alphas=self.alphas,
              model_type=self.model_type,
              agg=self.agg,
          )
      elif self.method == "grid":
          if not self.is_fit:
              self.feature_range = np.asarray(
                  [[0, 1]] * x.shape[1]
              )  # hardcoded (e.g. from 0 to 1)
          lin = _linearity_measure(
              predict_fn,
              x,
              X_train=None,
              feature_range=self.feature_range,
              method=self.method,
              nb_samples=self.nb_samples,
              res=self.res,
              epsilon=self.epsilon,
              alphas=self.alphas,
              model_type=self.model_type,
              agg=self.agg,
          )
      else:
          raise ValueError(
              'Method not understood. Supported methods: "knn", "grid"'
          )
  
      return lin
  
file_path: alibi/alibi/confidence/model_linearity.py
imports: import logging
  import string
  from time import time
  from typing import Callable, List, Optional, Tuple, Union
  import numpy
  from numpy.linalg import norm
  from sklearn.neighbors import NearestNeighbors
label_desc: Use image node_id 3 for calling the LinearityMeasure obj's underlying member method code with example usage: obj.score(predict_fn, x) and returns: lin