Machine learning simple data classification

                                         

 

 

table of Contents:

  1. Implementation of simple machine learning
  2. The basic structure is simple neural network
  3. Simple mathematics neural network data classification
  4. Implementation process of data classification
  5. Use python3.7 and tensorflow1.15 simple data classification
  6. A better understanding of machine learning.

Summary:

Keywords: machine learning, neural networks, data classification

 

text

zero. Simple machine learning implementation process.

Machine learning (machine learning) is to extract knowledge from the data. It is artificial intelligence, computer science and technology and mathematics, especially statistics cross area of research, also known as predictive analytics or statistic learning. In recent years, machine learning has been applied to people's daily lives. [1]

Excellent machine learning algorithm should be those computer algorithm independent decisions. Machine learning methods can be roughly divided into supervised learning (supervised learning algorithm) and unsupervised learning (Unsupervised Learning algorithm) [1] . Supervised learning, in short, from a previously prepared input and output data to focus on learning. For example, if you want to achieve digital handwriting recognition, it is necessary to prepare a large number of handwritten numbers corresponding to the correct answer and photos in advance. Models are "fed" into the large amounts of data, after which they can be modified based on the correct answer get, adjusting the parameters of the original model, thereby increasing the accuracy of the model. From this perspective, the data sets provided the larger, the more accurate the resulting model.

        If there is no implementation provides output data is unsupervised learning algorithm. Obviously, the whole is more difficult to say than unsupervised learning supervised learning algorithm.

The basic structure of a simple neural network

Neurons are present in the human body (mainly the brain) is a type of cell. Mainly by the dendrites of neurons, axon, cell body composition. Wherein axon dendrites will nerve impulse transmission to the next neuron or cell body, the cell body is responsible for central processing and calculation. The number of neurons in the human body has about 14 billion [3] . Many neurons are connected together, constitute the neural network.

 

(Figure from Baidu picture)

The neural network has two very good advantages: [2]

  1. Massively parallel computing architecture.
  2. Neural network learning ability

Mathematical model of the neural network (Artificial Neural Network), in the field of artificial intelligence, neural network structure is a structure modeled on the biological nature (mainly mimics the central nervous system), and this model has logical completeness, can for some values were estimated. Neural network consists of a large number of artificial structures on the neuron model or mathematical logic connected to this neuron model calculation unit as the basic correlation calculation. Artificial neural networks can adjust the feedback in the data base of parameters outside their own neural network, the popular talk, that is, the neural network has the function of self-learning. [2]

II. Simple math neural network data classification

After learning works neurons can bionic design similar information systems;

 

(Figure from Bing Images)

As shown, neurons "receiving", "dendritic" coming "stimulus" (in this case x1 to XM), coming from different directions in order to allow stimulation differ, also specify on each dendrite value corresponding to the right. Intermediate summation of the calculated result is + b, where the first term is the sum of the input values ​​and the weight, the second term is the bias (BIAS), proposed by McCulloch and pitts in 1964. The summation results obtained after reprocessing by the active function (activation function). Finally, according to the processing results obtained output, the output function is defined such as:

 

Such neurons are connected together, the front of the output neurons of neurons as the next input, constitute a neural network.

 

(Photo know almost)

 

three. Implementation process of data classification;

        Before using neural networks, to training, and the training process, in fact, it is to modify the back-propagation neural network parameters to make the model more accurate process. For example, n is now set to give two rows of the matrix, if the same row output a sum greater than 0, less than 0 if the output 1.

       So, it is necessary to spread the spread and reverse the process before use.

       The forward spread is the data "Hello" into the process of neural networks. Here the choice of neural network structure as shown in FIG:

 

        Then, during a data transfer can use the 1 * 2 matrix representative of the size. Because both parameters need to be considered with 2 * 3 matrix parameter storage neurons of the first layer, with 3 * 1 matrix storage parameters for the second layer. To simplify the representation, here we choose bias = 0, the function is activated

        Then, write the input data matrix is ​​composed of X, the matrix of neural network parameter storage data were processed through the neural network is

 

        But just before there is not enough to spread, in order to adjust the neural parameters based on the results, we need to back-propagation process.

        First, determine the amount of "degree of accuracy," the results are described, which we call "loss of function." Calculated as the mean square error, namely:

 

        Our goal is to make the value of the loss as small as possible. Means to achieve this goal there are many more commonly used is the gradient descent method. Gradient descent iterative method to find the extreme point of the objective function.

        Thus, after many times of adjustment, the parameters of the neural network obtained basically meet the requirements, can be used for practical use.

       

 

