Bright result diagram: (Ignore the Chinese display function, please review the previous article to modify)
Cm_light = Mpl.colors.ListedColormap ([' G ', ' R ', ' B '])
Objective:
Create an interface diagram of the classifier model (display the classification interface of the model)
Remember: The plane is also made up of many points of mesh points
(1) Choose two dimensions, x1,x2; Select its maximum minimum value (suitable for enlarging the range of data already in the sample, using the Extend (custom function))
def extend (A, B):
Return 1.05*a-0.05*b, 1.05*b-0.05*a
X1_min, X1_max = Extend (x[:, 0].min (), x[:, 0].max ()) # x1 Range
X2_min, X2_max = Extend (x[:, 1].min (), x[:, 1].max ()) # x2 Range
(2) Forming a grid area (for drawing)
n=500;m=500
T1 = Np.linspace (X1_min, X1_max, N) t2 = Np.linspace (X2_min, X2_max, M)
x1, x2 = np.meshgrid (t1, T2)
(3) Formation of predictive values
X_show = Np.stack ((X1.flat, X2.flat), Axis=1)
Y_hat = Model.predict (x_show) # Forecast
Y_hat = Y_hat.reshape (x1.shape) # make it the same shape as the input
(4) Classification interface for drawing classifiers
Plt.figure (facecolor= ' W ')
Plt.pcolormesh (x1, x2, Y_hat, Cmap=cm_light) # Display of predictive values
(5) Show classification effect of classifier (add sample points)
Plt.scatter (x[:, 0], x[:, 1], s=30, c=y, edgecolors= ' K ', cmap=cm_light) # sample Display
Summarize:
Draw the classification interface of the classifier first, form the grid data with Np.meshgrid (), then draw with the help of Plt.pcolormesh ()
Again, sample data scatter plot plus
Doubts, Plt.pcolormesh () the type of input parameter requires confusion
Because there are no two-dimensional planes, you can select only two features to
Diagram steps for Python to draw a classification effect