Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
utils: add HW8_Q4.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tiankaima committed May 31, 2024
1 parent 3bd2b09 commit b5b2532
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions utils/HW8_Q4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import numpy as np
import matplotlib.pyplot as plt

x = np.array([[1, 2], [2, 3], [3, 3], [2, 1], [3, 2]])
y = np.array([1, 1, 1, -1, -1])

plt.scatter(x[y == 1, 0], x[y == 1, 1], c='r', label='positive')
plt.scatter(x[y == -1, 0], x[y == -1, 1], c='b', label='negative')

w = np.array([-1, 2])
b = -2

x1 = np.linspace(0, 4, 100)
x2 = (-w[0] * x1 - b) / w[1]

plt.plot(x1, x2, label='separating hyperplane')

plt.fill_between(x1, x2 - 1 / np.linalg.norm(w), x2 + 1 / np.linalg.norm(w), alpha=0.5, label='margin boundary')

plt.legend()
plt.show()

0 comments on commit b5b2532

Please sign in to comment.