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 realize convolution Neural Network based on Libra

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

Share

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

This article mainly introduces "how to realize the convolution neural network based on Libra". In the daily operation, I believe that many people have doubts about how to realize the convolution neural network based on Libra. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to realize the convolution neural network based on Libra". Next, please follow the editor to study!

Using Libra to detect Credit Card Fraud

I used the Kaggle dataset to predict credit card fraud. The data has been analyzed by principal component analysis, so it is now simplified to smaller dimensional data than the original data.

In solving this problem, we need to follow a systematic approach. Generally speaking, you will follow the order mentioned in the first paragraph. But with Libra, you don't have to worry.

Most of the transactions in this data are non-fraudulent in time (99.83%), while fraudulent transactions occur in the dataset (0.17%). This means that the data are highly unbalanced. Let's take a look at the data preprocessing and results of Libra.

Install Librapip install-U libra Import client from libra (client) from libra import client using Libra

Everything is built around client. You can call different queries on it, and all the contents will be stored under the object's models field.

We pass the location of the file in the client object and name it newClient. To access various queries now, refer to the documentation.

I use the decision tree. For example, forecast the median value of a house, or estimate the number of households. Otherwise, the code should correspond to the columns in the dataset. Libra automatically detects the target column, but to make sure it selects the correct column, I have passed the name of the target column.

NewClient = client ('creditcard.csv') newClient.decision_tree_query (' Class')

With only two lines of code, we got a score of about 0.99, which is the best we can get. If you check the success of others, you will find that only a few people get 0.99% accuracy, and they spend hours preprocessing data and writing code for it.

In this case, Libra saves you a lot of time and gives you the best results. Libra uses intelligent preprocessing so you don't have to preprocess the data yourself.

You don't have to worry about the analysis.

NewClient.analyze () creates confusion matrices and ROC curves for all classification problems. It also calculates recall rates, accuracy, F1 and f2 scores.

NewClient.analyze ()

NewClient.info () returns all the keys representing each data category generated for the dataset.

NewClient.info ()

NewClient.model () returns the dictionary of the model. It includes everything from accuracy, accuracy, recall rates, F1 scores to all preprocessing techniques. This is more helpful for those who already understand these concepts and are able to write code. Non-technical users need not worry about this.

NewClient.model ()

Access model

NewClient.model () returns a dictionary, and if you want to access the model, you can directly use newClient.model () ['model']

NewClient.model () ['model']

Convolution Neural Network based on Libra

In colab Notebook, use the following code to download the rock scissors paper data set. I could have shown you the code to create CNN using Libra directly, but I want to create an example that you can try in colab Notebook to better understand. You don't need to worry about the following code.

! wget-- no-check-certificate\ https://storage.googleapis.com/laurencemoroney-blog.appspot.com/rps.zip\-O / tmpUnip rps.zipchangwget-- no-check-certificate\ https://storage.googleapis.com/laurencemoroney-blog.appspot.com/rps-test-set.zip\-O / tmp/rps-test-set.zip

Use the following code to extract the downloaded file.

Import osimport zipfilelocal_zip ='/ tmp/rps.zip'zip_ref = zipfile.ZipFile (local_zip,'r') zip_ref.extractall ('/ tmp/') zip_ref.close () local_zip ='/ tmp/rps-test-set.zip'zip_ref = zipfile.ZipFile (local_zip,'r') zip_ref.extractall ('/ tmp/') zip_ref.close ()

We use the following code to create a folder and put the extracted image into it.

Rock_dir = os.path.join ('/ tmp/rps/rock') paper_dir = os.path.join ('/ tmp/rps/paper') scissors_dir = os.path.join ('/ tmp/rps/scissors') print ('total training rock images:', len (os.listdir (rock_dir) print (' total training paper images:', len (os.listdir (paper_dir) print ('total training scissors images:') Len (os.listdir (scissors_dir)) rock_files = os.listdir (rock_dir) print (rock_files [: 10]) paper_files = os.listdir (paper_dir) print (paper_files [: 10]) scissors_files = os.listdir (scissors_dir) print (scissors_files [: 10])

The following figure shows information about the dataset

Using the following code, you can create a CNN. The data is automatically increased by scaling, cutting, flipping, and rescaling. Then choose the best image size. You will also notice the number of images in each class and the number of classes associated with it. Finally, the training accuracy and test accuracy should be observed.

You can also pass the read_ mode superparameter inside the convolutional_query, where you can specify the read mode. Three read modes are allowed. I will describe them one by one. By default, * * read_mode=distinguisher () * * automatically detects data types. The three read modes allowed are:

1.Setwise

The directory consists of "training_set" and "testing_set" folders, both of which contain classified folders with images.

2.Classwise

The directory consists of classified folders that contain images.

3.CSV Wise

The directory consists of an image folder and a CSV file that contains image columns.

NewClient = client ('/ tmp/rps') newClient.convolutional_query ("Please classify my images")

NLP text Classification based on Libra

I use spam classified datasets to solve this problem.

Link: https://www.kaggle.com/team-ai/spam-text-message-classification

New_client = client ('SPAM text message 20170820-Data.csv') new_client.text_classification_query (' sentiment') new_client.classify_text ('new text to classify')

New_client.classify_text () classifies the text entered into it. In the output above, you can see that it classifies my text as "ham".

Using Libra for mean clustering

I use mall customer segmentation data to solve this problem: https://www.kaggle.com/vjchoudhary7/customer-segmentation-tutorial-in-python

Libra will create a K-means clustering model, and will determine the best cluster center, optimization accuracy, and the best number of clusters.

Neural Network Classification based on Libra

In this section, I will use neural network queries for classification. To do this, I used a private data set to predict the behavior of brain signals. Let's check its execution on that dataset.

New_client = client ('Mood_classification.csv') new_client.neural_network_query (' Predict the behavior')

From the above code, you can notice that the initial number of layers used by the model is 3. Then, it also tests the accuracy of different layers, which vary according to the performance of the previous layer.

It can predict the optimal number of layers to be found and the accuracy of training and testing. It seems that I need to collect more data for my dataset.

You can access the model with new_client.model () ['model'], and you can use the summary () function of Keras to get a summary of the neural network model.

New_client.model () ['model'] .summary ()

At this point, the study of "how to realize the convolution neural network based on Libra" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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