python实现AGNES(凝聚层次聚类)算法

news/2024/5/20 5:59:26 标签: 聚类, python, 聚类算法

在这里插入图片描述

python">#AGNES(凝聚层次聚类)算法
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.cluster import AgglomerativeClustering
from sklearn import datasets
from sklearn.metrics import confusion_matrix
iris=datasets.load_iris()
irisdata=iris.data
clustering=AgglomerativeClustering(linkage='ward',n_clusters=3)
res=clustering.fit(irisdata)
print("各个簇的样本数目:")
print(pd.Series(clustering.labels_).value_counts())
print("聚类结果:")
print(confusion_matrix(iris.target,clustering.labels_))
plt.figure()
d0=irisdata[clustering.labels_==0]
plt.plot(d0[:,0],d0[:,1],'r.')
d1=irisdata[clustering.labels_==1]
plt.plot(d1[:,0],d1[:,1],'go')
d2=irisdata[clustering.labels_==0]
plt.plot(d2[:,0],d2[:,2],'b*')
plt.xlabel('petal length')
plt.ylabel('petal width')
plt.legend(loc=2)
plt.show()


http://www.niftyadmin.cn/n/1712019.html

相关文章

window下的eclipse连接本机虚拟机的redis服务的步骤

老哥这个太强了,一遍过::: 原文连接 https://blog.csdn.net/qq_44195749/article/details/103220031

python绘制散点图时将整个区域分为10乘10个网格

#绘制散点图时将整个区域分为10乘10个网格 from matplotlib import pyplot as plt import matplotlib as mpl import pandas as pd import numpy as np mpl.rcParams["font.sans-serif"]["LiSu"] mpl.rcParams["axes.unicode_minus"]False datap…

操作系统 轮转调度 优先级调度

操作系统 轮转调度 优先级调度 实验要求 多道系统中,必须按照某种策略决定选取哪些进程占用处理器。本实验模拟实现进程调度,进一步加深对低级调度算法的理解。 实验内容 选择某种调度算法,设计一个实现进程调度的程序 轮转调度 首先明确&a…

操作系统 银行家算法

操作系统 银行家算法 实验要求 模拟银行家算法,用银行家算法实现资源分配 实验内容 已知进程{P0,P1,P2,P3,P4},有三类系统资源A、B、C的数量分别为10、5、7,在T0时刻的资源分配情况如下图所示: 若进程P1请求资源,发…

python散点图将整个区域分为10乘10个网格并依次编号

#将散点图分为10乘10个网格并依次编号 from matplotlib import pyplot as plt import matplotlib as mpl import pandas as pd import numpy as np mpl.rcParams["font.sans-serif"]["LiSu"] mpl.rcParams["axes.unicode_minus"]False datapd.re…

python绘制散点图将整个区域分为10乘10个网格,并统计每个网格中点的个数

#绘制散点图将整个区域分为10乘10个网格,并统计每个网格中点的个数 from matplotlib import pyplot as plt import matplotlib as mpl import pandas as pd import numpy as np import os import csv mpl.rcParams["font.sans-serif"]["LiSu"] …

操作系统 动态分区存储管理(循环首次适应算法、最坏适应算法)

操作系统 动态分区存储管理 实验要求 通过编写动态分区存储管理的模拟程序,加深对操作系统存储管理功能中的动态分区管理方式、空闲分区表等相应知识的理解。 实验内容 实现动态分区存储管理方式下存储空间的分配和去配。 循环首次适应算法:每次都从上…

操作系统 请求分页式存储管理(FIFO、LRU)

操作系统 请求分页式存储管理 实验要求 通过编写分页式存储管理的模拟程序,加深对页式存储管理方式的理解,熟悉逻辑地址到物理地址的转换过程,掌握虚拟存储管理中的页面调度算法,认识分页式虚拟存储系统中缺页中断的处理过程。 …