统计学习方法第14章作业:层次聚类聚合/分裂算法和K-means代码实现
发布时间
阅读量:
阅读量
层次聚类算法的聚合与分裂机制
import numpy as np
import copy
import matplotlib.pyplot as plt
class Hierarchical_cluster:
def __init__(self,k=None,p=2,dis_way='min',c_way='agg'):
self.k = k
self.p = p
self.dis_way = dis_way
self.c_way = c_way
def cauclate_dis(self, x1, x2):
return np.sum(abs(x1 - x2) ** self.p) ** (1 / self.p)
def create_D_matrix(self):
self.D = np.zeros((self.n,self.n))
for i in range(self.n):
for j in range(self.n):
if i==j:
self.
全部评论 (0)
还没有任何评论哟~
