title: How to get the confidence of svm algorithm in sklearn using python
body: <p>I want to get the confidence but when I try <code>clf.score(X_test)</code> I get the following error: </p>
  
  <blockquote>
    <p>TypeError: score() takes at least 3 arguments (2 given)</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre><code>import cv2, os
  from numpy import *
  import numpy as np
  from PIL import Image
  from sklearn.decomposition import PCA
  from sklearn.decomposition import RandomizedPCA
  from sklearn.naive_bayes import GaussianNB
  import matplotlib.pyplot as plt
  from sklearn.svm import SVC
  
  cascadeLocation = "haarcascade_frontalface_default.xml"
  faceCascade = cv2.CascadeClassifier(cascadeLocation)
  
  def prepare_dataset(directory):
      paths = [os.path.join(directory, filename) for filename in os.listdir(directory)]
      images = []
      labels = []
      row = 140
      col = 140
      for image_path in paths:
  
          image_pil = Image.open(image_path).convert('L')
  
          image = np.array(image_pil, 'uint8')
          nbr = int(os.path.split(image_path)[-1].split('.')[1])
          print(nbr)
          faces = faceCascade.detectMultiScale(image)
          for (x,y,w,h) in faces:
              images.append(image[y:y+col,x:x+row])
              labels.append(nbr)
              cv2.imshow("Reading Faces ",image[y:y+col,x:x+row])
              cv2.waitKey(50)
      return images,labels, row, col
  
  directory = 'dataset'
  directory2 = 'dataset2'
  images, labels, row, col = prepare_dataset(directory)
  
  n_components = 10
  cv2.destroyAllWindows()
  pca = PCA(n_components=n_components, whiten=True)
  
  param_grid = {'C': [1e3, 5e3, 1e4, 5e4, 1e5],
                'gamma': [0.0001, 0.0005, 0.001, 0.005, 0.01, 0.1], }
  clf = SVC(kernel='rbf', class_weight='balanced')
  
  testing_data = []
  for i in range(len(images)):
      testing_data.append(images[i].flatten())
  pca = pca.fit(testing_data)
  
  transformed = pca.transform(testing_data)
  clf.fit(transformed,labels)
  
  image_paths = [os.path.join(directory2, filename) for filename in os.listdir(directory2)]
  la=[]
  for image_path in image_paths:
      pred_image_pil = Image.open(image_path).convert('L')
  
      pred_image = np.array(pred_image_pil, 'uint8')
  
      faces = faceCascade.detectMultiScale(pred_image)
      for (x,y,w,h) in faces:
          temp=np.array(pred_image[y:y+col,x:x+row]).reshape((1, -1))
  
          X_test = pca.transform(temp)
  
          id = clf.predict(X_test)
          #a=clf.score(X_test)            
          if(id==1):
              id="john"
          elif(id==2):
              id="brad"
          elif(id==3):
              id="scr"
          elif(id==4):
              id="natalie portman"
          elif(id==5):
              id="jennifer lawrence"
          elif(id==6):
              id="van diesel"
          elif(id==7):
              id="jennifer aniston"
          elif(id==8):
              id="leonardo dicaprio"    
          else :
              id="unknown"
          print(id)               
          cv2.imshow("Recognizing Face", pred_image[y: y + h, x: x + w])
          cv2.waitKey(1000)
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>I also tried <code>clf.score(X_test,id)</code>. In this case all confidence takes the value <code>1.0</code>.</p>