Лаба 11 сдана
This commit is contained in:
parent
d75f598425
commit
ca3fdf03ca
@ -8,7 +8,6 @@ def get_distance(first: np.ndarray, second: np.ndarray) -> float:
|
||||
return math.sqrt(sum([(first[i] - second[i]) ** 2 for i in range(first.shape[0])])) + 1e-5
|
||||
|
||||
|
||||
# Расчёт степени принадлежности
|
||||
def affiliation_calculation(data: np.ndarray, centers: np.ndarray, k: int, m: int) -> np.ndarray:
|
||||
data_len = data.shape[0]
|
||||
u = np.zeros((data_len, k))
|
||||
@ -22,7 +21,6 @@ def affiliation_calculation(data: np.ndarray, centers: np.ndarray, k: int, m: in
|
||||
return u
|
||||
|
||||
|
||||
# Расчёт отклонения
|
||||
def variance_calculation(data: np.ndarray, centers: np.ndarray, u: np.ndarray) -> float:
|
||||
value = 0
|
||||
for j in range(k):
|
||||
@ -31,7 +29,6 @@ def variance_calculation(data: np.ndarray, centers: np.ndarray, u: np.ndarray) -
|
||||
return value
|
||||
|
||||
|
||||
# Обновление центров кластеров
|
||||
def center_update(data: np.ndarray, u: np.ndarray, k: int, m: int) -> np.ndarray:
|
||||
centers = np.zeros((k, data.shape[1]))
|
||||
for j in range(k):
|
||||
@ -63,7 +60,6 @@ def fuzzy_c_means(data: np.ndarray, k: int, m: int, max_iter: int = 100, tol: fl
|
||||
return centers, u, value
|
||||
|
||||
|
||||
# Работа с plt для визуализации результата
|
||||
def visualise_resout(centers: np.ndarray, u: np.ndarray):
|
||||
center_colors = [[random.random(), random.random(), random.random()] for i in range(k)]
|
||||
point_colors = []
|
||||
@ -78,7 +74,6 @@ def visualise_resout(centers: np.ndarray, u: np.ndarray):
|
||||
plt.title("Нечёткая кластеризация")
|
||||
plt.xlabel("Размер зарплаты")
|
||||
|
||||
# Визуализация
|
||||
if data.shape[1] == 1:
|
||||
plt.scatter(data[:, 0], [0] * data.shape[0], c=point_colors)
|
||||
plt.scatter(centers[:, 0], [0] * centers.shape[0], marker='*', edgecolor='black', s=100, c=center_colors)
|
||||
|
Loading…
Reference in New Issue
Block a user