内容:根据作业题目给出的高维空间坐标数据,做聚类分析
durudataset.txt如下:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def load_dataset(name):
return np.loadtxt(name)
def euclidian(a, b):
return np.linalg.norm(a-b)
def plot(dataset, history_centroids, belongs_to):
colors = ['r', 'g']
fig, ax = plt.subplots()
for index in range(dataset.shape[0]):
instances_close = [i for i in range(len(belongs_to)) if belongs_to[i] == index]
for instance_index in instances_close:
ax.plot(dataset[instance_index][0], dataset[instance_index][1], (colors[index] + 'o'))
history_points = []
for index, centroids in enumerate(history_centroids):
for inner, item in enumerate(centroids):