four. Use python3.7 and tensorflow1.15 simple data classification

        Tensorflow is an open source distributed by Google's software library is often used in the field of machine learning, tensorflow very flexible and can be used on different places, has good portability, but also tensorflow package of related algorithms very good. Whether in academia or industry, tensorflow use are common. Now try to exploit the python and tensorflow, and achieve decimal between 0 and 1 identify the two is greater than 1.

        Tensorflow can be invoked in several languages, such as python, Java, C ++, Go, Swift and so on. This selection python3.7 and tensorflow1.15 to achieve the classification of data. Build a programming environment using the python release anaconda for scientific computing.

        In Comparative Tensorflow basic, frequently used data type referred to as "tensors", can be regarded as an array of a plurality of dimensions. Such as zero-dimensional tensor is real (or referred to as "scalar") usually used one-dimensional tensor is a one-dimensional array, two-dimensional tensor is a two-dimensional array.

        In tensorflow can easily be generated randomly using a normal neural network parameter, and then adjusting the value of the parameter obtained by the beginning of a backpropagation. To obtain test data, you can call another scientific computing package python numpy.

# Generate a random matrix

rng=np.random.RandomState(seed)

# 2 returns a matrix of 32 rows, sets of test data indicates 32

X=rng.rand(32,2)

 

        So that after the specified value of the seed, you can obtain the size of 32 * 2 matrix of random number generation. Re-use the formula to get a list of the "right answer"

Y=[[int(x0+x1<1)] for(x0,x1) in X]

Propagating process before use code implements:

 

# Define input and output parameters of the neural network, the communication process is defined in the preceding paragraph

x=tf.placeholder(tf.float32,shape=(None,2))

y_=tf.placeholder(tf.float32,shape=(None,1))

 

# May generate a random number with a normal distribution

w1=tf.Variable(tf.random.normal([2,3],stddev=1,seed=1))

w2=tf.Variable(tf.random.normal([3,1],stddev=1,seed=1))

 

a=tf.matmul(x,w1)

y=tf.matmul(a,w2)

 

tf.random.normal can be normally distributed random numbers as the initial parameters of the neural network; gcc - internal i.e., matrix multiplication. This will build a simple neural network

Tensorflow in the packaging of various algorithms have been very mature, which allows users to achieve the call to the algorithm in the case do not quite understand the underlying mechanism of the algorithm. For example, if you want to achieve gradient descent training process, and hope each time you change the amplitude of the neural network parameter is 0.001, you can call direct methods exist:

import tensorflow as tf

train_step=tf.train.GradientDescentOptimizer(0.001).minimize(loss)

First introduced tensorflow module, calling gradient descent training methods, each change step size is set to 0.001, the purpose is to minimize the loss function.

If you want to be after the calculation process to obtain the final result, but also to use the process of "session".

        The basic process of the whole program is to prepare test data (input data and the corresponding answers), the process of communication to spread the reverse before building, trained a large number of times, to get the appropriate parameters of the neural network.

3000 training set number of times, the output of the neural network parameters after training, the following results can be obtained:

 

(Screenshot image output parameter system runtime)

Thus, only if the input data is now available, and if the two numbers is greater than 1, then the result will be very close to the calculated one, if the two numbers is less than 1, the calculated results should be very close to 0. The final result for rounding and output, you can get the final result. The last run I test result accuracy diameter, should be more than 80%. As shown below:

       

 

(Picture-based program run shot in the process)

In this way, you can let the program identify the two numbers is greater than 1   

(Runtime environment: win10, python3,7 tensorflow1.15, code address: https://github.com/OldAtaraxia/tensorflow- )

V. learn a better understanding of the machine.

        Only the most basic of some elements described above. In fact, machine learning is much more complicated than this. Linear regression, naive Bayes, SVM, gradient descent, tree ...... extensive knowledge of machine learning also is waiting for us to learn, to explore.

        Daily life, very broad application of machine learning. Such as blocking spam, fraud detection in credit card transactions, the subject of many articles of detection, detection of abnormal web access and so on. Machine learning has a very wide range of application scenarios in modern society, from data mining to pattern recognition, from embedded systems to bioinformatics, data analysis from the natural language processing, from intellectual activity to electronic games, machine learning inevitable in the coming age shine, become an integral part of promoting social progress and improve the quality of people's lives.

references:

  1. [Germany] Andreas C.Muller [US] Sarah Guido "Python machine learning based tutorial", China Industry and Information Publishing Group Posts and Telecom Press
  2. Praise, Wei Zheng, Yin Huisheng "vernacular big data and machine learning", Machinery Industry Press
  3. Wikipedia: neurons
  4. Wikipedia: neural networks
  5. Baidu Encyclopedia: tensorflow
  6. Wikipedia: Machine Learning

 

 

       

 

Guess you like

Origin www.cnblogs.com/OldAtaraxi/p/12175140.html