What is Machine Learning?
Hi guys,
Today I will be giving you a tutorial on one of the most talked about topics
in the world of technology, and that is machine learning.
I’m sure that if you are reading this post, you must have heard about
machine learning somewhere or the other, and yes, it is quite an intriguing
topic.
This article will act as a supplement for those who know the basics of
machine learning and are aware of where it is being used and how it is being
used. For those who are completely new to this, you don’t have to worry. We will
be brushing up the basics as well.
Life Without Machine Learning
Well,
So to start off with, let's have a look at the agenda. First, we'll look
into a life without machine learning. Then we'll move into a life with machine
learning. Next, we'll try to understand what machine learning actually is.
We'll then look into the types of machine learning and discuss the right
machine learning solutions. Finally, we'll move into the different algorithms
that machine learning has.
Let's talk about a life without machine learning. For someone who doesn't
know anything about machine learning or artificial intelligence, they might
think it is only being used in robots or machines, which is actually true as
portrayed by most of the sci-fi movies nowadays. But you wouldn't believe how
much more machine learning is giving us and how much of it we are using in our
daily lives.
Let's say you need information on any random topic, say a computer. The
first place you would check would definitely be Google, right? It would collect
all the information on the word you search for and present it to you according
to relevance. If there was no Google, you would have to do it the hard way,
that is, by going through tens or hundreds of books and articles, even after
which you might not find the answer.
If we go back four to five years, facial recognition would be a thing only
shown in movies like Mission Impossible or Terminator or any of the sci-fi
movies you pick. But machine learning has made it possible for Facebook and
Instagram to use this feature for your benefit. You don't have to go through
the trouble of tagging every single person in a picture you have posted.
Facebook will automatically recognize the people in the photo and tag them for
you. That saves a lot of time for you, doesn’t it?
Also, Siri, Cortana, Iris—all of them would not be there to help you if
there was no machine learning.
Now that we know life would be a lot more difficult without machine
learning, let's look into the things that are run by machine learning and that
we use on a daily basis.
Let’s enter the world of gaming. PS4s and Xboxes have introduced virtual
reality glasses, which bring a whole new level of detail into gaming. Every
time your head moves in the real world, it replicates the movement in the
virtual world, providing an excellent gaming experience. Then there is gesture
control gaming, where machine learning tracks your body movement and makes a
corresponding movement in the game. Finally, in the game FIFA, your opponent
tends to adapt based on the kind of strategy or gameplay you follow. That is
again done by machine learning.
I’m sure you must have shopped a lot from Amazon, so let’s look into some of
the places Amazon makes use of machine learning. Let’s say you buy a formal
t-shirt on Amazon. Now, as you buy it, it suggests formal shoes, ties, blazers,
and apparel that go with what you have bought. That’s the recommendation system
powered by machine learning. The price on every product you see on Amazon
varies every moment based on demand. That’s being done by machine learning
algorithms.
Then comes customer segmentation. Customer segmentation is one of the most
crucial aspects for all e-commerce platforms. Machine learning helps them
differentiate between customers based on what they buy, how frequently they
buy, and their reviews. This helps the companies ensure that their customers
are taken care of and their needs are being fulfilled.
Now let’s talk about an app that you use on a daily basis to reach the
office on time. Yes, it's Uber. Once you have traveled with Uber, you must have
noticed that it suggests places you might want to go based on your previous
journeys. When you are taking a share, how does the app ensure that the cab you
get travels by the same route you want to travel in? There are many factors
like the distance, the traffic, the ratings—all of it is taken care of by
machine learning.
For the past five minutes, we have been talking about how machine learning
is improving our lives and where it is being used. I have probably said
"machine learning" 100 times already.
What is Machine Learning?
I think it's about time that I tell you what machine learning actually is.
Let’s take an ordinary system that you are currently using. It can’t do much except perform the basic operations that you already know about.
Now, let’s add artificial intelligence, or from a layman's point of view, let’s give the same machine the power to think on its own. That is what machine learning basically is.
It's an application of artificial intelligence that provides systems the ability to learn on their own and improve from experience without being programmed externally.
So, if your computer had machine learning, it might be able
to play the difficult parts of a game for you or probably solve a complicated
mathematical equation for you. That could be really helpful.
Machine Learning Process
Let’s dive in a little deeper and see how machine learning works.
Let’s say you provide a system with input data that contains photos of various kinds of fruits. Now you want the system to figure out what the different fruits are and group them accordingly. So, what the system does is analyze the input data.
Then, it tries to find patterns, such as shapes, sizes, and colors. Based on these patterns, the system will try to predict the different types of fruit and segregate them.
Finally, it keeps track of all the decisions it made in the process to make sure it’s learning. The next time you ask the same system to predict and segregate different types of fruits, it won’t have to go through the entire process again.
That’s how machine learning works.
Types of Machine Learning
Now let’s look into the types of machine learning.
Machine learning is primarily of three types. The first one is supervised machine learning. As the name suggests, you have to supervise your machine learning while you train it to work on its own. It requires labeled training data.
Next up is unsupervised learning, wherein there will be training data, but it won’t be labeled.
Finally, there’s reinforcement learning, wherein the system learns on its own.
Let’s talk about all these types in detail.
Let’s try to understand how machine learning works. Look at the pictures very, very carefully. The monitor depicts the model or the system that we are going to train. This is how the training is done: we provide a data set that contains pictures of a kind of fruit, say an apple. Then we provide another data set which lets the model know that these pictures were of a fruit called apple. This ends the training phase.
Now, what we will do is provide a new set of data that only contains pictures of apples. Now here comes the fun part: the system can actually tell you what fruit it is, and it will remember this and apply this knowledge in the future as well. That’s how supervised learning works; you are training the model to do a certain kind of operation on its own. This kind of model is generally used in filtering spam emails from your email accounts as well. Yes, surprise, aren’t you?
So let’s move on to unsupervised learning. Let’s say we have a data set that is cluttered. In this case, we have a collection of pictures of different fruits. We feed this data to the model, and the model analyzes the data to figure out patterns in it. In the end, it categorizes the photos into types based on their similarities, as you can see in the image. So you provide the data to the system and let the system do the rest of the work. Simple, isn’t it? This kind of model is used by Flipkart to figure out the products that are well suited for you. Honestly speaking, this is my favorite type of machine learning out of all the three, and this type has been widely shown in most of the sci-fi movies lately.
Let’s find out how it works. Imagine a newborn baby. You put a burning candle in front of the baby. The baby does not know that if it touches the flame, its fingers might get burned. So it does that anyway and gets hurt. The next time you put that candle in front of the baby, it will remember what happened the last time and would not repeat what it did. That’s exactly how reinforcement learning works. We provide the machine with a data set wherein we ask it to identify a particular kind of fruit, in this case an apple. So what it does as a response is tell us that it’s a mango. But as we all know, that’s a completely wrong answer. So as feedback, we tell the system that it’s wrong—it’s not a mango, it’s an apple. What it does is learn from the feedback and keeps that in mind. The next time when we ask the same question, it gives us the right answer. It is able to tell us that it’s actually an apple. That is a reinforced response. So that’s how reinforcement learning works; it learns from its mistakes and experiences. This model is used in games like Prince of Persia, Assassin's Creed, or FIFA, where the level of difficulty increases as you get better with the games.
Just to make it more clear for you...
Supervised Vs Unsupervised
Let’s look at a comparison between supervised and unsupervised learning.
Firstly, the data involved in supervised learning is labeled, as we mentioned in the examples previously. We provide the system with a photo of an apple and let the system know that this is actually an apple. That is called labeled data, so the system learns from the labeled data and makes future predictions.
Now, unsupervised learning does not require any kind of labeled data because its work is to look for patterns in the input data and organize it.
The next point is that you get feedback in the case of supervised learning. That is, once you get the output, the system tends to remember that and uses it for the next operation. This does not happen with unsupervised learning.
And the last point is that supervised learning is mostly used to predict data, whereas unsupervised learning is used to find hidden patterns or structures in data.
I think this would have made a lot of things clear for you regarding supervised and unsupervised learning.
Now let’s talk about a question that everyone needs to
answer before building a machine learning model: What kind of machine learning
solution should we use?
The Right Machine Learning Solution
Yes, you should be very careful with selecting the right kind of solution for your model because if you don't, you might end up losing a lot of time, energy, and processing cost.
I won’t be naming the actual solutions because you guys aren’t familiar with them yet. So we will be looking at it based on supervised, unsupervised, and reinforcement learning.
Let’s look into the factors that might help us select the right kind of machine learning solution.
The first factor is the problem statement. This describes
the kind of model you will be building or, as the name suggests, tells you what
the problem is. For example, let’s say the problem is to predict future stock
market prices. For anyone who is new to machine learning, figuring out the
right solution might be challenging. But with time and practice...
Machine Learning Algorithms
You will understand that for a problem
statement like this, a solution based on supervised learning would work the
best for obvious reasons.
Then comes the size, quality, and nature of
the data. If the data is cluttered, you go for unsupervised learning. If the
data is very large and categorical, we normally go for supervised learning
solutions.
Finally, we choose the solution based on its
complexity. For the problem statement of predicting stock market prices, it can
also be solved using reinforcement learning, but that would be very, very
difficult and time-consuming, unlike supervised learning.
Algorithms are not types of machine learning.
In the simplest terms, they are methods of solving a particular problem.
The first kind of method is classification,
which falls under supervised learning. Classification is used when the output
you are looking for is a yes or no, or in the form of A or B, or true or false.
For example, if a shopkeeper wants to predict if a particular customer will
return to his shop or not, he will use a classification algorithm. The
algorithms that fall under classification include decision tree, Naive Bayes,
random forest, logistic regression, and KNN.
The next kind is regression. This method is
used when the predicted data is numerical in nature. For instance, if the
shopkeeper wants to predict the price of a product based on its demand, he
would use regression.
The last method is clustering. Clustering is a
kind of unsupervised learning used when the data needs to be organized. Most of
the recommendation systems used by Flipkart, Amazon, etc., make use of
clustering. Another major application of clustering is in search engines.
Search engines study your old search history to figure out your preferences and
provide you with the best search results. One of the algorithms that fall under
clustering is K-means.
Now that we know the various algorithms, let’s
look into four key algorithms that are used widely. We will understand them
with very simple examples. The four algorithms we will explore are K-Nearest
Neighbors, Linear Regression, Decision Tree, and Naive Bayes.
Let’s start with our first machine learning
solution: K-Nearest Neighbors (KNN). K-Nearest Neighbors is a classification
algorithm. As you can see on the screen, similar data points form clusters: the
blue one, the red one, and the green one. There are three different clusters.
Now, if we get a new and unknown data point, it is classified based on the
cluster closest to it or the most similar to it. The "K" in KNN is
the number of nearest neighboring data points we wish to compare the unknown
data with.
key Nearest Labours - Example
Let’s make it clear with an example.
Let’s say we have three clusters in a cost-to-durability graph. The first cluster is of footballs, the second one is of tennis balls, and the third one is of basketballs. From the graph, we can say that the cost of footballs is high and the durability is less, the cost of tennis balls is very low but the durability is high, and the cost of basketballs is as high as the durability.
Now, let’s say we have an unknown data point. We have a black spot which could be one of the balls, but we don’t know what kind it is. So, what we’ll do is try to classify this using KNN.
If we set K equal to 5, we draw a circle with the unknown data point at the center and ensure that we have five balls inside that circle. In this case, we have a football, a basketball, and three tennis balls.
Since we have the highest number of tennis balls inside the circle, the classified ball would be a tennis ball.
So that’s how K-Nearest Neighbor classification is done.
Linear Regression
Linear regression is again a type of supervised learning algorithm. This algorithm is used to establish a linear relationship between variables, one of which would be dependent and the other independent. For example, if we want to predict the weight of a person based on their height, weight would be the dependent variable and height would be independent.
Let’s have a look at it through an example.
Let’s say we have a graph showing the relationship between height and weight of a person. Let’s put the y-axis as height and the x-axis as weight. The green dots represent various data points.
These green dots are the data points, and `d` is the mean squared error. That is, the perpendicular distances from the line to the data points represent the error values. This error tells us how much the predicted values vary from the original values.
Let’s ignore the blue line for a while. Suppose this is our regression line. You can see the distance from all the data points to this line is very high. If we take this line as our regression line, the error in the prediction will be too high. Thus, the model will not be able to give us a good prediction.
Now, let’s say we draw another regression line like this. Even in this case, the perpendicular distance of the data points from the line is very high, so the error value will still be high, and this model will also not be able to give us a good prediction.
So, what to do?
Finally, we draw a line which is this blue line. Here, we can see that the distance of the data points from the line is very low compared to the other two lines we drew. Thus, the value of `d` for this line will be very low.
So, if we take any value on the x-axis, the corresponding value on the y-axis will be our prediction. Given that `d` is very low, our prediction should be good.
This is how regression works: we draw a regression line in
such a way that the value of `d` is minimized, eventually giving us good
predictions.
Decision Tree
The decision tree algorithm is one you can relate to very strongly. It uses a branching method to analyze the problem and make decisions based on various conditions.
Let’s take this graph as an example. Imagine you’re sitting at home, getting bored, and feel like going for a swim. What you do is check if it’s sunny outside; that’s your first condition. If the answer is yes, you go for a swim. If it’s not sunny, then the next question you would ask yourself is if it’s raining outside; that’s condition number two. If it’s actually raining, you cancel the plan and stay indoors. If it’s not raining, you would probably go outside and have a walk, which is the final node.
That’s how the decision tree algorithm works. It evaluates a
problem and makes decisions based on the answers to each condition. You
probably use this every day—it analyzes the problem and makes decisions based
on the answers to various conditions.
This algorithm is most commonly used in filtering spam emails in your email account. Let’s say you receive an email. The model goes through your old spam email records and then uses Bayes' theorem to predict if the present email is spam or not. Here’s how it works:
- \( P(C|A) \) is the probability of event C occurring given
that A has already occurred.
- \( P(A|C) \) is the probability of event A occurring given
that C has already occurred.
- \( P(C) \) is the probability of event C occurring.
- \( P(A) \) is the probability of event A occurring.
Naïve Bayes
Let’s try to understand Naive Bayes with a better example. Naive Bayes can be used to determine on which days to play cricket based on the probabilities of a day being rainy, windy, or sunny. The model tells us if a match is possible.
If we consider all the weather conditions to be event A for us, and the probability of a match being possible as event C, the model applies the probabilities of event A and C into Bayes' theorem and predicts if a game of cricket is possible on a particular day or not.
In this case, if the probability \( P(C|A) \) is more than 0.5, we can play a game of cricket. If it’s less than 0.5, we won’t be able to. That’s how the Naive Bayes algorithm works.
So that brings us to the end of the post. I hope you guys
understood the concepts. Put your doubts and feedback in the comments below.
ConversionConversion EmoticonEmoticon