You are on page 1of 9

What is Machine Learning?

Machine Learning involves the use of Artificial Intelligence to enable


machines to learn a task from experience without programming them
specifically about that task. (In short, Machines learn automatically without
human hand holding!!!) This process starts with feeding them good quality
data and then training the machines by building various machine learning
models using the data and different algorithms. The choice of algorithms
depends on what type of data do we have and what kind of task we are
trying to automate.

How to start learning ML?

This is a rough roadmap you can follow on your way to becoming an


insanely talented Machine Learning Engineer. Of course, you can always
modify the steps according to your needs to reach your desired end-goal!

Step 1 – Understand the Prerequisites

In case you are a genius, you could start ML directly but normally, there are
some prerequisites that you need to know which include Linear Algebra,
Multivariate Calculus, Statistics, and Python. And if you don’t know these,
never fear! You don’t need a Ph.D. degree in these topics to get started but
you do need a basic understanding.

(a) Learn Linear Algebra and Multivariate Calculus

Both Linear Algebra and Multivariate Calculus are important in Machine


Learning. However, the extent to which you need them depends on your
role as a data scientist. If you are more focused on application heavy
machine learning, then you will not be that heavily focused on maths as
there are many common libraries available. But if you want to focus on
R&D in Machine Learning, then mastery of Linear Algebra and Multivariate
Calculus is very important as you will have to implement many ML
algorithms from scratch.
(b) Learn Statistics

Data plays a huge role in Machine Learning. In fact, around 80% of your
time as an ML expert will be spent collecting and cleaning data. And
statistics is a field that handles the collection, analysis, and presentation of
data. So it is no surprise that you need to learn it!!!
Some of the key concepts in statistics that are important are Statistical
Significance, Probability Distributions, Hypothesis Testing, Regression, etc.
Also, Bayesian Thinking is also a very important part of ML which deals
with various concepts like Conditional Probability, Priors, and Posteriors,
Maximum Likelihood, etc.

(c) Learn Python

Some people prefer to skip Linear Algebra, Multivariate Calculus and


Statistics and learn them as they go along with trial and error. But the one
thing that you absolutely cannot skip is Python! While there are other
languages you can use for Machine Learning like R, Scala, etc. Python is
currently the most popular language for ML. In fact, there are many Python
libraries that are specifically useful for Artificial Intelligence and Machine
Learning such as Keras, TensorFlow, Scikit-learn, etc.

Step 2 – Learn Various ML Concepts

Now that you are done with the prerequisites, you can move on to actually
learning ML (Which is the fun part!!!) It’s best to start with the basics and
then move on to the more complicated stuff. Some of the basic concepts in
ML are:

(a) Terminologies of Machine Learning

 Model – A model is a specific representation learned from data by


applying some machine learning algorithm. A model is also called a
hypothesis.
 Feature – A feature is an individual measurable property of the data. A
set of numeric features can be conveniently described by a feature
vector. Feature vectors are fed as input to the model. For example, in
order to predict a fruit, there may be features like color, smell, taste,
etc.
 Target (Label) – A target variable or label is the value to be predicted
by our model. For the fruit example discussed in the feature section,
the label with each set of input would be the name of the fruit like
apple, orange, banana, etc.
 Training – The idea is to give a set of inputs(features) and it’s
expected outputs(labels), so after training, we will have a model
(hypothesis) that will then map new data to one of the categories
trained on.
 Prediction – Once our model is ready, it can be fed a set of inputs to
which it will provide a predicted output(label).

(b) Types of Machine Learning

 Supervised Learning – This involves learning from a training dataset


with labeled data using classification and regression models. This
learning process continues until the required level of performance is
achieved.
 Unsupervised Learning – This involves using unlabelled data and
then finding the underlying structure in the data in order to learn more
and more about the data itself using factor and cluster analysis
models.
 Semi-supervised Learning – This involves using unlabelled data like
Unsupervised Learning with a small amount of labeled data. Using
labeled data vastly increases the learning accuracy and is also more
cost-effective than Supervised Learning.
 Reinforcement Learning – This involves learning optimal actions
through trial and error. So the next action is decided by learning
behaviors that are based on the current state and that will maximize
the reward in the future.

 Classification: Inputs are divided into two or more classes, and the learner must
produce a model that assigns unseen inputs to one or more (multi-label
classification) of these classes. This is typically tackled in a supervised way. Spam
filtering is an example of classification, where the inputs are email (or other)
messages and the classes are “spam” and “not spam”.
 Regression: It is also a supervised learning problem, but the outputs are
