Machine Learning Research Based on Dragonboard 410c Development Board (1) K-Nearest Neighbor Algorithm

As the most popular concept, machine learning and artificial intelligence have been widely applied to various fields, such as WeChat, Alipay, Baidu, etc., which are integrated with machine learning algorithms to realize various intelligences. The operation makes the user experience more. For example, in Baidu's online recognition image application, Alibaba's product intelligence recommendation, face recognition verification, etc. all use machine learning related technology, of course, some are more advanced deep learning (the essence) It is also a kind of machine learning, more advanced, specific concepts and about machine learning, deep learning and pattern recognition. You can refer to the deep learning vs machine learning vs pattern recognition three techniques to compare this article), but machine learning can only be used in Are these tall places? Of course not. In fact, when our ordinary developers want to DIY their own things, they can also use machine learning. For example, in your smart car visual obstacle avoidance, machine learning can be used to construct obstacle models in face recognition. You can use machine learning to continuously optimize the recognition results. Fortunately, nonsense is not much to say. If you can use your machine in your DIY, you can use it in your Dragonboard 410c. Is it higher?

There are many algorithms for machine learning. Today, we are going to get an entry level. It is also the simplest algorithm in machine learning. K-Nearest Neighbor Algorithm (KNN), which uses different distances between different eigenvalues ​​to different The objects are classified. In the specific operation process, we need a sample set. All the feature data in this sample set has a corresponding label, that is, the classification attribute corresponding to all the data in this sample set, we know, and then When the new data is input, the KNN algorithm compares the new data with the sample data, and extracts the classification label corresponding to the most similar data in the sample. In the specific KNN processing, only the sample data is usually selected. The top k most similar data, then select the label with the most occurrences of the top k data as the result.

With the above understanding, basically you only need to know that KNN is a simple classifier that classifies things. Since we mentioned classification, we introduce the specific implementation principle and process of KNN algorithm through a simple classification scenario in life. And combined with Python scripts tells you how to write and run the KNN algorithm on the Dragonbaord 410c.

This is a classic example of learning in Machine Learning. According to the number of kissing shots and fighting shots in the movie, whether a movie belongs to a love movie or an action movie can be determined by the following figure. description:

In the above picture, we already know the number of kissing shots and fighting shots of the six movies, but if you give a new movie and tell you the number of kissing shots and fighting shots, how do you determine this movie at this time? What type of movie?

In the analysis, in order to better see the number and type of various lenses of the six movies we already know, the lens and type distribution table of each movie is given below:

According to the KNN algorithm principle discussed earlier, we mainly calculate the distance between the unknown data and the sample data based on the sample data, and then implement the classification according to the frequency of occurrence of the label. Here, if we use KNN to implement the six according to the known The classification of movies to achieve the classification of unknown movies is very simple. The core code of KNN implementation is as follows:

Def classify0(inX, dataSet, labels, k):
dataSetSize = dataSet.shape[0]
diffMat = TIle(inX, (dataSetSize,1)) - dataSet
sqDiffMat = diffMat**2
sqDistances = sqDiffMat.sum(axis=1)
Distances = sqDistances**0.5
sortedDisTIndicies = distances.argsort()
classCount={}
For i in range(k):
voteIlabel = labels[sortedDisTIndicies[i]]
classCount[voteIlabel] = classCount.get(voteIlabel,0) + 1
sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse=True)
Return sortedClassCount[0][0]

In the above code, classify0 contains 4 parameters, which are used for input vector inX, input training sample set dataSet, label vector labels, and select the nearest neighbor number parameter k. In the KNN algorithm used in this paper, the calculated distance uses the commonly used European The distance formula is as follows:

Detailed code can be downloaded from http://pan.baidu.com/s/1mh5W0XU.

Ok, after the code is ready, we can test it. Copy the code to our Dragonbaord 410c via SD card or USB flash drive, then enter the cd command to jump to the code directory, enter Python, and enter the Python command mode. , enter the following test command:

>>> import kNN

>>> group,lables = kNN.createDataSet()

>>>kNN,classify0([0,0],group,lables,3)

We can see that the output is B, as shown in the figure below. At the same time, you can change the input [0,0] to other values ​​and test results during the test.

Here we have successfully completed the writing and testing of our KNN algorithm on the Dragonbaord 410c with the aid of Python scripts. You can use the test code to expand and use the classifier for other recognition and classification in your DIY. Your DIY has become more intelligent, and later I will introduce more complex machine learning algorithms and implementations on the Dragonbaord 410c in the machine learning series blog.

Backlit Bluetooth Keyboard

Wireless Bluetooth Slim Keyboard is disigned for a variety of Bluetooth devices especially the iPad series. which can be easily and quickly switched between the three operating systems of IOS / Android / Windows. And provide helpful function keys for each operating system. Any Bluetooth-enabled device ( tablet, smartphone) can be easily paired and quickly access
Bluetooth Keyboard has 7 colors LED backlight with breathing lights and constant light modes. It provides you with a very precise and sensitive typing experience. With a stable scissor mechanism constructure beneath each keys, The buttons are very smooth and do not get stuck. Press without noise and rebound quickly, effectively improve your work efficiency
Keyboard with scissors kick construction enables nice responsive typing and every key can be used more than 3 million times continuously. The quiet and quickly rebound keys bring a whole new level of comfort to your fingertips

Dongguan Jupu Electronic Co.,Ltd , https://www.jupumade.com

This entry was posted in on