目录
问题分析 3问题求解 3from MyData import MyData from sklearn.decomposition import PCA import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.mplot3d import Axes3D from time import time # PCA降维 if (__name__=="__main__"): # 是否显示降维结果 show_plot = False # 是否显示各个阶段的用时 show_plot_Time = True # 记录各个关键时刻的时间 keyTime = [] keyTime.append(time()) data = MyData() pictures,labels=data.getData() vectorPictures=pictures.reshape((-1,3*80*80)) keyTime.append(time()) # 降到二维 model = PCA(n_components=2) model.fit(vectorPictures) keyTime.append(time()) result = model.transform(vectorPictures) keyTime.append(time()) if(show_plot): x_min = np.min(result[:,0]) x_max = np.max(result[:,0]) y_min = np.min(result[:,1]) y_max = np.max(result[:,1]) plt.figure(1) for i in range(8): indexLabel = labels==i tmpResult = result[indexLabel] tmpLabel = labels[indexLabel] plt.subplot(2,4,i+1) plt.scatter(tmpResult[:,0],tmpResult[:,1],s=1) plt.axis([x_min-0.1*(x_max-x_min),x_max+0.1*(x_max-x_min),y_min-0.1*(y_max-y_min),y_max+0.1*(y_max-y_min)]) plt.title(data.Flowers[i]) plt.show() plt.figure(2) legends = [] for i in range(8): indexLabel = labels==i tmpResult = result[indexLabel] tmpLabel = labels[indexLabel] plt.scatter(tmpResult[:,0],tmpResult[:,1],s=1) plt.legend(data.Flowers) plt.axis([x_min-0.1*(x_max-x_min),x_max+0.1*(x_max-x_min),y_min-0.1*(y_max-y_min),y_max+0.1*(y_max-y_min)]) plt.show() keyTime.append(time()) model = PCA(n_components=3) model.fit(vectorPictures) keyTime.append(time()) result = model.transform(vectorPictures) keyTime.append(time()) if(show_plot): x_min = np.min(result[:,0]) x_max = np.max(result[:,0]) y_min = np.min(result[:,1]) y_max = np.max(result[:,1]) z_min = np.min(result[:,2]) z_max = np.max(result[:,2]) f=plt.figure(1) for i in range(8): indexLabel = labels==i tmpResult = result[indexLabel] tmpLabel = labels[indexLabel] ax=plt.subplot(2,4,i+1,projection='3d') # ax=Axes3D(f) ax.scatter(tmpResult[:,0],tmpResult[:,1],tmpResult[:,2],s=1) ax.set_zlim3d(z_min-0.1*(z_max-z_min),z_max+0.1*(z_max-z_min)) ax.set_xlim3d(x_min-0.1*(x_max-x_min),x_max+0.1*(x_max-x_min)) ax.set_ylim3d(y_min-0.1*(y_max-y_min),y_max+0.1*(y_max-y_min)) plt.title(data.Flowers[i]) plt.show() plt.figure(2) ax=plt.subplot(projection='3d') legends = [] for i in range(8): indexLabel = labels==i tmpResult = result[indexLabel] tmpLabel = labels[indexLabel] ax.scatter(tmpResult[:,0],tmpResult[:,1],tmpResult[:,2],s=1) plt.legend(data.Flowers) ax.set_zlim3d(z_min-0.1*(z_max-z_min),z_max+0.1*(z_max-z_min)) ax.set_xlim3d(x_min-0.1*(x_max-x_min),x_max+0.1*(x_max-x_min)) ax.set_ylim3d(y_min-0.1*(y_max-y_min),y_max+0.1*(y_max-y_min)) plt.show() print(keyTime) if(show_plot_Time): tmp_KeyTime = np.array(keyTime) # plt.plot(tmp_KeyTime) # plt.show() yticks = np.diff(tmp_KeyTime) plt.plot(yticks) plt.yticks(yticks,yticks) plt.show()
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
相关知识
基于Python机器学习实现的花卉识别
基于深度学习的花卉识别系统开发
基于Pytorch的花卉识别
一种基于小样本学习的花卉识别系统
花卉识别(tensorflow)
基于WEB的花卉养殖知识平台的设计与实现
花伴侣——花卉识别利器!
这篇文章告诉你如何识别花卉植物
花卉识别ios版下载
用Python爬虫获取网络园艺社区植物养护和种植技巧
网址: 基于Python机器学习实现的花卉识别 https://m.huajiangbk.com/newsview4485.html
上一篇: 这篇文章告诉你如何识别花卉植物 |
下一篇: 花伴侣——花卉识别利器! |