code: def test_classification():
      fake_raw_data = [create_epoch(i, 5) for i in range(20)]
      labels = [
          0,
          1,
          0,
          1,
          0,
          1,
          0,
          1,
          0,
          1,
          0,
          1,
          0,
          1,
          0,
          1,
          0,
          1,
          0,
          1,
      ]
      # 5 subjects, 4 epochs per subject
      epochs_per_subj = 4
      # svm
      svm_clf = svm.SVC(
          kernel="precomputed", shrinking=False, C=1, gamma="auto"
      )
      training_data = fake_raw_data[0:12]
      clf = Classifier(svm_clf, epochs_per_subj=epochs_per_subj)
      clf.fit(list(zip(training_data, training_data)), labels[0:12])
      expected_confidence = np.array(
          [
              -1.18234421,
              0.97403604,
              -1.04005679,
              0.92403019,
              -0.95567738,
              1.11746593,
              -0.83275891,
              0.9486868,
          ]
      )
      recomputed_confidence = clf.decision_function(
          list(zip(fake_raw_data[12:], fake_raw_data[12:]))
      )
      hamming_distance = (
          hamming(
              np.sign(expected_confidence),
              np.sign(recomputed_confidence),
          )
          * expected_confidence.size
      )
      assert hamming_distance <= 1, (
          "decision function of SVM with recomputation "
          "does not provide correct results"
      )
      y_pred = clf.predict(
          list(zip(fake_raw_data[12:], fake_raw_data[12:]))
      )
      expected_output = [0, 0, 0, 1, 0, 1, 0, 1]
      hamming_distance = hamming(y_pred, expected_output) * len(y_pred)
      assert (
          hamming_distance <= 1
      ), "classification via SVM does not provide correct results"
      confidence = clf.decision_function(
          list(zip(fake_raw_data[12:], fake_raw_data[12:]))
      )
      hamming_distance = (
          hamming(np.sign(expected_confidence), np.sign(confidence))
          * confidence.size
      )
      assert hamming_distance <= 1, (
          "decision function of SVM without recomputation "
          "does not provide correct results"
      )
      y = [0, 1, 0, 1, 0, 1, 0, 1]
      score = clf.score(
          list(zip(fake_raw_data[12:], fake_raw_data[12:])), y
      )
      assert np.isclose([hamming(y_pred, y)], [1 - score])[
          0
      ], "the prediction score is incorrect"
      # svm with partial similarity matrix computation
      clf = Classifier(
          svm_clf,
          num_processed_voxels=2,
          epochs_per_subj=epochs_per_subj,
      )
      clf.fit(
          list(zip(fake_raw_data, fake_raw_data)),
          labels,
          num_training_samples=12,
      )
      y_pred = clf.predict()
      expected_output = [0, 0, 0, 1, 0, 1, 0, 1]
      hamming_distance = hamming(y_pred, expected_output) * len(y_pred)
      assert hamming_distance <= 1, (
          "classification via SVM (partial sim) does not "
          "provide correct results"
      )
      confidence = clf.decision_function()
      hamming_distance = (
          hamming(np.sign(expected_confidence), np.sign(confidence))
          * confidence.size
      )
      assert hamming_distance <= 1, (
          "decision function of SVM (partial sim) without recomputation "
          "does not provide correct results"
      )
      # logistic regression
      lr_clf = LogisticRegression()
      clf = Classifier(lr_clf, epochs_per_subj=epochs_per_subj)
      clf.fit(list(zip(training_data, training_data)), labels[0:12])
      expected_confidence = np.array(
          [
              -4.49666484,
              3.73025553,
              -4.04181695,
              3.73027436,
              -3.77043872,
              4.42613412,
              -3.35616616,
              3.77716609,
          ]
      )
      recomputed_confidence = clf.decision_function(
          list(zip(fake_raw_data[12:], fake_raw_data[12:]))
      )
      hamming_distance = (
          hamming(
              np.sign(expected_confidence),
              np.sign(recomputed_confidence),
          )
          * expected_confidence.size
      )
      assert hamming_distance <= 1, (
          "decision function of logistic regression with recomputation "
          "does not provide correct results"
      )
      y_pred = clf.predict(
          list(zip(fake_raw_data[12:], fake_raw_data[12:]))
      )
      expected_output = [0, 0, 0, 1, 0, 1, 0, 1]
      hamming_distance = hamming(y_pred, expected_output) * len(y_pred)
      assert hamming_distance <= 1, (
          "classification via logistic regression "
          "does not provide correct results"
      )
      confidence = clf.decision_function(
          list(zip(fake_raw_data[12:], fake_raw_data[12:]))
      )
      hamming_distance = (
          hamming(np.sign(expected_confidence), np.sign(confidence))
          * confidence.size
      )
      assert hamming_distance <= 1, (
          "decision function of logistic regression without precomputation "
          "does not provide correct results"
      )
  
file_path: brainiak/tests/fcma/test_classification.py
imports: from brainiak.fcma.classifier import Classifier
  from scipy.stats.mstats import zscore
  from sklearn import svm
  from sklearn.linear_model import LogisticRegression
  import numpy
  import math
  from numpy.random import RandomState
  from scipy.spatial.distance import hamming
label_desc: Use image node_id 2 for calling a global function with example usage: test_classification() without return types