3 Introduction To Machine Learning

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Introduction to

Machine learning
Source:
https://campus.datacamp.com/courses/understanding-
machine-learning/machine-learning-models?ex=1

Course Instructor:
ANAM SHAHID
AI, Machine Learning, and Deep Learning, the difference?
Machine learning is a discipline in AI, where computers learn from the data without explicit coding.
Deep learning is a popular technique in machine learning where we use deep neural networks (that is
network with many layers).

What is Machine Learning


In the real world, we are surrounded by humans who can learn everything from their experiences
with their learning capability, and we have computers or machines which work on our instructions.
But can a machine also learn from experiences or past data like a human does? So here comes
the role of Machine Learning.
Machine Learning is said as a subset of artificial intelligence that is mainly concerned with the
development of algorithms which allow a computer to learn from the data and past experiences
on their own. The term machine learning was first introduced by Arthur Samuel in 1959. We can
define it in a summarized way as:

Machine learning enables a machine to automatically learn from data, improve performance
from experiences, and predict things without being explicitly programmed.

Types
There are several types to machine learning

1) Supervised learning
Supervised learning is basically a labeling machine. It takes an observation, and assigns a label to it. In
which machines are trained using well "labelled" training data, and on basis of that data, machines predict
the output. The labelled data means some input data is already tagged with the correct output.

In supervised learning, the training data provided to the machines work as the supervisor that teaches the
machines to predict the output correctly. It applies the same concept as a student learns in the supervision
of the teacher.
Picture Source: 1https://www.javatpoint.com/supervised-machine-learning

Classification and regression


There are two flavors of supervised learning: classification and regression.

1. Classification
Let's focus on classification first. Classification consists in assigning a category to an
observation. Classification algorithms are used when the output variable is categorical, which
means there are two classes such as Yes-No, Male-Female, True-false, etc. We're predicting a
discrete variable, a variable that can only take a few different values. Is this customer going to
stop its subscription or not? Is this mole cancerous or not? Is this wine red, white or rosé? Is this
flower a rose, a tulip, a carnation, a lily?

There are some examples of classification algorithms

o Random Forest
o Decision Trees
o Logistic Regression
o Support vector Machines
o K-NN (K- Nearest Neighbor)

Observations:
Remember, we feed the model observations. Let's take college admissions where we
want to predict acceptance.

Features
For simplification, we show two features here: GPA and admission test results. We could have
more features like: involvement in student organizations and sports or prizes applicants have
won.

Target
And, the target is what we want to predict. There are two possible labels: those who are
accepted and those who are not. The target can only be one of these two labels,
making it a classification problem.
Graphing our data
Here are our observations plotted. GPA on the x axis and test results on the y axis. Blue
points represent accepted applicants, red points represent rejected applicants.

Splitting data
We keep 80% of our data to train our model.

Manual classifier
Because we use just two features, we're able to plot and interpret the results. For us humans,
it's pretty clear. If you score above 4 on both the GPA and entrance test, you're accepted. If we
added more features like extracurricular or prizes, we would need more axes. It would be very
hard for us to interpret the data with our human eye. However, an model wouldn't struggle at all.
We can use a Support Vector Machine. It sounds scary, but it's just a line separating our
points.

Support Vector Machine:

Support Vector Machine or SVM is one of the most popular Supervised Learning algorithms,
which is used for Classification as well as Regression problems. However, primarily, it is used for
Classification problems in Machine Learning.

The goal of the SVM algorithm is to create the best line or decision boundary that can segregate
n-dimensional space into classes so that we can easily put the new data point in the correct
category in the future. This best decision boundary is called a hyperplane.
1. Support vector machine - linear classifier
We train our algorithm and classify the 20% of observations we left aside. It only misclassifies
two blue points as red - meaning two applicants were wrongly predicted as rejected. The
problem is, it tries to separate with a straight line, so it's unlikely to do better than that.

2. Support vector machine - polynomial classifier


