Getting Started with machine learning-understanding machine learning + Simple perceptron (Java implementation)

Source: Internet
Author: User

First, let's talk about gossip.

 If you go to machine learning now, will you go? Is it because you are not interested in this aspect, or because you think this thing is too difficult, you will not learn? If you feel too difficult, very good, believe that after reading this article, you will have the courage to step into the field of machine learning.

Machine learning (machine-learning), a person who has been programming for a year, seems to be a very tall thing, and unknowingly touches it. Summer vacation When my cousin assigned me a task, on GitHub there is a deeplearningflappybird, he then asked me to let this code run in a day, and then the next day to translate this code into C + + ... wtf???   I was a face confused, a learning program one year less, C and C + + level is almost the kind of college classroom after teaching, run up may be easy, but to translate?!! Spare me, Orz. With a day's environment, it was almost 12 o'clock that night, and finally ran. Then the next day, I went to check the tensorflow,opencv3 on vs to use, found that there is no way ... My computer is VS2013, there are only 32-bit, emmmm. The next VS2017, look at the computer space, not enough! OK, give up, later have a free to panic again to do it ....

A few days ago, there is nothing to do, suddenly think of machine learning (in fact, Dalao mentioned the perception machine this thing), try to do it, also as a primer.

Let's talk about machine learning.

 Machine learning is the same as human learning is the same, but the machine can be endless learning, and machine learning completely do not need to understand what the principle, as long as know how to achieve the line. Like Alpha Go, do you think it understands chess? I think certainly do not understand, but through the countless game of learning, people feel that it must have mastered the true meaning of Weiqi.

Standard paradigm expression of machine learning

For the measurement of a task and its performance, a specific algorithm is given, which can be continuously improved by using experience data on the task.
The performance method is called machine learning.

  In fact, this definition is "learning" the full meaning of this thing according to the machine's thinking to do, is machine learning

Plainly, as long as the algorithm is reasonable, each learning can be improved, the machine has enough computing power, can be the machine's ability to achieve the ultimate to surpass human beings. The essence of machine learning is to establish a relational library ("Data"-"cognition").

So here's the sense machine.

First, pull the definition: The perceptron (perceptron) is a linear classification model of the two classification, entered as an instance of the eigenvector, and output as the class of the instance (take +1 and-1). The perceptron corresponds to the separation of the instances into two classes of detached hyper-planes in the input space. The perceptual machine is designed to obtain the super plane, and the loss function based on the error classification is introduced for the super plane, and the loss function is optimized by the gradient descent method. The learning algorithm of perceptual machine has the advantages of simple and easy to realize, which are divided into primitive form and dual form. Perceptron prediction is a model that is used to predict new instances by learning the perceptual machine model. The Perceptron, presented by Rosenblatt in 1957, is the foundation of neural networks and support vector machines.

Take a two-dimensional plane example,

Look at this picture, it is clear that the line does not completely separate the red and blue points in two areas, we can call it the wrong line, the perception of the confidential do, is based on the coordinates of the points, the wrong line corrected to the correct, so that the resulting line is the result of training.

How do you make it so much? look at the flowchart below.

    /** Determine the location of all points and classify them*/     Public Booleanclassify () {BooleanFlag =false;  while(!flag) {             for(inti = 0; I < arraylist.size (); i++) {                if(Anwser (Arraylist.get (i)) <= 0{Update (Arraylist.get (i));  Break; }                if(i + 1 = =arraylist.size ()) {Flag=true; }            }        }        return true; }

    /** Point multiply return sum*/    Private DoubleDot (Double[] W,Double[] x) {Doublesum = 0;  for(inti = 0; i < x.length; i++) {sum+ = w[i] *X[i]; }        returnsum; }    /** Returns the value calculated by the function*/    Private DoubleAnwser (Point point) {System.out.println (arrays.tostring (w));        System.out.println (b); returnPoint.y * (Dot (w, point.x) +b); }

If there is doubt, it may be W and b How to modify, we will define a variable η (0≤η≤1) as a step, in statistics is the learning rate. The larger the step size, the faster the gradient drops and the closer to the minimum point. If the step size is too large, it is possible to cross a minimum, resulting in a function divergence, and if the step size is too small, it may take a long time to reach the minimum. Default is 1

For WI wi+=η*y*xi

For b b+=η*y

     Public void Update (Point point) {        for (int i = 0; i < w.length; i++) {            + = ETA * point. Y * point.x[i];        }         + = ETA * point.y        ; return ;    }

In this way, we can complete the update of W and B.

By combining the above steps, you can implement the perceptual machine.

Talk about your thoughts.

After writing this perceptual machine, found that machine learning is not so difficult to imagine, in fact, as long as know how to calculate it can be (at present more superficial understanding, perhaps I have not touched the difficult place), and Python, the machine learning library can be said to be very perfect, if familiar with the use of these libraries, even if you do not understand the algorithm , you can use these libraries to do development, you know the algorithm and the development of the job is not the same

This is the test case and the result I selected

1         New Point (newdouble[] {0, 0, 0, 1},-1); 2         New Point (newdouble[] {1, 0, 0, 0}, 1); 3         New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2.0[2.0,-1.0, 0.0,-6.0]2.0[2.0,-1.0, 0.0,-6.0]2.0[2.0,-1.0, 0.0,-6.0]2.0

 

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.