Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib import style
  4.  
  5. style.use("ggplot")
  6. from sklearn import svm
  7.  
  8. x = [1, 5, 1.5, 8, 1, 9]
  9. y = [2, 8, 1.8, 8, 0.6, 11]
  10.  
  11. plt.scatter(x,y)
  12. plt.show()
  13.  
  14. X = np.array([[1,2],
  15. [5,8],
  16. [1.5,1.8],
  17. [8,8],
  18. [1,0.6],
  19. [9,11]])
  20.  
  21. y = [0,1,0,1,0,1]
  22.  
  23. clf = svm.SVC(kernel='linear', C = 1.0)
  24. clf.fit(X,y)
  25.  
  26. test = np.array([0.58, 0.76])
  27. print(test) # Produces: [ 0.58 0.76]
  28. print(test.shape) # Produces: (2,) meaning 2 rows, 1 col
  29.  
  30. test = test.reshape(1, -1)
  31. print(test) # Produces: [[ 0.58 0.76]]
  32. print(test.shape) # Produces (1, 2) meaning 1 row, 2 cols
  33.  
  34. print(clf.predict(test)) # Produces [0], as expected
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement