参考网站:https://www.python-course.eu/dividing_lines_between_classes.php
上一节我们可以自动的识别出能够将两个点分开的直线簇,但是我们的目标不是将两个点分开,而是两类点,本节我们就尝试一下由这两个点生成两类点簇,为后续分类做准备。
import numpy as np
import matplotlib.pyplot as plt
def points_within_circle(radius,center=(0,0),number_of_points=100):
center_x, center_y = center
r = radius * np.sqrt(np.random.random((number_of_points,)))
theta = np.random.random((number_of_points,))*2*np.pi
x = center_x + r * np.cos(theta)
y = center_y + r * np.sin(theta)
return x, y
X = np.arange(0, 8)
fig, ax =plt.subplots()
point1_x, point1_y = points_within_circle(2, (6, 2), 100)
point2_x, point2_y = points_within_circle(2, (2, 6), 100)
ax.scatter(point1_x, point1_y, c="red", label="class 1")
ax.scatter(point2_x, point2_y, c="black", label="class 2")
ax.plot(X, X, "g-", linewidth=2)
ax.legend()
ax.grid()
plt.show()