Diagram steps for Python to draw a classification effect

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.