()
| 126 | 2017-08-30 |
| 127 | """ |
| 128 | def plotDataSet(): |
| 129 | dataMat, labelMat = loadDataSet() #加载数据集 |
| 130 | dataArr = np.array(dataMat) #转换成numpy的array数组 |
| 131 | n = np.shape(dataMat)[0] #数据个数 |
| 132 | xcord1 = []; ycord1 = [] #正样本 |
| 133 | xcord2 = []; ycord2 = [] #负样本 |
| 134 | for i in range(n): #根据数据集标签进行分类 |
| 135 | if int(labelMat[i]) == 1: |
| 136 | xcord1.append(dataArr[i,1]); ycord1.append(dataArr[i,2]) #1为正样本 |
| 137 | else: |
| 138 | xcord2.append(dataArr[i,1]); ycord2.append(dataArr[i,2]) #0为负样本 |
| 139 | fig = plt.figure() |
| 140 | ax = fig.add_subplot(111) #添加subplot |
| 141 | ax.scatter(xcord1, ycord1, s = 20, c = 'red', marker = 's',alpha=.5)#绘制正样本 |
| 142 | ax.scatter(xcord2, ycord2, s = 20, c = 'green',alpha=.5) #绘制负样本 |
| 143 | plt.title('DataSet') #绘制title |
| 144 | plt.xlabel('X1'); plt.ylabel('X2') #绘制label |
| 145 | plt.show() #显示 |
| 146 | |
| 147 | """ |
| 148 | 函数说明:绘制数据集 |
nothing calls this directly
no test coverage detected