How to draw classified pictures in perceptron with matplotlib

question: recently I was learning the perceptron model and wanted to draw the following picture, but found that the"+"- "sign in the following picture could not be drawn.

drawing code from elsewhere, where Perceptron is a class implemented in another place

-sharp linear separable data
X = np.random.uniform(0.0, 10.0, (data_size, 2))
Y = np.sign(X[:, 0] + X[:, 1] - 10)
ax1 = plt.subplot(121)
ax1.plot([0, 10], [10, 0], label="real boundary")

X_train, Y_train, X_test, Y_test = X[:train_size, :], Y[:train_size], X[train_size:, :], Y[train_size:]
plot_data(X, Y, train_size)

-sharp model training and test
p = Perceptron()
p.train_dual(X_train, Y_train, X_test, Y_test)
plt.plot([0, -p.b / p.w[0]], [-p.b / p.w[1], 0])
Y_pred = p.predict(X_test)
accurary = p.get_accuracy(Y_pred, Y_test)

scale = -10/p.b
print p.w * scale, p.b * scale
print "Predict Accurary: %f" % accurary

-sharp test accuracy during training process
ax2 = plt.subplot(122)
if len(p.acc_list):
    ax2.plot(range(len(p.acc_list)), p.acc_list)
    ax2.set_title("Num of epoch: %d" % p.iter)
plt.show()
Menu