Introduction: Python is one of the best and most popular programming languages and is known for its simplicity, breadth of application, and strong class library, and is the language of choice for implementing machine learning algorithms. Taking the actual combat of artificial neural network as an example, this paper proves that it is necessary to understand the principle of the algorithm, the advantages and disadvantages and the application scenarios so as to achieve the degree of application freedom.
This article is selected from the Python War Machine learning: The first small goal of data scientists.
Before this operation, the packages that need to be imported here are:
650) this.width=650; "Src=" http://img.blog.csdn.net/20170323100805532?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqvynjvywr2awv3mjawng==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/ Gravity/southeast "alt=" Figure 1 "title=" Figure 1 "style=" border:0px;vertical-align:middle; "/>
The original form of perceptual machine learning algorithm
650) this.width=650; "Src=" Http://img.blog.csdn.net/20170323100815735?watermark/2/te xt/ahr0cdovl2jsb2cuy3nkbi5uzxqvynjvywr2awv3mjawng==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/ Gravity/southeast "alt=" Figure 2 "title=" Figure 2 "style=" border:0px;vertical-align:middle; "/>
Parameters
N: The number of sample points for a positive class, and the number of sample points for negative classes. The total number of sample points is 2n.
Return value: An array of all the sample points, shaped as (2*n,4). Each row in the array represents a sample point, consisting of its feature x and Marker Y.
The process is: first generates n random points above the z coordinate of 20 as a positive class, and generates N random points below the z coordinate of 10 as the negative class. At this time in the plane z=, z= 20 as a separation belt. Then rotate the X axis 45 degrees and return the coordinates of those points in the new axis. Note that the data is mixed, otherwise you will find the first half of the data set is a positive class, the latter part is negative class, need to wash the data so that the positive and negative cross-section.
The functions for drawing datasets are:
650) this.width=650; "Src=" http://img.blog.csdn.net/20170323100922518?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqvynjvywr2awv3mjawng==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/ Gravity/southeast "alt=" Figure 3 "title=" Figure 3 "style=" border:0px;vertical-align:middle; "/>
Ax: An AXES3D instance that is responsible for drawing graphics.
Samples: Represents an array of training datasets, with a shape of (n,n_features+1), where N is the number of sample points, and N_features represents the number of features (here is 3, which represents three features).
The use of the Plot_samples function is:
650) this.width=650; "Src=" http://img.blog.csdn.net/20170323100952851?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqvynjvywr2awv3mjawng==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/ Gravity/southeast "alt=" Figure 4 "title=" Figure 4 "style=" Border:0px;vertical-align:middle; "/>
then give the function of the original form algorithm of the Perceptual Machine learning algorithm (as shown in the graph):
650) this.width=650; "Src=" http://img.blog.csdn.net/20170323101001289?wate rmark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvynjvywr2awv3mjawng==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "alt=" Figure 5 "title=" Figure 5 "style=" border:0px;vertical-align:middle; "/>
650) this.width=650; "Src=" http://img.blog.csdn.net/20170323101008613?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqvynjvywr2awv3mjawng==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/ Gravity/southeast "alt=" Figure 6 "title=" Figure 6 "style=" border:0px;vertical-align:middle; "/>
Perceptr On_data
Train_data: Represents an array of training datasets, with a shape of (n,n_features+1), where N is the number of sample points, and N_features represents the number of features (here is 3, which represents three features).
ETA: Learning rate.
W_0: W0, which is a column vector.
B_0: That is B0, is a scalar.
The process is:
-
Outermost loop exits only if all classifications are correct in this case
The inner loop of the
-
Iterates through all the sample points from front to back. Once a sample point is found to be a false classification point, update the w,b and then iterate through all the sample points from the beginning.
Because you need to draw a detached hyper-plane, you need to give a function that generates a detached hyper-plane according to W,b:
650) this.width=650; "Src=" http://img.blog.csdn.net/20170323101047289?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqvynjvywr2awv3mjawng==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/ Gravity/southeast "alt=" Figure 7 "title=" Figure 7 "style=" Border:0px;vertical-align:middle; "/>
X: The array that separates the x-coordinate of the point on the hyper-plane.
Y: The array that separates the y-coordinate of the point on the super-plane.
W: That is W, the normal vector of the super plane, which is a column vector.
B: That is, B, the Intercept of the super-plane.
The process is based on the wxx+wyy+wzz+b=0 equation.
This function can be used to observe the operation of the original algorithm of the Perceptual machine learning algorithm:
650) this.width=650; "Src=" http://img.blog.csdn.net/20170323101125039?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqvynjvywr2awv3mjawng==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/ Gravity/southeast "alt=" Figure 8 "title=" Figure 8 "style=" Border:0px;vertical-align:middle; "/>
The resulting w is [[-10.1] [ -68.08433252][64.85174234]], separating the hyper-planar normal vector ( -10.1,-68.08,64.85), whose projection on the y-z plane is a straight line with a slope of 68.08/64.85= 1.05, very close to our setting to rotate the 45-degree angle when generating the data. The Perceptual machine learning algorithm is the original form of the algorithm for the function perceptron_original graph (as shown in).
650) this.width=650; "Src=" http://img.blog.csdn.net/20170323101139821?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqvynjvywr2awv3mjawng==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/ Gravity/southeast "alt=" Figure 9 "title=" Figure 9 "style=" Border:0px;vertical-align:middle; "/>
This article is selected from the Python War Machine learning: The first small goal of data scientists, this link can be viewed in the blog post view of the book.
650) this.width=650; "Src=" http://img.blog.csdn.net/20170323101736230?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqvynjvywr2awv3mjawng==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/ Gravity/southeast "alt=" Picture description "title=" Picture description "style=" border:0px;vertical-align:middle; "/>
Want to get more good articles in time, you can search "blog point of View" or scan the QR code below and follow.
650) this.width=650; "src=" http://img.blog.csdn.net/20161128135240324 "alt=" Picture description "title=" Picture description "style=" border:0px; Vertical-align:middle; "/>
This article is from the blog of "Blog View blog", make sure to keep this source http://bvbroadview.blog.51cto.com/3227029/1909492
Artificial neural network for Python combat