#添加误差线(即标准差) for i inrange(len(K)):plt.errorbar(K[i], acc[i], fmt="bo:", yerr = std[i], capsize =5) #添加 K 值和对应的正确率 plt.plot(K, acc) #添加网格 plt.grid(linestyle=':') #x轴名称 plt.xlabel('K') #y轴名称 plt.ylabel('Accuracy') #绘制表格 plt.show()
效果: 4、生成空间分类图
我知道的两种绘图方式:pcolormesh、scatter
前者的运行速度比后者要快很多
下面代码只是绘图的部分,如果运行并不能实现下图的效果
from matplotlib.colors import ListedColormap import matplotlib.pyplot as plt#特征空间的颜色映射表 color_map = ListedColormap(['#AAAAFF','#AAFFAA','#FFAAAA']) #样本集的各种类别代表的颜色 color =['blue','green','red'] #对原始空间进行上色 plt.pcolormesh(X, Y, Z, cmap = color_map)#对原始样本集进行上色 for i inrange(len(iris.data)):plt.scatter(iris.data[i][0], iris.data[i][1], c = color[y[i]], s =10) #绘图 plt.show()
Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ...
[详细]
Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ...
[详细]