baotrung217

MapFeature

Dec 25th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. def mapFeature(x1, x2):
  2.    out = np.ones((x1.shape[0], 1))
  3.    for i in range(1, degree+1):
  4.       for j in range(i+1):
  5.          term1 = x1 ** (i-j)
  6.          term2 = x2 ** (j)
  7.          term  = (term1 * term2).reshape( term1.shape[0], 1 )
  8.          out   = np.hstack(( out, term ))
  9.    return out
  10.  
  11. fig, ax = plt.subplots(figsize=(10, 8))
  12. ax.scatter(positive['Test 1'], positive['Test 2'], c='b', marker='o', label='Accepted')
  13. ax.scatter(negative['Test 1'], negative['Test 2'], c='r', marker='x', label='Rejected')
  14. x1 = np.linspace(-1, 1.2)
  15. x2 = np.linspace(-1, 1.2)
  16. Z = np.zeros((len(x1), len(x2)))
  17. #Z = np.zeros(len(x1), len(x2))
  18. for i in range(len(x1)):
  19.    for j in range(len(x2)):
  20.       myfeatureij = mapFeature(np.array([x1[i]]), np.array([x2[j]]))
  21.       Z[i,j] = np.dot(myfeatureij, result[0])
  22.      
  23. Z = Z.transpose()
  24. ax.contour(x1, x2, Z, 0, linewidths=2, colors='g')
  25. ax.legend()
  26. ax.grid()
  27. ax.set_xlabel('Microchip Test 1')
  28. ax.set_ylabel('Microchip Test 2')
Advertisement
Add Comment
Please, Sign In to add comment