Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def mapFeature(x1, x2):
- out = np.ones((x1.shape[0], 1))
- for i in range(1, degree+1):
- for j in range(i+1):
- term1 = x1 ** (i-j)
- term2 = x2 ** (j)
- term = (term1 * term2).reshape( term1.shape[0], 1 )
- out = np.hstack(( out, term ))
- return out
- fig, ax = plt.subplots(figsize=(10, 8))
- ax.scatter(positive['Test 1'], positive['Test 2'], c='b', marker='o', label='Accepted')
- ax.scatter(negative['Test 1'], negative['Test 2'], c='r', marker='x', label='Rejected')
- x1 = np.linspace(-1, 1.2)
- x2 = np.linspace(-1, 1.2)
- Z = np.zeros((len(x1), len(x2)))
- #Z = np.zeros(len(x1), len(x2))
- for i in range(len(x1)):
- for j in range(len(x2)):
- myfeatureij = mapFeature(np.array([x1[i]]), np.array([x2[j]]))
- Z[i,j] = np.dot(myfeatureij, result[0])
- Z = Z.transpose()
- ax.contour(x1, x2, Z, 0, linewidths=2, colors='g')
- ax.legend()
- ax.grid()
- ax.set_xlabel('Microchip Test 1')
- ax.set_ylabel('Microchip Test 2')
Advertisement
Add Comment
Please, Sign In to add comment