code: import matplotlib.image as mpimg
  import matplotlib.pyplot as plt
  import numpy as np
  import cv2
  import glob
  import time
  from sklearn.svm import LinearSVC
  from sklearn.preprocessing import StandardScaler
  from extract_feature import *
  # NOTE: the next import is only valid for scikit-learn version <= 0.17
  # for scikit-learn >= 0.18 use:
  # from sklearn.model_selection import train_test_split
  from sklearn.cross_validation import train_test_split
  import pickle
  
  
  # Read in cars and notcars
  cars = glob.glob('./train_data/vehicles/*/*.png'); train_data_tpye = 'png'; notcars = glob.glob('./train_data/non-vehicles/*/*.png')
  #cars = glob.glob('./hog_test_imgs/vehicles_smallset/*/*.jpeg'); train_data_tpye = 'jpeg'; #notcars = glob.glob('./hog_test_imgs/non-vehicles_smallset/*/*.jpeg')
  sample_size = None
  cars = cars[0:sample_size]
  notcars = notcars[0:sample_size]
  
  color_space = 'YCrCb' # Can be RGB, HSV, LUV, HLS, YUV, YCrCb
  orient = 9  # HOG orientations
  pix_per_cell = 8 # HOG pixels per cell
  cell_per_block = 2 # HOG cells per block
  hog_channel = "ALL" # Can be 0, 1, 2, or "ALL"
  spatial_size = (32, 32) # Spatial binning dimensions
  hist_bins = 32    # Number of histogram bins
  spatial_feat = True # Spatial features on or off
  hist_feat = True # Histogram features on or off
  hog_feat = True # HOG features on or off
  y_start_stop = [None, None] # Min and max in y to search in slide_window()
  
  t = time.time()
  print("start extract car_features")
  car_features = extract_features(cars, train_data_tpye, color_space=color_space, 
                          spatial_size=spatial_size, hist_bins=hist_bins, 
                          orient=orient, pix_per_cell=pix_per_cell, 
                          cell_per_block=cell_per_block, 
                          hog_channel=hog_channel, spatial_feat=spatial_feat, 
                          hist_feat=hist_feat, hog_feat=hog_feat)
  print("start extract notcar_features")
  notcar_features = extract_features(notcars, train_data_tpye, color_space=color_space, 
                          spatial_size=spatial_size, hist_bins=hist_bins, 
                          orient=orient, pix_per_cell=pix_per_cell, 
                          cell_per_block=cell_per_block, 
                          hog_channel=hog_channel, spatial_feat=spatial_feat, 
                          hist_feat=hist_feat, hog_feat=hog_feat)
                          
  X = np.vstack((car_features, notcar_features)).astype(np.float64)
  
  # Define the labels vector
  y = np.hstack((np.ones(len(car_features)), np.zeros(len(notcar_features))))
  
  # Split up data into randomized training and test sets
  rand_state = np.random.randint(0, 100)
  X_train, X_test, y_train, y_test = train_test_split(
      X, y, test_size=0.2, random_state=rand_state)
  
  t2 = time.time()
  print(round(t2-t, 2), 'Seconds to extract features SVC...')
      
  print("X_train shape: {} \X_test shape: {}".format(X_train.shape, X_test.shape))
      
  # Fit a per-column scaler
  X_scaler = StandardScaler().fit(X_train)
  # Apply the scaler to X
  X_train = X_scaler.transform(X_train)
  X_test = X_scaler.transform(X_test)
  
  print('Using:',orient,'orientations',pix_per_cell,
      'pixels per cell and', cell_per_block,'cells per block')
  print('Feature vector length:', len(X_train[0]))
  # Use a linear SVC 
  svc = LinearSVC()
  t=time.time()
  svc.fit(X_train, y_train)
  t2 = time.time()
  print(round(t2-t, 2), 'Seconds to train SVC...')
  
  # Check the score of the SVC
  print('Test Accuracy of SVC = ', round(svc.score(X_test, y_test), 4))
  
  # pickle SVC
  pickle_file = 'svc_acc_%f.p'%round(svc.score(X_test, y_test), 4)
  try:
      with open(pickle_file, 'wb') as pfile:
          pickle.dump(
                  {
                      'svc': svc,
                      'scaler': X_scaler,
                      'color_space': color_space,
                      'orient': orient,
                      'pix_per_cell': pix_per_cell,
                      'cell_per_block': cell_per_block,
                      'spatial_size': spatial_size,
                      'hist_bins': hist_bins,
                      'spatial_feat': spatial_feat,
                      'hist_feat': hist_feat,
                  },
                  pfile, pickle.HIGHEST_PROTOCOL)
  except Exception as e:
      print('Unable to save data to', pickle_file, ':', e)
      raise
apis: numpy.vstack sklearn.svm.LinearSVC sklearn.cross_validation.train_test_split sklearn.preprocessing.StandardScaler numpy.random.randint