What if we allow a curved line instead? Then it classifies everything correctly! There are ways
we can tweak our model's behavior, like allowing curves. We will talk about that later.

2. Regression
Now, what about regression? Regression algorithms are used if there is a relationship between
the input variable and the output variable. While classification assigns a category, regression
assigns a continuous variable, that is, a variable that can take any value. For example, how
much will this stock be worth? What is this exoplanet's mass? How tall will this child be as an
adult? , Weather forecasting, Market Trends, etc

Below are some popular Regression algorithms which come under supervised learning:

o Linear Regression
o Regression Trees
o Non-Linear Regression
o Bayesian Linear Regression
o Polynomial Regression

18. Predicting temperature

Let's look at some new data: weather readings. Can we predict temperature based on humidity?

Training data
We use 80% of the data to train our model. Seems like when humidity rises, temperature
decreases.
Linear regression
Indeed, our linear regression model catches that.

Model
Making this is our model.

Given humidity...
According to our model, if the humidity rate is 0.5, then the temperature is 18.5? C.
And this is how the model performs on real data. It identified the trend, but is still bad at
predicting. More features, like wind, cloudiness, location, and season could make it
more accurate.

Classification vs regression
It's up to you to choose whether you want to frame your problem as a regression or
classification problem. For example, we could predict an exact temperature
(regression), or a categorical range of temperatures like "Cold", "Mild", and "Hot"
(Classification). Do you see the difference?

2) Unsupervised Learning
Unsupervised learning is quite similar to supervised learning, except it doesn't have a target column - hence
the unsupervised part. So what's the point then? Unsupervised learning is a learning method in which a
machine learns without any supervision. The training is provided to the machine with the set of data that
has not been labeled, classified, or categorized, and the algorithm needs to act on that data without any
supervision. The goal of unsupervised learning is to restructure the input data into new features or a group
of objects with similar patterns. Unsupervised learning learns from the dataset, and tries to find
patterns. That's the reason this technique is so interesting and powerful: we can find insights without
knowing much about our dataset.
Image Source: https://towardsdatascience.com/what-are-the-types-of-machine-learning-e2b9e5d1756f

Below is the list of some popular unsupervised learning algorithms:

o K-means clustering
o Hierarchal clustering
o Anomaly detection
o Neural Networks
o Neural Networks
o Principle Component Analysis
o Apriori algorithm

Applications
Unsupervised learning has different applications. We'll focus on clustering, anomaly detection,
association.
1. Clustering
Clustering consists in identifying groups in your dataset. The observations in these groups share
stronger similarities with members of their group, than with members of other groups.
Clustering is a method of grouping the objects into clusters such that objects with most
similarities remains into a group and has less or no similarities with the objects of another group.
Cluster analysis finds the commonalities between the data objects and categorizes them as per
the presence and absence of those commonalities.

Clustering example
For example, say we have a dataset with six observations. What clusters would the algorithm
detect?

Species cluster

Well, it depends. It may come up with two groups: dogs and cats.
Color cluster

Or, it might make four groups by color: black, grey, white and brown.

Origin cluster

Or, it may find origin groups: the top row originates from Europe, while the bottom row are from
Japan. In these examples, I've told you what each group represents. However, you usually don't
know what differentiates your clusters in real life. Your model won't tell you why or how it
decided on these clusters. It's up to you to investigate and find out.
Clustering models
Some clustering models, like K-Means, require you to specify in advance the number of clusters
you would like to identify. Others, like DBSCAN, or - get ready - "Density-based spatial
clustering of applications with noise", don't require you to specify the number of clusters in
advance. Instead, they require you to define what constitutes a cluster, like the minimum number
of observations in one cluster.

11. Iris table

Let's say we have flowers of unknown species. All we have is their petal width and length. See
the difference with a classification problem? Here, we don't have a column with labels of the
species. We don't know which species we're dealing with or even how many there are.
12. K-Means with 4 clusters

If we hypothesize there are 4 species, we can use a K Means and require 4 different clusters. It
will result in this clustering.

13. K-Means with 3 clusters

If we hypothesize there are 3 species, we require 3 different clusters.


14. Ground truth

These clusters are actually correct, as there are three different species in the dataset: Setosa,
Virginica and Versicolor.

2. Anomaly detection
Let's now talk about anomaly detection.

Detecting outliers

Anomaly detection is all about detecting outliers. Outliers are observations that strongly differ
from the others.

Some anomaly detection use cases

Detecting outliers can help find which devices fail faster or last longer, which fraudsters trick the
protection systems in place, or which patients surprisingly resist a fatal disease.

3. Association
Let's end with association, which consists in finding relationships between observations. It
determines the set of items that occurs together in the dataset. Association rule makes
marketing strategy more effective. Such as people who buy X item (suppose a bread) are also
tend to purchase Y (Butter/Jam) item. A typical example of Association rule is Market Basket
Analysis.

In other words, it's about finding events that happen together. It's often used for market basket
analysis, which is just a fancy expression to state "Which objects are bought together?" For
example, people who buy jam are likely to buy bread, people who buy beer are likely to buy
peanuts, and people who buy wine are likely to buy cheese.

3) Reinforcement Learning
Reinforcement learning is a feedback-based learning method, in which a learning agent gets a
reward for each right action and gets a penalty for each wrong action. The agent learns
automatically with these feedbacks and improves its performance. In reinforcement learning, the
agent interacts with the environment and explores it. The goal of an agent is to get the most
reward points, and hence, it improves its performance.

The robotic dog, which automatically learns the movement of his arms, is an example of
Reinforcement learning.

Artificial Neural Networks and Deep Learning


Artificial neural network (ANN) is a type of machine learning algorithm where hidden layers are
in small numbers, say 1 or 2.
Deep learning is a discipline in machine learning, and very close to AI, which are based on deep
neural network (where we may many hidden layers). There are different types of deep neural
network, you will learn in an advance course.

Evaluating performance of ML models


You now know more about different model types and their outputs.
Overfitting
A statistical model is said to be overfitted if it can’t generalize well with unseen data.
The first thing to look for when evaluating is overfitting. That's when our model performs
great on training data, but poorly on the testing data. This is bad: it means our model
learned the training set by heart and is unable to generalize learnings to new data,
which is what we originally want. This is why we need to split our dataset into two sets.

Illustrating overfitting

For instance, the green line here overfits. It's going out of its way to classify all points
perfectly, thus performing great on this dataset, but poorly on unseen data. The black
line makes more errors on this specific dataset, but generalizes better.

5. Accuracy

How would we measure the model's performance? We could use accuracy, which is the
number of correctly predicted observations divided by the number of all observations.
We had 48 correct classifications out of 50, which is a 96% accuracy.
Applications of Machine Learning
Different types of machine learning techniques and their application are shown in the following
figures.
Types of machine leaning and applications source: https://laptrinhx.com/an-introduction-to-machine-learning-or-how-to-jump-
start-the-robot-uprising-608526321/

RELATIONSHIP BETWEEN AI, ML, DEEP LEARNING,


DATA SCIENCE, Data Analysis
The terms AI and ML, used interchangeably, but AI is broad domain, still largely
unexplored. AI is a tool for creating better products and imparting them with autonomy.
Data Science is a field that makes use of AI/ML to generate predictions but also focuses
on transforming (Big) data for analysis and visualizations. Data Scientists understand
data from a business point of view and can provide accurate predictions and insights
that can be used to power critical business decisions.
A data analyst is usually the person who can do basic descriptive statistics, visualize
data, and communicate data points for conclusions.
A data scientist creates questions, while a data analyst finds answers to the existing set
of questions.
Image Source:https://www.corpnce.com/relationship-ai-ml-dl-ds/

You might also like