docstr: Fit the detector on reference data.
  
  In the linear case we compute the principal components of the reference data using the
  covariance matrix and then remove the largest `n_components` eigenvectors. The remaining
  eigenvectors correspond to the invariant dimensions of the data. Changes in these
  dimensions are used to compute the outlier score which is the distance to the principal
  subspace spanned by the first `n_components` eigenvectors.
  
  In the kernel case we compute the principal components of the reference data using the
  kernel matrix and then return the largest `n_components` eigenvectors. These are then
  normalized to have length equal to `1/eigenvalue`. Note that this differs from the
  linear case where we remove the largest eigenvectors.
  
  In both cases we then store the computed components to use later when we score test
  instances.
  
  Parameters
  ----------
  x_ref
      Reference data used to fit the detector.
  
  Raises
  ------
  ValueError
      If using linear pca variant and `n_components` is greater than or equal to number of
      features or if using kernel pca variant and `n_components` is greater than or equal
      to number of instances.
docstr_tok: ["Fit","the","detector","on","reference","data",".","In","the","linear","case","we","compute","the","principal","components","of","the","reference","data","using","the","covariance","matrix","and","then","remove","the","largest","`","n_components","`","eigenvectors",".","The","remaining","eigenvectors","correspond","to","the","invariant","dimensions","of","the","data",".","Changes","in","these","dimensions","are","used","to","compute","the","outlier","score","which","is","the","distance","to","the","principal","subspace","spanned","by","the","first","`","n_components","`","eigenvectors",".","In","the","kernel","case","we","compute","the","principal","components","of","the","reference","data","using","the","kernel","matrix","and","then","return","the","largest","`","n_components","`","eigenvectors",".","These","are","then","normalized","to","have","length","equal","to","`","1\/eigenvalue","`",".","Note","that","this","differs","from","the","linear","case","where","we","remove","the","largest","eigenvectors",".","In","both","cases","we","then","store","the","computed","components","to","use","later","when","we","score","test","instances",".","Parameters","--","--","--","--","--","x_ref","Reference","data","used","to","fit","the","detector",".","Raises","--","--","--","ValueError","If","using","linear","pca","variant","and","`","n_components","`","is","greater","than","or","equal","to","number","of","features","or","if","using","kernel","pca","variant","and","`","n_components","`","is","greater","than","or","equal","to","number","of","instances","."]
code: def fit(self, x_ref: np.ndarray) -> None:
      """Fit the detector on reference data.
  
      In the linear case we compute the principal components of the reference data using the
      covariance matrix and then remove the largest `n_components` eigenvectors. The remaining
      eigenvectors correspond to the invariant dimensions of the data. Changes in these
      dimensions are used to compute the outlier score which is the distance to the principal
      subspace spanned by the first `n_components` eigenvectors.
  
      In the kernel case we compute the principal components of the reference data using the
      kernel matrix and then return the largest `n_components` eigenvectors. These are then
      normalized to have length equal to `1/eigenvalue`. Note that this differs from the
      linear case where we remove the largest eigenvectors.
  
      In both cases we then store the computed components to use later when we score test
      instances.
  
      Parameters
      ----------
      x_ref
          Reference data used to fit the detector.
  
      Raises
      ------
      ValueError
          If using linear pca variant and `n_components` is greater than or equal to number of
          features or if using kernel pca variant and `n_components` is greater than or equal
          to number of instances.
      """
      self.backend.fit(self.backend._to_backend_dtype(x_ref))
  
file_path: alibi-detect/alibi_detect/od/_pca.py
imports: from typing import Union, Optional, Callable, Dict, Any
  from typing_extensions import Literal
  import numpy
  from alibi_detect.base import outlier_prediction_dict
  from alibi_detect.base import BaseDetector, ThresholdMixin, FitMixin
  from alibi_detect.od.pytorch import KernelPCATorch, LinearPCATorch
  from alibi_detect.utils.frameworks import BackendValidator
  from alibi_detect.version import __version__
  from alibi_detect.exceptions import _catch_error
  from alibi_detect.utils._types import TorchDeviceType
label_desc: Use image node_id 2 for calling the PCA obj's underlying member method code with example usage: obj.fit(x_ref) without return types