▶ 使用序列最小优化法(Sequential Minimal Optimization)实现非线性支持向量机
● 代码
1 import numpy as np 2 import csv 3 import matplotlib.pyplot as plt 4 from mpl_toolkits.mplot3d import Axes3D 5 from mpl_toolkits.mplot3d.art3d import Poly3DCollection 6 from matplotlib.patches import Rectangle 7 8 dataSize = 1000 9 trainRatio = 0.3 10 defaultC = 1 # 正则化参数 11 defaultSigma = 0.1 12 defaultP = 3 13 defaultEpsilon = 0.001 14 defaultTurn = 500 15 floatEpsilon = 1e-10 16 randomSeed = 107 17 18 def myColor(x): # 颜色函数 19 r = np.select([x < 1/2, x < 3/4, x <= 1, True],[0, 4 * x - 2, 1, 0]) 20 g = np.select([x < 1/4, x < 3/4, x <= 1, True],[4 * x, 1, 4 - 4 * x, 0]) 21 b = np.select([x < 1/4, x < 1/2, x <= 1, True],[1, 2 - 4 * x, 0, 0]) 22 return [r**2,g**2,b**2] 23 24 def dataSplit(x, y, part): # 将数据分离为训练集和测试集 25 return x[:part], y[:part],x[part:],y[part:] 26 27 def myRandom(nowSeed): # 自己的随机数发生器,仅用于调试 28 return nowSeed * 16807 % 214748637 29 30 def linearKernel(x1, x2): # 线性核 31 return np.sum(x1 * x2) 32 33 def gaussianKernel(x1, x2, sigma = defaultSigma): # 高斯核 34 return np.exp( -np.sum((x1 - x2)**2) / (2 * sigma**2) ) 35 36 def polynomialKernel(x1, x2, p = defaultP): # 多项式核,当作“其他核”进行测试 37 return (np.sum(x1 * x2) + 1) ** p 38 39 def loadData(dim, kernelName): # 从文件读取数据,废弃 40 if kernelName == 'linearKernel': 41 fileName = "R:\data1.csv" 42 elif kernelName == 'gaussianKernel': 43 fileName = "R:\data2.csv" 44 temp = np.array([ line for line in csv.reader(open(fileName,'r')) ]) 45 X = np.array(temp[:,:2]).astype(float) 46 Y = np.array(temp[:,2]).astype(int) 47 return X, Y 48 49 def createData(dim, linearSeparable, count = dataSize): # 创建数据 50 np.random.seed(randomSeed) 51 X = np.random.rand(count, dim) 52 if dim == 1: 53 if linearSeparable: # 1 维线性可分,用 0.5 作为分界点 54 Y = ( (X > 0.5).astype(int) * 2 - 1 ).flatten() 55 else: # 1 维线性不可分,用 0.25,0.5,0.75 依次作为分界点 56 Y = ( np.logical_or(X < 0.25, np.logical_and(X >= 0.5, X < 0.75)).astype(int) * 2 - 1 ).flatten() 57 else: 58 if linearSeparable: # 线性可分,用一个超平面作为分界 59 Y = ((3 - 2 * dim) * X[:,0] + 2 * np.sum(X[:,1:], 1) > 0.5).astype(int) * 2 - 1 60 else: # 线性不可分,使用若干区域的并集作为一个类别,其补集为另一类别 61 Y = np.ones(np.shape(X)) 62 area1 = np.sum((X[:,:2] - np.array([1/3, 2/3]))**2, 1) < 1 / 16 63 area2 = np.logical_and( np.logical_and(np.sum(X, 1) > 0.8, np.sum(X, 1) < 1.2), np.logical_and(np.sum(X[:,1:],1) - X[:,0] > -1/3, np.sum(X[:,1:],1) - X[:,0] < 1/3) ) 64 area3 = np.any(X[:,1:] > 0.8, 1) 65 #area3 = np.logical_and( np.logical_and(X[:,0] > 0.75, X[:,0] < 0.9), np.logical_and(X[:,1] > 0.75, X[:,1] < 0.9) ) # 正方形 66 Y = np.logical_or(np.logical_or(area1, area2), area3).astype(int) * 2 - 1 67 print( "dim = %d, dataSize = %d, class1Ratio = %f"%(dim, count, np.sum((Y == 1).astype(int)) / count) ) 68 return X, Y 69 70 def svmTrain(dataX, dataY, kernel, maxTurn = defaultTurn, C = defaultC, epsilon = defaultEpsilon, sigma = defaultSigma): # 训练 71 count, dim = np.shape(dataX) 72 alpha = np.zeros(count) 73 E = np.zeros(count) 74 b = 0 75 np.random.seed(randomSeed) 76 #randomSeed = 103 # 自己的随机数发生器,仅用于调试 77 #randomM = 214748637 78 #newSeed = myRandom(randomSeed) 79 80 if kernel =='linearKernel': # 预计算 Gram 矩阵 81 K = np.dot(dataX, dataX.T) 82 elif kernel == 'gaussianKernel': # 预计算 K(count*count), Kij = np.sum( -(dataX[i]-dataX[j])**2 / (2 * sigma**2) ) 83 X2 = np.mat(np.sum(dataX * dataX, 1)) 84 K = gaussianKernel(1, 0, sigma) ** ( X2 + X2.T - 2 * np.dot(dataX, dataX.T) ) 85 else: 86 K = np.zeros([count,count]) 87 for i in range(count): 88 for j in range(count): 89 K[i,j] = eval(kernel + "(dataX[i], dataX[j], defaultP)") 90 91 for turn in range(maxTurn): 92 alphaChange = 0 93 for i in range(count): 94 E[i] = np.sum (alpha * dataY * K[:,i]) + b - dataY[i] # E[i] = Σ_j α[i]y[i]K(x[i],x[j]) + b - y[i] 95 if dataY[i] * E[i] < -epsilon and alpha[i] < C - floatEpsilon or dataY[i] * E[i] > epsilon and alpha[i] > 0 + floatEpsilon: # 检查第 i 样本是否满足 KKT 条件 96 #newSeed = myRandom(newSeed) # 随机选择 j != i,注释部分调用的是自己的随机数生成器,仅用于调试 97 #j = np.ceil(count * newSeed / randomM).astype(int) - 1 98 j = np.random.choice(count) 99 while j == i: 100 #newSeed = myRandom(newSeed) 101 #j = np.ceil(count * newSeed / randomM).astype(int) - 1 102 j = np.random.choice(count) 103 E[j] = sum (alpha * dataY * K[:,j]) + b - dataY[j] 104 105 sign = int(dataY[i] == dataY[j]) 106 L = max(0, alpha[j] + (2 * sign - 1) * alpha[i] - sign * C) #if (dataY(i) == dataY(j)): L = max(0, alpha(j) + alpha(i) - C);H = min(C, alpha(j) + alpha(i)) 107 H = min(C, alpha[j] + (2 * sign - 1) * alpha[i] + (1 - sign) * C) #else: L = max(0, alpha(j) - alpha(i)); H = min(C, C + alpha(j) - alpha(i)) 108 if L == H: # 上下限相等,已经是最优解,不用再调整 alpha 了 109 continue 110 111 ita = 2 * K[i,j] - K[i,i] - K[j,j] 112 if ita >= 0: 113 continue 114 115 alphaJOld = alpha[j] 116 alpha[j] = max( L, min(H, alpha[j] - (dataY[j] * (E[i] - E[j])) / ita) ) # 沿约束方向剪辑的解 117 if np.abs(alpha[j] - alphaJOld) < epsilon: 118 alpha[j] = alphaJOld 119 continue 120 121 alphaIOld = alpha[i] 122 alpha[i] += dataY[i] * dataY[j] * (alphaJOld - alpha[j]) # 用 alpha[j] 和条件 Σα[i]y[i] == 0 来求 alpha[i] 123 if np.abs(alpha[i]) < floatEpsilon: 124 alpha[i] = 0.0 125 126 b1 = b - E[i] - dataY[i] * (alpha[i] - alphaIOld) * K[i,j] - dataY[j] * (alpha[j] - alphaJOld) * K[i,j] 127 b2 = b - E[j] - dataY[i] * (alpha[i] - alphaIOld) * K[i,j] - dataY[j] * (alpha[j] - alphaJOld) * K[j,j] 128 if alpha[i] > 0 and alpha[i] < C: # 不同 alpha[i] 条件下选取 b 129 b = b1 130 elif alpha[j] > 0 and alpha[j] < C: 131 b = b2 132 else: 133 b = (b1 + b2) / 2 134 135 alphaChange += 1 136 137 print("turn = %d, alphaChange = %d, sum(alpha) = %f"%(turn, alphaChange, np.sum(alpha)) ) 138 if alphaChange == 0: 139 break 140 141 idx = [ i for i in range(count) if alpha[i] > 0 ] # 选出非零的 alpha,即支持向量对应的乘子 142 return {'alphaCount':len(idx), 'dataX': dataX[idx], 'dataY' : dataY[idx], 'kernel' : kernel, 143 'w' : np.array( np.dot(np.mat(alpha*dataY),dataX) ), 'b' : b, 'alpha' : alpha[idx]} 144 145 def judgePoint(x, para, sigma = defaultSigma): # 预测单点 x 的类别 146 if para['kernel'] == 'linearKernel': 147 return np.sign( np.sum(x * para['w'].flatten()) + para['b'] ) 148 elif para['kernel'] == 'gaussianKernel': 149 K = gaussianKernel(1, 0, sigma) ** ( np.sum(x**2) + np.sum(para['dataX']**2, 1) - 2 * np.sum(x * para['dataX'], 1) ) 150 return np.sign( np.sum(para['alpha'] * para['dataY'] * K) + para['b'] ) 151 else: 152 res = 0 153 for i in range(para['alphaCount']): 154 res += para['alpha'][i] * para['dataY'][i] * eval(para['kernel'] + "(x, para['dataX'][i], defaultP)") 155 return np.sign( res + para['b']) 156 157 def judgeList(xList, para, sigma = defaultSigma): # 预测一堆 x 的类别,为 judgePoint 的向量化版本,暂时没有用到函数 test 中 158 if para['kernel'] == 'linearKernel': 159 return np.sign( np.sum(np.array(xList) * para['w'].flatten(), 1) + para['b'] ) 160 elif para['kernel'] == 'gaussianKernel': 161 K = gaussianKernel(1, 0) ** ( np.sum(xList**2, 1) + np.sum(para['dataX']**2, 1).T - 2 * np.dot(np.mat(xList), para['dataX'].T) ) 162 return np.sign( np.sum(para['alpha'] * para['dataY'] * K, 1) + para['b'] ) 163 else: 164 count = len(xList) 165 K = np.zeros([ count, para['alphaCount'] ]) 166 for i in range(count): 167 for j in range(para['alphaCount']): 168 K[i,j] = eval(kernel + "(xList[i], para['dataX'][j], defaultP)") 169 return np.sign( para['alpha'] * para['dataY'] * K + para['b']) 170 171 def test(dim, kernelName, linearSeparable = True): # 测试函数,单词调用包含完整的数据生成、训练、预测、画图 172 #allX, allY = loadData(dim, kernelName) # 从文件读取数据的版本,废弃 173 allX, allY = createData(dim, linearSeparable) 174 trainX, trainY, testX, testY = dataSplit(allX, allY, int(dataSize * trainRatio)) 175 176 para = svmTrain(trainX, trainY, kernelName) # 训练 177 178 myResult = [ judgePoint(x, para) for x in testX] 179 errorRatio = np.sum( ((np.array(myResult) != testY)).astype(int)**2 ) / (dataSize * (1 - trainRatio)) 180 print("dim = %d, kernel = %s, linearSeparable = %s, errorRatio = %4f "%(dim, kernelName, str(linearSeparable), errorRatio)) 181 182 if dim >= 4: # 4 维以上不画图,只输出测试错误率 183 return 184 185 classP = [ [],[] ] 186 errorP = [] 187 for i in range(len(testX)): 188 if myResult[i] != testY[i]: 189 if dim == 1: 190 errorP.append(np.array([testX[i], int(testY[i]+1)>>1])) 191 else: 192 errorP.append(np.array(testX[i])) 193 else: 194 classP[int(myResult[i]+1)>>1].append(testX[i]) 195 errorP = np.array(errorP) 196 classP = [ np.array(classP[0]), np.array(classP[1]) ] 197 198 fig = plt.figure(figsize=(10, 8)) 199 if dim == 1: 200 plt.xlim(0.0,1.0) 201 plt.ylim(-0.25,1.25) 202 for i in range(2): 203 plt.scatter(classP[i], np.ones(len(classP[i])) * i, color = myColor(i/2), s = 8, label = "class" + str(i)) 204 if len(errorP) != 0: 205 plt.scatter(errorP[:,0], errorP[:,1],color = myColor(1), s = 16,label = "errorData") 206 if para['kernel'] == 'linearKernel': # 1 维线性可分,画直线 207 plt.plot([0.5, 0.5], [-0.25, 1.25], color = [0.5,0.25,0],label = "realBoundary") 208 plt.plot([0,1], para['w'].flatten() * np.array([0,1]) + para['b'], color = [1.0,0.5,0], label = "myF") 209 plt.text(0.2, 1.1, "realBoundary: 2x = 1 myF(x) = " + str(round(para['w'].flatten()[0],2)) + " x + " + str(round(para['b'],2)) + " errorRatio = " + str(round(errorRatio,4)), 210 size=15, ha="center", va="center", bbox=dict(boxstyle="round", ec=(1., 0.5, 0.5), fc=(1., 1., 1.))) 211 else: #elif para['kernel'] == 'gaussianKernel': # 其他,画等高线 212 xx = yy = np.arange(0.0, 1.0, 0.01) 213 z = np.tile(np.array([ judgePoint(i, para) for i in xx ]),[len(xx),1]) 214 plt.contour(xx, yy, z, [0.0]) 215 plt.text(0.85, 1.1, "errorRatio = " + str(round(errorRatio,4)), size = 15, ha="center", va="center", bbox=dict(boxstyle="round", ec=(1., 0.5, 0.5), fc=(1., 1., 1.))) 216 #else: 217 # pass 218 R = [ Rectangle((0,0),0,0, color = myColor(i / 2)) for i in range(2) ] + 219 [ Rectangle((0,0),0,0, color = myColor(1)), Rectangle((0,0),0,0, color = [0.5,0.25,0]), Rectangle((0,0),0,0, color = [1,0.5,0]), Rectangle((0,0),0,0, color = [0.25, 0.0, 0.375]) ] 220 plt.legend(R, [ "class" + str(i) for i in range(2) ] + ["errorData", "realBoundary", "myFunction", "contour"], loc=[0.81, 0.2], ncol=1, numpoints=1, framealpha = 1) 221 222 if dim == 2: 223 plt.xlim(-0.1, 1.1) 224 plt.ylim(-0.1, 1.1) 225 for i in range(2): 226 plt.scatter(classP[i][:,0], classP[i][:,1], color = myColor(i/2), s = 8, label = "class" + str(i)) 227 if len(errorP) != 0: 228 plt.scatter(errorP[:,0], errorP[:,1], color = myColor(1), s = 16, label = "errorData") 229 if para['kernel'] == 'linearKernel': # 2 维线性可分,画直线 230 w1, w2 = para['w'].flatten() 231 b = para['b'] 232 plt.plot([0,1], -(w1 * np.array([0,1]) + b) / w2, color = [0.5,0.25,0], label = "realBoundary") 233 plt.text(0.78, 1.02, "realBoundary: -x + 2y = 1 myF(x,y) = " + str(round(w1,2)) + " x + " + str(round(w2,2)) + " y + " + str(round(b,2)) + " errorRatio = " + str(round(errorRatio,4)), 234 size = 15, ha="center", va="center", bbox=dict(boxstyle="round", ec=(1., 0.5, 0.5), fc=(1., 1., 1.))) 235 else: #elif para['kernel'] == 'gaussianKernel': # 其他,画等高线 236 xx = np.arange(0.0, 1.0, 0.01) 237 yy = np.arange(0.0, 1.0, 0.01) 238 z = [ [ judgePoint(np.array([i, j]), para) for i in xx ] for j in yy ] 239 xx, yy = np.meshgrid(xx, yy) 240 plt.contour(xx, yy, z, [0.0]) 241 plt.text(0.91, 1.05, "errorRatio = " + str(round(errorRatio,4)), size = 15, ha="center", va="center", bbox=dict(boxstyle="round", ec=(1., 0.5, 0.5), fc=(1., 1., 1.))) 242 #else: 243 # pass 244 R = [ Rectangle((0,0),0,0, color = myColor(i / 2)) for i in range(2) ] + [ Rectangle((0,0),0,0, color = myColor(1)) ] 245 plt.legend(R, [ "class" + str(i) for i in range(2) ] + ["errorData"], loc=[0.84, 0.012], ncol=1, numpoints=1, framealpha = 1) 246 247 if dim == 3: 248 ax = Axes3D(fig) 249 ax.set_xlim3d(0.0, 1.0) 250 ax.set_ylim3d(0.0, 1.0) 251 ax.set_zlim3d(0.0, 1.0) 252 ax.set_xlabel('X', fontdict={'size': 15, 'color': 'k'}) 253 ax.set_ylabel('Y', fontdict={'size': 15, 'color': 'k'}) 254 ax.set_zlabel('Z', fontdict={'size': 15, 'color': 'k'}) 255 for i in range(2): 256 ax.scatter(classP[i][:,0], classP[i][:,1], classP[i][:,2], color = myColor(i/2), s = 8, label = "class" + str(i)) 257 if len(errorP) != 0: 258 ax.scatter(errorP[:,0], errorP[:,1],errorP[:,2], color = myColor(1), s = 8, label = "errorData") 259 if para['kernel'] == 'linearKernel' and linearSeparable == True: # 3 维线性可分,画分割面 260 v = [(0, 0, 0.25), (0, 0.25, 0), (0.5, 1, 0), (1, 1, 0.75), (1, 0.75, 1), (0.5, 0, 1)] 261 f = [[0,1,2,3,4,5]] 262 poly3d = [[v[i] for i in j] for j in f] 263 ax.add_collection3d(Poly3DCollection(poly3d, edgecolor = 'k', facecolors = [0.5,0.25,0,0.5], linewidths=1)) 264 w1, w2, w3 = para['w'].flatten() 265 ax.text3D(0.75, 0.92, 1.15, "realBoundary: -3x + 2y +2z = 1 myF(x,y,z) = " + str(round(w1,2)) + " x + " + 266 str(round(w2,2)) + " y + " + str(round(w3,2)) + " z + " + str(round(para['b'],2)) + " errorRatio = " + str(round(errorRatio,4)), 267 size = 12, ha="center", va="center", bbox=dict(boxstyle="round", ec=(1, 0.5, 0.5), fc=(1, 1, 1))) 268 else: #elif para['kernel'] == 'gaussianKernel': # 其他,仅画散点 269 ax.text3D(0.75, 0.92, 1.15, "errorRatio = " + str(round(errorRatio,4)), size = 12, ha="center", va="center", bbox=dict(boxstyle="round", ec=(1, 0.5, 0.5), fc=(1, 1, 1))) 270 #else: 271 # pass 272 R = [ Rectangle((0,0),0,0, color = myColor(i / 2)) for i in range(2) ] + [ Rectangle((0,0),0,0, color = myColor(1)) ] 273 plt.legend(R, [ "class" + str(i) for i in range(2) ] + ["errorData"], loc=[0.84, 0.012], ncol=1, numpoints=1, framealpha = 1) 274 275 fig.savefig("R:\dim" + str(dim) + "kind2" + para['kernel'] + str(linearSeparable) + ".png") 276 plt.close() 277 278 if __name__=='__main__': 279 test(1,'linearKernel') # 同一维度测试 6 组,分别为数据集 线性可分/不可分 情况下的三种核 280 test(1,'linearKernel', False) 281 test(1,'gaussianKernel') 282 test(1,'gaussianKernel', False) 283 test(1,'polynomialKernel') 284 test(1,'polynomialKernel', False) 285 test(2,'linearKernel') 286 test(2,'linearKernel', False) 287 test(2,'gaussianKernel') 288 test(2,'gaussianKernel', False) 289 test(2,'polynomialKernel') 290 test(2,'polynomialKernel', False) 291 test(3,'linearKernel') 292 test(3,'linearKernel', False) 293 test(3,'gaussianKernel') 294 test(3,'gaussianKernel', False) 295 test(3,'polynomialKernel') 296 test(3,'polynomialKernel', False) 297 test(4,'linearKernel') 298 test(4,'linearKernel', False) 299 test(4,'gaussianKernel') 300 test(4,'gaussianKernel', False) 301 test(4,'polynomialKernel') 302 test(4,'polynomialKernel', False) 303 test(5,'linearKernel') 304 test(5,'linearKernel', False) 305 test(5,'gaussianKernel') 306 test(5,'gaussianKernel', False) 307 test(5,'polynomialKernel') 308 test(5,'polynomialKernel', False)
● 测试输出结果,含有每种条件下的预测错误率
dim = 1, dataSize = 1000, class1Ratio = 0.502000 turn = 0, alphaChange = 41, sum(alpha) = 61.777849 ... turn = 17, alphaChange = 0, sum(alpha) = 92.472427 dim = 1, kernel = linearKernel, linearSeparable = True, errorRatio = 0.067143 dim = 1, dataSize = 1000, class1Ratio = 0.499000 turn = 0, alphaChange = 83, sum(alpha) = 124.440197 ... turn = 31, alphaChange = 0, sum(alpha) = 222.751342 dim = 1, kernel = linearKernel, linearSeparable = False, errorRatio = 0.428571 dim = 1, dataSize = 1000, class1Ratio = 0.502000 turn = 0, alphaChange = 28, sum(alpha) = 17.106702 ... turn = 63, alphaChange = 0, sum(alpha) = 26.425768 dim = 1, kernel = gaussianKernel, linearSeparable = True, errorRatio = 0.000000 dim = 1, dataSize = 1000, class1Ratio = 0.499000 turn = 0, alphaChange = 37, sum(alpha) = 27.927220 ... turn = 30, alphaChange = 0, sum(alpha) = 57.091924 dim = 1, kernel = gaussianKernel, linearSeparable = False, errorRatio = 0.015714 dim = 1, dataSize = 1000, class1Ratio = 0.502000 turn = 0, alphaChange = 17, sum(alpha) = 24.271410 ... turn = 21, alphaChange = 0, sum(alpha) = 52.191926 dim = 1, kernel = polynomialKernel, linearSeparable = True, errorRatio = 0.022857 dim = 1, dataSize = 1000, class1Ratio = 0.499000 turn = 0, alphaChange = 77, sum(alpha) = 108.363683 ... turn = 45, alphaChange = 0, sum(alpha) = 219.320424 dim = 1, kernel = polynomialKernel, linearSeparable = False, errorRatio = 0.381429 dim = 2, dataSize = 1000, class1Ratio = 0.484000 turn = 0, alphaChange = 43, sum(alpha) = 53.823493 ... turn = 26, alphaChange = 0, sum(alpha) = 93.417916 dim = 2, kernel = linearKernel, linearSeparable = True, errorRatio = 0.035714 dim = 2, dataSize = 1000, class1Ratio = 0.427000 turn = 0, alphaChange = 52, sum(alpha) = 74.465762 ... turn = 24, alphaChange = 0, sum(alpha) = 150.187006 dim = 2, kernel = linearKernel, linearSeparable = False, errorRatio = 0.202857 dim = 2, dataSize = 1000, class1Ratio = 0.484000 turn = 0, alphaChange = 59, sum(alpha) = 33.729367 ... turn = 177, alphaChange = 0, sum(alpha) = 47.814144 dim = 2, kernel = gaussianKernel, linearSeparable = True, errorRatio = 0.010000 dim = 2, dataSize = 1000, class1Ratio = 0.427000 turn = 0, alphaChange = 64, sum(alpha) = 44.588532 ... turn = 207, alphaChange = 0, sum(alpha) = 63.486728 dim = 2, kernel = gaussianKernel, linearSeparable = False, errorRatio = 0.028571 dim = 2, dataSize = 1000, class1Ratio = 0.484000 turn = 0, alphaChange = 17, sum(alpha) = 14.054926 ... turn = 48, alphaChange = 0, sum(alpha) = 46.507013 dim = 2, kernel = polynomialKernel, linearSeparable = True, errorRatio = 0.018571 dim = 2, dataSize = 1000, class1Ratio = 0.427000 turn = 0, alphaChange = 49, sum(alpha) = 39.872982 ... turn = 58, alphaChange = 0, sum(alpha) = 116.704852 dim = 2, kernel = polynomialKernel, linearSeparable = False, errorRatio = 0.138571 dim = 3, dataSize = 1000, class1Ratio = 0.510000 turn = 0, alphaChange = 45, sum(alpha) = 53.118025 ... turn = 27, alphaChange = 0, sum(alpha) = 91.635853 dim = 3, kernel = linearKernel, linearSeparable = True, errorRatio = 0.025714 dim = 3, dataSize = 1000, class1Ratio = 0.552000 turn = 0, alphaChange = 66, sum(alpha) = 93.457770 ... turn = 41, alphaChange = 0, sum(alpha) = 194.771610 dim = 3, kernel = linearKernel, linearSeparable = False, errorRatio = 0.228571 dim = 3, dataSize = 1000, class1Ratio = 0.510000 turn = 0, alphaChange = 131, sum(alpha) = 84.262099 ... turn = 101, alphaChange = 0, sum(alpha) = 104.799036 dim = 3, kernel = gaussianKernel, linearSeparable = True, errorRatio = 0.044286 dim = 3, dataSize = 1000, class1Ratio = 0.552000 turn = 0, alphaChange = 143, sum(alpha) = 101.788465 ... turn = 90, alphaChange = 0, sum(alpha) = 132.553143 dim = 3, kernel = gaussianKernel, linearSeparable = False, errorRatio = 0.085714 dim = 3, dataSize = 1000, class1Ratio = 0.510000 turn = 0, alphaChange = 28, sum(alpha) = 11.031567 ... turn = 44, alphaChange = 0, sum(alpha) = 42.360866 dim = 3, kernel = polynomialKernel, linearSeparable = True, errorRatio = 0.018571 dim = 3, dataSize = 1000, class1Ratio = 0.552000 turn = 0, alphaChange = 51, sum(alpha) = 25.475450 ... turn = 74, alphaChange = 0, sum(alpha) = 139.188897 dim = 3, kernel = polynomialKernel, linearSeparable = False, errorRatio = 0.147143 dim = 4, dataSize = 1000, class1Ratio = 0.498000 turn = 0, alphaChange = 35, sum(alpha) = 43.674822 ... turn = 35, alphaChange = 0, sum(alpha) = 96.021582 dim = 4, kernel = linearKernel, linearSeparable = True, errorRatio = 0.018571 dim = 4, dataSize = 1000, class1Ratio = 0.644000 turn = 0, alphaChange = 66, sum(alpha) = 94.519804 ... turn = 26, alphaChange = 0, sum(alpha) = 174.430759 dim = 4, kernel = linearKernel, linearSeparable = False, errorRatio = 0.250000 dim = 4, dataSize = 1000, class1Ratio = 0.498000 turn = 0, alphaChange = 145, sum(alpha) = 119.156807 ... turn = 35, alphaChange = 0, sum(alpha) = 199.188603 dim = 4, kernel = gaussianKernel, linearSeparable = True, errorRatio = 0.077143 dim = 4, dataSize = 1000, class1Ratio = 0.644000 turn = 0, alphaChange = 169, sum(alpha) = 140.931018 ... turn = 35, alphaChange = 0, sum(alpha) = 185.839114 dim = 4, kernel = gaussianKernel, linearSeparable = False, errorRatio = 0.204286 dim = 4, dataSize = 1000, class1Ratio = 0.498000 turn = 0, alphaChange = 30, sum(alpha) = 8.426132 ... turn = 96, alphaChange = 0, sum(alpha) = 39.601635 dim = 4, kernel = polynomialKernel, linearSeparable = True, errorRatio = 0.041429 dim = 4, dataSize = 1000, class1Ratio = 0.644000 turn = 0, alphaChange = 64, sum(alpha) = 26.109571 ... turn = 105, alphaChange = 0, sum(alpha) = 123.836824 dim = 4, kernel = polynomialKernel, linearSeparable = False, errorRatio = 0.152857 dim = 5, dataSize = 1000, class1Ratio = 0.498000 turn = 0, alphaChange = 45, sum(alpha) = 40.268829 ... turn = 50, alphaChange = 0, sum(alpha) = 94.613699 dim = 5, kernel = linearKernel, linearSeparable = True, errorRatio = 0.020000 dim = 5, dataSize = 1000, class1Ratio = 0.662000 turn = 0, alphaChange = 59, sum(alpha) = 82.089864 ... turn = 44, alphaChange = 0, sum(alpha) = 171.887347 dim = 5, kernel = linearKernel, linearSeparable = False, errorRatio = 0.221429 dim = 5, dataSize = 1000, class1Ratio = 0.498000 turn = 0, alphaChange = 153, sum(alpha) = 141.898973 ... turn = 24, alphaChange = 0, sum(alpha) = 262.906561 dim = 5, kernel = gaussianKernel, linearSeparable = True, errorRatio = 0.120000 dim = 5, dataSize = 1000, class1Ratio = 0.662000 turn = 0, alphaChange = 131, sum(alpha) = 121.391288 ... turn = 29, alphaChange = 0, sum(alpha) = 204.612337 dim = 5, kernel = gaussianKernel, linearSeparable = False, errorRatio = 0.298571 dim = 5, dataSize = 1000, class1Ratio = 0.498000 turn = 0, alphaChange = 29, sum(alpha) = 6.392476 ... turn = 109, alphaChange = 0, sum(alpha) = 32.881752 dim = 5, kernel = polynomialKernel, linearSeparable = True, errorRatio = 0.047143 dim = 5, dataSize = 1000, class1Ratio = 0.662000 turn = 0, alphaChange = 60, sum(alpha) = 17.873797 ... turn = 207, alphaChange = 0, sum(alpha) = 110.518102 dim = 5, kernel = polynomialKernel, linearSeparable = False, errorRatio = 0.124286
● 画图,一维。行:数据集线性可分/ 不可分,列:线性核、高斯核、三次多项式核
● 画图,二维。行:数据集线性可分/ 不可分,列:线性核、高斯核、三次多项式核
● 画图,三维。行:数据集线性可分/ 不可分,列:线性核、高斯核、三次多项式核