####################################################################################################### x_begin = min(data[:, 0]) #扫描分界面位置 x_end = max(data[:, 0]) y_begin = min(data[:, 1]) y_end = max(data[:, 1]) + 1 pointnumber = 1200 linex = np.linspace(x_begin, x_end, pointnumber) liney = np.zeros(pointnumber) linextest = np.ones(pointnumber) tempdata = np.zeros((pointnumber, 2)) tempdata[:, 1] = np.linspace(y_begin, y_end, pointnumber) def coutline(): for i in range(0, pointnumber): tempdata[:, 0] = linex[i] * linextest temp = svm_predict(np.zeros(pointnumber), tempdata, model, '-q') for j in range(1, pointnumber): if (temp[0][j] + temp[0][j - 1] == 1): break liney[i] = tempdata[j][1] return liney coutline() ####################################################################################################### #输出数据 np.savez("SVM_Linear", linex, liney) #np.savez("SVM_Gauss",linex,liney) plotall(data, label, np.array(predict[0]), None, None, None, train_size + test_size, 0, False, linex, liney)
x_end = max(data[:, 0]) y_begin = min(data[:, 1]) y_end = max(data[:, 1]) + 1 pointnumber = 1200 linex = np.linspace(x_begin, x_end, pointnumber) liney = np.zeros(pointnumber) linextest = np.ones(pointnumber) tempdata = np.zeros((pointnumber, 2)) tempdata[:, 1] = np.linspace(y_begin, y_end, pointnumber) def coutline(): for i in range(0, pointnumber): tempdata[:, 0] = linex[i] * linextest temp = model.predict(tempdata) for j in range(1, pointnumber): if (temp[j] + temp[j - 1] == 1): break liney[i] = tempdata[j][1] return liney coutline() plotall(data, label, decide, None, None, None, train_size + test_size, 0, False, linex, liney) #np.savez("Perceptron",linex,liney) #withoutnorm #average accuracy=0.9628288209606433 #withnorm #average accuracy=0.983187772925717