本文共 1119 字,大约阅读时间需要 3 分钟。
import numpy as npimport matplotlib.pyplot as pltreturnMat=np.array([[1,2],[3,4]])fig=plt.figure()ax=fig.add_subplot(111)#ax.scatter(returnMat[:,1],returnMat[:,2])#绘制颜色,大小不同的点classLabelVector=[1,2]ax.scatter(returnMat[:,1],returnMat[:,2],15.0*array(classLabelVector),15.0*array(classLabelVector))plt.show()
样例2:
#-*- coding=UTF-8 -*-#adaboost 算法import numpy as npdef loadSimpleData(): datMat = np.matrix([[1., 2.1], [2., 1.1], [1.3, 1.], [1., 1.], [2., 1.]]) classLabels = [1.0, 1.0, -1.0, -1.0, 1.0] return datMat, classLabelsdataMat,classLabels=loadSimpleData()c=np.hstack((dataMat,np.mat(classLabels).T))b=[examle[:2] for examle in np.array(c) if examle[2]==1.0]b=np.array(b)print b[:,1]d=[examle[:,:2] for examle in c if examle[:,2]==-1.0]e=np.array(d)e= np.array(e.reshape(2,2))import numpy as npimport matplotlib.pyplot as pltreturnMat=np.array([[1,2],[3,4],[5,6]])fig=plt.figure()ax=fig.add_subplot(111)#ax.scatter(returnMat[:,1],returnMat[:,2])#绘制颜色,大小不同的点ax.scatter(b[:,0],b[:,1],14)ax.scatter(e[:,0],e[:,1],13)plt.show()