Advertisement
pavel_ch

Coding Up the SVM Quiz

Oct 29th, 2015
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. import sys
  2. from class_vis import prettyPicture
  3. from prep_terrain_data import makeTerrainData
  4.  
  5. import matplotlib.pyplot as plt
  6. import copy
  7. import numpy as np
  8. import pylab as pl
  9.  
  10.  
  11. features_train, labels_train, features_test, labels_test = makeTerrainData()
  12.  
  13.  
  14. ########################## SVM #################################
  15. ### we handle the import statement and SVC creation for you here
  16. from sklearn.svm import SVC
  17. clf = SVC(kernel="linear")
  18.  
  19.  
  20. #### now your job is to fit the classifier
  21. #### using the training features/labels, and to
  22. #### make a set of predictions on the test data
  23. clf.fit(features_train, labels_train)
  24.  
  25. #### store your predictions in a list named pred
  26. pred = clf.predict(features_test)
  27.  
  28. print pred
  29.  
  30.  
  31.  
  32. from sklearn.metrics import accuracy_score
  33. acc = accuracy_score(pred, labels_test)
  34.  
  35. def submitAccuracy():
  36.     return acc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement