美文网首页
clustering 聚类分析

clustering 聚类分析

作者: 你的仙女本仙 | 来源:发表于2020-03-06 11:21 被阅读0次


系统聚类分析

参考文献:https://blog.csdn.net/sinat_40431164/article/details/81017568?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

```

import pandasas pd

from sklearnimport preprocessing

import scipy.cluster.hierarchyas sch

#用于进行层次聚类,画层次聚类图的工具包

from matplotlibimport pyplotas plt

from sklearn.clusterimport KMeans

from prettytableimport PrettyTable

##数据准备

df = pd.read_excel("习题5.8.xlsx")

label =df['地区']

array = df.values[:,1:7]

##数据预处理

def ZscoreNormalization(X):

scaler = preprocessing.StandardScaler().fit(X)

x_norm = scaler.transform(X)

return x_norm

##系统聚类

X_norm =ZscoreNormalization(array)

Z = sch.linkage(X_norm,method='ward', metric='euclidean')

sch.dendrogram(Z)

#绘图1

plt.title('Clustering')

plt.xlabel('area')

plt.ylabel('distance')

plt.show()

```

```

##K—mean 聚类

cluster =4

cls =KMeans(cluster).fit(X_norm)

# print(cls.labels_) #输出分类列表

cls_result,results =[],[]

for iin cls.labels_:

cls_result.append(i)

results =list(zip(label,cls_result))

Results= PrettyTable(["地区", "K-mean分类"])

for iin results:

Results.add_row([i[0],i[1]])

print(Results)

```

+--------+------------+

|  地区  | K-mean分类 |

+--------+------------+

|  北京  |    3      |

|  天津  |    0      |

|  河北  |    1      |

|  山西  |    1      |

| 内蒙古 |    1      |

|  辽宁  |    0      |

|  吉林  |    2      |

| 黑龙江 |    2      |

|  上海  |    3      |

|  江苏  |    0      |

|  浙江  |    0      |

|  安徽  |    2      |

|  福建  |    2      |

|  江西  |    2      |

|  山东  |    0      |

|  河南  |    1      |

+--------+------------+

相关文章

  • 深入推荐引擎相关算法 - 聚类

    聚类分析 什么是聚类分析? 聚类 (Clustering) 就是将数据对象分组成为多个类或者簇 (Cluster)...

  • clustering 聚类分析

    系统聚类分析 参考文献:https://blog.csdn.net/sinat_40431164/article/...

  • 2019-01-12[Stay Sharp]hierarchic

    what is hierarchical clustering ? hierarchical clustering...

  • ML - hw4

    1. Spectral Clustering (a) Spectral Clustering on synthes...

  • 2019-03-07

    聚类分析 单击→聚类分析 (欢迎关注微信公众号:spss学习乐园) 聚类分析 聚类分析:研究如何将样品或变量进行分...

  • 100天持续行动—Day13

    10.26看了K-Means clustering, Hierarchical clustering 和 DBSC...

  • 2019-01-10[Stay Sharp]k-means cl

    what is k-means clustering? K-means clustering is a metho...

  • 漫谈 Clustering

    漫谈 Clustering (1): k-means 漫谈 Clustering (2): k-medoids 漫...

  • Clustering

    We perform clustering because we believe the underlying c...

  • Clustering

    本文结构安排 经典聚类算法:线性聚类 Kmeans 经典聚类算法:非线性聚类 DBSCAN、谱聚类 新兴聚类算法:...

网友评论

      本文标题:clustering 聚类分析

      本文链接:https://www.haomeiwen.com/subject/ekyvrhtx.html