Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use machine learning model for fast image classification and recognition in big data

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

What this article shares with you is about how big data uses the machine learning model to quickly classify and recognize images. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Don't say much. Let's take a look at it.

Zero, preface

We introduce the use of sklearn library to create a machine learning model for classification prediction. The prediction of classification problems also belongs to the category of supervised learning, through the marking of the categories of known data to achieve the prediction and determination of the categories of unknown data.

Common application fields include: spam recognition, spam message recognition, image classification recognition and so on.

Common application algorithms are: SVM (support vector machine), K nearest neighbor, naive Bayesian, random forest and so on.

Next, we introduce the machine learning classification model through the Digits handwritten number set.

I. A preliminary study of handwritten digital data sets

The handwritten digital data set selected in this article also comes from the sklearn.datasets sub-module, which is provided by the famous UCI machine learning library:

The dataset consists of 1797 8x8 images. Every image is a handwritten number.

Just like the previous article on importing the Boston dataset, we imported from the sklearn module:

Then look at the submethods contained in the dataset:

Similar to the Boston dataset, it provides images, target_names, target, data, DESCR, and so on. Where:

Images: the original array that represents the image

Target_names: represents all the numbers in the image classification

Target: represents the numerical name corresponding to the image array

Data: an array of one-dimensional features representing an image

DESCR: represents dataset description information

From these two data sets, we can find that the API of sklearn is quite unified and standardized, which is very convenient to learn and call. Next, let's take a look at what is in each method.

By looking at the shape of images and the shape of the known image 8 × 8, we can see that there are 1797 images in this data set. Look at the contents of one of the images:

This is the form of an image converted into an array. How do we know what kind of image it is? You can restore an image array to an image with the help of the matplotlib module.

Maybe this module was not installed when building the environment before, so let's install it first:

Then introduce the matplotlib module and call the imshow () method:

As you can see, the first image in iamges appears to be the number 0. Let's move on to the following.

Data's target_name information shows that our data represents a numeric category of 0 to 9.

The target value of the data matches the time of the dataset. Finally, take a look at data's data:

The amount of data is still 1797, but the shape has changed from two-dimensional (8, 8) to one-dimensional 64. Let's take a look at a specific data:

It can be found that the array in data.data combines the previous 8 / 8 arrays into an array, so that it is convenient to train and calculate the image array using the algorithm. So how to restore an one-dimensional image array to an image, through the above method, but you need to change the shape of the one-dimensional array first:

We also convert the characteristics and targets of the dataset into the DataFrame of pandas to facilitate students to understand the shape of the dataset:

Second, segmenting the training test set

Also use the train_test_split method provided by sklearn to split the training set and the test set:

Third, create a classification model

Here, we also choose the random forest algorithm as the basic algorithm of the machine learning model estimator to create a machine learning classifier and train it.

IV. Evaluation model

After training the model, we can also use the predict () method of the model to obtain the prediction results of the test set:

In the face of the regression model, we can use the average absolute error, mean square error and other methods to evaluate the effect of the model, while in the classification algorithm model, we use other methods to evaluate the effect of the model. for example: accuracy classification score, recall score and so on. These methods are also under the metrics sub-module of the sklearn module.

Let's evaluate the effectiveness of the classification model:

The best result of the two evaluation methods is 1, it seems that our model is quite accurate, we can try other algorithms to build a classification model.

The above is how big data uses the machine learning model for fast image classification and recognition. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report