Comprehensive Guide to Artificial Intelligence with Python (Translate.p3)

Tram Ho

Source: Edureka

In part 2 we explored through 4 topics:

  1. Machine Learning Basics
  2. Types Of Machine Learning
  3. Types Of Problems Solved By Using Machine Learning
  4. Machine Learning Process

Continuing in this section, we will explore the following topics:

  1. Machine Learning With Python
  2. Limitations Of Machine Learning
  3. Why Deep Learning?
  4. How Deep Learning Works?
  5. What Is Deep Learning?
  6. Deep Learning Use Case
  7. Perceptrons
  8. Multilayer Perceptrons

9. Machine Learning With Python

In this section, we will deploy Machine Learning using Python. Let’s get started.

Problem Statement: To build a Machine Learning model, predict whether it will rain tomorrow by studying past data.

Data Set Description: This dataset contains about 145k observations about daily weather conditions as observed from many weather stations in Australia. The dataset has about 24 features and we will use 23 features (Predictor variables) to predict the target variable, which is “RainTomorrow”.

Download weatherAUS dataset: here.

This target variable (RainTomorrow) will store two values:

  • Yes: Indicates that it will rain tomorrow
  • No: Indicates that it will not rain tomorrow

Therefore, this is clearly a classification problem. Machine Learning model will classify the output into 2 classes, YES or NO.

Logic: Building Classification models to predict whether it will rain tomorrow or not based on weather conditions.

Now that the goal is clear, let our brain work and start coding.

Step 1: Enter the required libraries

Step 2: Download the data set

Run the command python main.py will show results:

Step 3: Data processing

And result is:

Note the output, it shows that the first four columns have more than 40% null values, so it is best if we exit these columns.

During preprocessing data, it is always necessary to eliminate insignificant variables. Unnecessary data will only increase our calculations. Therefore, we will remove the ‘location’ and ‘date’ variables because they are not significant in predicting the weather.

We will also remove the variable ‘RISK_MM’ because we want to predict ‘RainTomorrow’ and RISK_MM (rainfall the next day) may leak some information for our model.

Next, we will delete all null values in our data frame.

After eliminating null values, we must also check our data set for any exceptions. An exception is a data point that is significantly different from other observations. Exceptions often occur due to miscalculation during data collection.

In the code below, we will remove the exception:

Recorded results:

Next, we will specify 0s and 1s in place of YES and NO.

Now, time to standardize data to avoid any frustration while predicting results. To do this, we can use the MinMaxScaler function included in the sklearn library.

The result will be:

Step 4: Analyze exploration data (EDA)

Now that we have pre-processed the data set, it’s time to examine the performance analysis and identify key variables that will help us predict the outcome. To do this, we will use the SelectKBest function found in the sklearn library:

The output gives us the three most important predictor variables:

  1. Rainfall
  2. Humidity3pm
  3. RainToday

Index(['Rainfall', 'Humidity3pm', 'RainToday'], dtype='object')

The main purpose of this demo is to help you understand how Machine Learning works, so to simplify the calculations, we will only assign one of these important variables as an input.

In the code above, X and y Indicates the corresponding input and output.

Step 5: Build a Machine Learning Model

In this step, we will build the Machine Learning model using a training data set and evaluate the effectiveness of the model using the testing data set.

We will build classification models using the following algorithms:

  1. Logistic Regression
  2. Random Forest
  3. Decision Tree
  4. Support Vector Machine

Below is the code snippet for each of the following classification models:

Logistic Regression

Random Forest Classifier

Decision Tree Classifier

Support Vector Machine

All grading models give us an accuracy score of 83-84% except for Support Vector Machines. Considering the size of our dataset, the accuracy is pretty good.

To learn more about Machine Learning, read these blogs:

  1. What is Machine Learning? Machine Learning For Beginners
  2. Machine Learning Tutorial for Beginners
  3. Latest Machine Learning Projects to Try in 2019

10. Limitations Of Machine Learning

The following are the limitations of Machine Learning:

  1. Machine Learning is not capable of processing and processing height data (high dimensional data).
  2. It cannot be used in image recognition and object detection because they require height data.
  3. Another major challenge in Machine Learning is telling the machine the important features to look for to accurately predict results. This process is called feature extraction. Feature extraction is a manual process in Machine Learning.

The above limitations can be solved by using Deep Learning.

11. Why Deep Learning?

  • Deep learning is one of the only ways we can overcome the challenges of feature extraction. This is because deep learning models are capable of self-learning focusing on appropriate features, requiring minimal human intervention.
  • Deep Learning is mainly used to deal with height data. It is based on the concept of Neural Networks and is often used in object detection and image processing.

Now let us understand how Deep Learning works.

12. How Deep Learning Works?

Deep Learning mimics the basic component of the human brain called a brain cell or a neuron. Inspired from a neuron an artificial neuron was developed.

