Machine Learning - Implementing Simple Neural Networks

Course address: https://www.imooc.com/learn/813

1. Basic concepts of machine learning 

Second, the perceptron classification algorithm

1. General description of the classification algorithm

classification behavior

Dot Product of Vectors

transpose of a matrix

2. Perceptron Classification Algorithm

Increase w0,x0 variables. When z is greater than 0, output 1, when z value is less than 0, output -1

The relevant electrical signal of the x(j) input

The weight of ▽w(j) needs to be adjusted only if the perceptron is misclassified

The learning rate is adjusted according to different situations

update the first volume

Similarly, update the second quantity

update the third quantity

After entering new classification input, update the weights

The threshold is initialized to 0, and the electrical signal component is fixed to 1, which is omitted.

It is told that the algorithm must satisfy the first case (Figure 1), that is, linear partitioning. The latter two cases are not suitable for perceptron algorithms

The goal is: to find the middle separating dotted line

step:

(1) Initialization vector w

(2) Input x samples into the perceptron

(3) Dot product, summation of component multiplication results

(4) The result is input into the pacing function, the activation function is activated, and the result is 1 or -1.

(5) If it is correct, output the electrical signal to get the final result; if it is wrong, return the wrong result according to the steps described above, update the weight vector, and then use other original training samples or new Even the samples are re-input into the perceptron.

3. Python implementation of perceptron classification algorithm

1. Implement the perceptron object

1 in y corresponds to the [1,2,3] sample of X, and -1 in y corresponds to the [4,5,6] sample of X

The training process is complete

Dot product of electrical signal input, judge whether the predicted value is greater than 0, return to judge the classification, 1, -1

The implementation of the neuron algorithm is completed

2. Data Analysis and Visualization


Data to load, separated by commas

Read the data, display the first ten lines

Assign the fourth column to y

convert string to number

Extract columns 0 and 2

data visualization

Data can be divided linearly

2. Neural network to achieve classification of data

Fill prepared data according to different colors

Use meshgrid to construct 2-dimensional matrices

Take the first element out and repeat 185 times to become the first row. 255 row matrix can be repeated

ravel: two-dimensional array is restored to a single-dimensional vector before expansion

4. Adaptive Linear Neurons

1. Basic principles of adaptive linear neurons

Treat the summation result directly as the final result, compare

The slope of the tangent line is positive, reducing the value of the w component of the neuron

The tangent slope is negative, increasing the value of the neuron's w component

get the minimum value of w

2. Adaptive Neuron Code Implementation 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325800724&siteId=291194637