docstr: PyTorch backend for PCA detector.
  
  Parameters
  ----------
  n_components:
      The number of dimensions in the principal subspace. For linear PCA should have
      ``1 <= n_components < dim(data)``. For kernel pca should have ``1 <= n_components < len(data)``.
  device
      Device type used. The default tries to use the GPU and falls back on CPU if needed.
      Can be specified by passing either ``'cuda'``, ``'gpu'``, ``'cpu'`` or an instance of
      ``torch.device``.
  
  Raises
  ------
  ValueError
      If `n_components` is less than 1.
docstr_tok: ["PyTorch","backend","for","PCA","detector",".","Parameters","--","--","--","--","--","n_components",":","The","number","of","dimensions","in","the","principal","subspace",".","For","linear","PCA","should","have","``","1","<","=","n_components","<","dim","(","data",")","``",".","For","kernel","pca","should","have","``","1","<","=","n_components","<","len","(","data",")","``",".","device","Device","type","used",".","The","default","tries","to","use","the","GPU","and","falls","back","on","CPU","if","needed",".","Can","be","specified","by","passing","either","``","'cuda","'","``",",","``","'gpu","'","``",",","``","'cpu","'","``","or","an","instance","of","``","torch.device","``",".","Raises","--","--","--","ValueError","If","`","n_components","`","is","less","than","1","."]
code: def __init__(
      self,
      n_components: int,
      device: TorchDeviceType = None,
  ):
      """PyTorch backend for PCA detector.
  
      Parameters
      ----------
      n_components:
          The number of dimensions in the principal subspace. For linear PCA should have
          ``1 <= n_components < dim(data)``. For kernel pca should have ``1 <= n_components < len(data)``.
      device
          Device type used. The default tries to use the GPU and falls back on CPU if needed.
          Can be specified by passing either ``'cuda'``, ``'gpu'``, ``'cpu'`` or an instance of
          ``torch.device``.
  
      Raises
      ------
      ValueError
          If `n_components` is less than 1.
      """
      super().__init__(device=device)
      self.n_components = n_components
  
      if n_components < 1:
          raise ValueError("n_components must be at least 1")
  
imports: from typing import Optional, Callable
  import torch
  from alibi_detect.od.pytorch.base import TorchOutlierDetector
  from alibi_detect.utils._types import TorchDeviceType
label_desc: Use image node_id 1 to create a new PCATorch object from inherited base classes: TorchOutlierDetector with example: obj = PCATorch(n_components, device)