continuous rather than discrete. For example, predicting the stock prices using
historical data.

Example

 Clustering: Here, a set of inputs is to be divided into groups. Unlike in


classification, the groups are not known beforehand, making this typically an
unsupervised task.
As you can see in the example below, the given dataset points have been divided
into groups identifiable by the colors red, green and blue.

 Density estimation: The task is to find the distribution of inputs in some space.
 Dimensionality reduction: It simplifies inputs by mapping them into a lower-
dimensional space. Topic modeling is a related problem, where a program is given
a list of human language documents and is tasked to find out which documents
cover similar topics.
On the basis of these machine learning tasks/problems, we have a number of
algorithms which are used to accomplish these tasks. Some commonly used machine
learning algorithms are Linear Regression, Logistic Regression, Decision Tree,
SVM(Support vector machines), Naive Bayes, KNN(K nearest neighbors), K-Means,
Random Forest, etc.

Confusion Matrix

1. What the confusion matrix is and why you need to use it.
2. How to calculate a confusion matrix for a 2-class
classification problem from scratch.
3. How to create a confusion matrix in Python.

Confusion Matrix:
A confusion matrix is a summary of prediction results on a classification
problem.
The number of correct and incorrect predictions are summarized with count
values and broken down by each class. This is the key to the confusion
matrix.

The confusion matrix shows the ways in which your classification model is
confused when it makes predictions.

It gives us insight not only into the errors being made by a classifier but
more importantly the types of errors that are being made.
Here,
• Class 1 : Positive
• Class 2 : Negative
Definition of the Terms:
• Positive (P) : Observation is positive (for example: is an apple).
• Negative (N) : Observation is not positive (for example: is not an apple).
• True Positive (TP) : Observation is positive, and is predicted to be
positive.
• False Negative (FN) : Observation is positive, but is predicted negative.
• True Negative (TN) : Observation is negative, and is predicted to be
negative.
• False Positive (FP) : Observation is negative, but is predicted positive.

Classification Rate/Accuracy:
Classification Rate or Accuracy is given by the relation:

However, there are problems with accuracy. It assumes equal costs for
both kinds of errors. A 99% accuracy can be excellent, good, mediocre,
poor or terrible depending upon the problem.
Recall:
Recall can be defined as the ratio of the total number of correctly classified
positive examples divide to the total number of positive examples. High
Recall indicates the class is correctly recognized (small number of FN).
Recall is given by the relation:

Precision:
To get the value of precision we divide the total number of correctly
classified positive examples by the total number of predicted positive
examples. High Precision indicates an example labeled as positive is
indeed positive (small number of FP).
Precision is given by the relation:

High recall, low precision:This means that most of the positive examples
are correctly recognized (low FN) but there are a lot of false positives.
Low recall, high precision:This shows that we miss a lot of positive
examples (high FN) but those we predict as positive are indeed positive
(low FP)
F-measure:
Since we have two measures (Precision and Recall) it helps to have a
measurement that represents both of them. We calculate an F-measure
which uses Harmonic Mean in place of Arithmetic Mean as it punishes the
extreme values more.
The F-Measure will always be nearer to the smaller value of Precision or
Recall.
Now,
Classification Rate/Accuracy:
Accuracy = (TP + TN) / (TP + TN + FP + FN)= (100+50) /(100+5+10+50)=
0.90

Recall: Recall gives us an idea about when it’s actually yes, how often
does it predict yes.

Recall=TP / (TP + FN)=100/(100+5)=0.95

Precision: Precsion tells us about when it predicts yes, how often is it


correct.

Precision = TP / (TP + FP)=100/ (100+10)=0.91

F-measure:
Fmeasure=(2*Recall*Precision)/(Recall+Presision)=(2*0.95*0.91)/(0.91+0.9
5)=0.92
# Python script for confusion matrix creation.

from sklearn.metrics import confusion_matrix

from sklearn.metrics import accuracy_score

from sklearn.metrics import classification_report

actual = [1, 1, 0, 1, 0, 0, 1, 0, 0, 0]

predicted = [1, 0, 0, 1, 0, 0, 1, 1, 1, 0]

results = confusion_matrix(actual, predicted)

print 'Confusion Matrix :'

print(results)

print 'Accuracy Score :',accuracy_score(actual, predicted)

print 'Report : '

print classification_report(actual, predicted)

You might also like