Deep Learning is based on the function of a biological neuron, so let’s understand how we mimic this function in artificial neurons (also known as perceptionrons):

  • In a biological neuron, Dendrites are used to receive input. These inputs are summarized in the cell body and through Axon it is transmitted to the next neuron.
  • Similar to biological neurons, a perceptron receives multiple inputs, applies different transformations and functions, and provides an output.
  • The human brain consists of many connected neurons called neural networks, similarly, by combining multiple perceptrons, we have developed what is known as the Deep neural network.

Now understand exactly what Deep Learning is

13. What Is Deep Learning?

Deep Learning is a collection of statistical machine learning techniques used to learn feature hierarchies based on the concept of artificial neural networks.

A Deep neural network consists of the following classes:

  1. The Input Layer
  2. The Hidden Layer
  3. The Output Layer

In the picture above:

  • The first class is the input layer that accepts all inputs.
  • The final layer is the output layer that provides the desired output.
  • All layers in between these layers are called hidden layers.
  • There may be n number of hidden layers, the number of hidden layers and the number of perceptions in each class that will completely depend on the use case you are trying to solve.

Deep Learning is used in highly computational use cases like Face verification, self-driving cars, etc. Understand the importance of Deep Learning by looking at real-world use cases.

14. Deep Learning Use Case

Consider how PayPal uses Deep Learning to identify any possible fraudulent activities. PayPal has processed more than $ 235 billion in payments from four billion transactions of more than 170 million customers.

PayPal used Machine learning and Deep Learning algorithms to extract data from customers’ purchase histories in addition to looking at fraudulent patterns that might be stored in their databases to predict Whether the deal is fraudulent or not.

The company has relied on Deep Learning & Machine Learning technology for about 10 years. Initially, the fraud monitoring team used simple linear models. But over the years, the company turned to a more advanced Machine Learning technology called Deep Learning.

Fraud management and Data Scientist at PayPal, Ke Wang, cites:

What we enjoy from more modern, advanced machine learning is its ability to consume a lot more data, handle layers and layers of abstraction and be able to ‘see’ things that a simpler technology would not be able to see, even human beings might not be able to see.

A simple linear model is capable of consuming about 20 variables. However, with Deep Learning technology, one can run thousands of data points.

“There’s a magnitude of difference — you’ll be able to analyze a lot more information and identify patterns that are a lot more sophisticated”

Therefore, by implementing Deep Learning technology, PayPal can finally analyze millions of transactions to identify any fraudulent activity.

To better understand Deep Learning, understand how Perceptron works.

15. What Is A Perceptron?

A perceptron is a single-layer neural network used to classify linear data. Perceptron has 4 important components:

  1. Input
  2. Weights and Bias
  3. Summation Function
  4. Activation or transformation Function

The basic logic behind a perceptron is as follows:

The inputs (x) received from the input layer are multiplied by the specified weight w. The multiplier values are then added to form the Weighted Sum. The total weight of the inputs and their corresponding weights are then applied to the relevant Activation Function. The function activates the input mapping to the corresponding output.

Weights and Bias In Deep Learning

Why do we have to assign weights to each input?

When an input variable is entered into the network, a randomly chosen value is assigned as the weight of that input. The weight of each input data point indicates the importance of that input in predicting the outcome.

On the other hand, the bias parameter allows you to adjust the trigger function curve in a way that achieves the correct output.

Summation Function

When the inputs are assigned a weight number, the product of the input and the corresponding weight are taken. Adding all these products gives us the weighted Sum. This is done by the sum function.

Activation Function

The main purpose of the trigger function is to map the total weight to the output. Activation functions such as fishy, ReLU, sigmoid, etc. are examples of transformation functions.

To learn more about Perceptron’s functions, you can take a look at the Deep Learning blog: Perceptron Learning Algorithm.

Now understand the concept of Perceptionron multilayer.

16. Multilayer Perceptrons

Why Multilayer Perceptron Is Used?

A Perceptionron class does not have the ability to handle height data and they can be used to classify non-linear disaggregated data.

Therefore, complex issues involving a large number of parameters can be solved using Multilayer Perceptrons.

What Is A Multilayer Perceptron?

A Multilayer Perceptron is a classifier containing one or more hidden layers and it is based on the artificial feedforward neural network. In Feedforward networks, each neural network layer is fully connected to the next.

How does Multilayer Perceptron Work?

In a multi-layer Perceptionron, the weights assigned to each input are initially updated to minimize errors resulting in calculations.

This is done because initially we randomly assigned weight values to each input, which obviously didn’t give us the desired results, so it was necessary to update the weights so that the output is correct.

The process of updating weights and training networks is called Backpropagation.

Backpropagation is the logic behind multi-layer Perceptionrons. This method is used to update the weights so that the most important input variable has a maximum weight, thus reducing errors while calculating the output.

So that’s the logic behind Artificial Neural Networks. If you want to learn more, make sure you provide it, read more Neural Network Tutorial – Multi-Layer Perceptron.

Share the news now

Source : Viblo