code: def test_pca_scoring(backend_detector):
      """Test Linear and Kernel PCATorch detector backend scoring methods.
  
      Test that the detector correctly detects true outliers and that the correct proportion of in
      distribution data is flagged as outliers.
      """
      pca_torch = backend_detector()
      mean = [8, 8]
      cov = [[2.0, 0.0], [0.0, 1.0]]
      x_ref = torch.tensor(
          np.random.multivariate_normal(mean, cov, 1000)
      )
      pca_torch.fit(x_ref)
  
      x_1 = torch.tensor([[8.0, 8.0]], dtype=torch.float64)
      scores_1 = pca_torch.score(x_1)
  
      x_2 = torch.tensor([[10.0, 8.0]], dtype=torch.float64)
      scores_2 = pca_torch.score(x_2)
  
      x_3 = torch.tensor([[8.0, 20.0]], dtype=torch.float64)
      scores_3 = pca_torch.score(x_3)
  
      # test correct ordering of scores given outlyingness of data
      assert scores_1 < scores_2 < scores_3
  
      # test that detector correctly detects true Outlier
      pca_torch.infer_threshold(x_ref, 0.01)
      x = torch.cat((x_1, x_2, x_3))
      outputs = pca_torch.predict(x)
      assert torch.all(
          outputs.is_outlier == torch.tensor([False, False, True])
      )
      assert torch.all(
          pca_torch(x) == torch.tensor([False, False, True])
      )
  
      # test that 0.01 of the in distribution data is flagged as outliers
      x = torch.tensor(np.random.multivariate_normal(mean, cov, 1000))
      outputs = pca_torch.predict(x)
      assert (outputs.is_outlier.sum() / 1000) - 0.01 < 0.005
  
file_path: alibi-detect/alibi_detect/od/tests/test__pca/test__pca_backend.py
imports: import pytest
  import torch
  import numpy
  from alibi_detect.utils.pytorch.kernels import GaussianRBF
  from alibi_detect.od.pytorch.pca import LinearPCATorch, KernelPCATorch
  from alibi_detect.exceptions import NotFittedError, ThresholdNotInferredError
label_desc: Use image node_id 2 for calling a global function with example usage: test_pca_scoring(backend_detector) without return types