ML Unit 1

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

Machine Learning

Unit:1
1. Machine Learning (ML)
Introduction
Machine learning is one of the most exciting technologies that one would have ever come across.
As it is evident from the name, it gives the computer that which makes it more similar to humans:
The ability to learn. Machine learning is actively being used today, perhaps in many more places
than one would expect. We probably use a learning algorithm dozens of time without even knowing
it.
Definition: “Machine Learning (ML) is a Field of study that gives computers the capability to
learn without being explicitly programmed”.
• In a very layman manner, Machine Learning(ML) can be explained as automating and
improving the learning process of computers based on their experiences without being actually
programmed i.e. without any human assistance.
• The process starts with feeding good quality data and then training our machines(computers)
by building 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.
Example:
Training of students during exam.
While preparing for the exams students don’t actually cram the subject but try to learn it
with complete understanding. Before the examination, they feed their machine(brain) with a good
amount of high-quality data (questions and answers from different books or teachers notes or
online video lectures). Actually, they are training their brain with input as well as output i.e. what
kind of approach or logic do they have to solve a different kind of questions. Each time they solve
practice test papers and find the performance (accuracy /score) by comparing answers with answer
key given, Gradually, the performance keeps on increasing, gaining more confidence with the
adopted approach.
That’s how actually models are built, train machine with data (both inputs and outputs are
given to model) and when the time comes test on data (with input only) and achieves our model
scores by comparing its answer with the actual output which has not been fed while training.
Researchers are working with assiduous efforts to improve algorithms, techniques so that these
models perform even much better.

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon


2. How Machine Learning is differ from Traditional Programming
 Traditional Programming : We feed in DATA (Input) + PROGRAM (logic), run it on
machine and get output.
 Machine Learning : We feed in DATA(Input) + Output, run it on machine during training
and the machine creates its own program(logic), which can be evaluated while testing.

3. Terminologies used in Machine Learning


 Model
A model is a specific representation learned from data by applying some machine learning
algorithm. A model is also called hypothesis.
 Feature
A feature is an individual measurable property of our 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.
Note: Choosing informative, discriminating and independent features is a crucial step for
effective algorithms. We generally employ a feature extractor to extract the relevant features
from the raw data.
 Target (Label)
A target variable or label is the value to be predicted by our model. For the fruit example
discussed in the features 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.

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon


 Prediction
Once our model is ready, it can be fed a set of inputs to which it will provide a predicted
output(label).
The figure shown below clears the above concepts:

4. What does exactly learning means for a computer?


A computer is said to be learning from Experiences with respect to some class of Tasks, if
its performance in a given Task improves with the Experience.
A computer program is said to learn from experience E with respect to some class of tasks T and
performance measure P, if its performance at tasks in T, as measured by P, improves with
experience E
Example: playing checkers.
E= the experience of playing many games of checkers
T= the task of playing checkers.
P= the probability that the program will win the next game
How things work in reality:-
 Talking about online shopping, there are millions of users with an unlimited range of interests with
respect to brands, colors, price range and many more. While online shopping, buyers tend to search
for a number of products. Now, searching a product frequently will make buyer’s Facebook, web
pages, search engine or that online store start recommending or showing offers on that particular
product. There is no one sitting over there to code such task for each and every user, all this task is
completely automatic. Here, ML plays its role. Researchers, data scientists, machine learners build
models on the machine using good quality and a huge amount of data and now their machine is
automatically performing and even improving with more and more experience and time.

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon


Traditionally, the advertisement was only done using newspapers, magazines and radio but now
technology has made us smart enough to do Targeted advertisement (online ad system) which is a
way more efficient method to target most receptive audience.

 Even in health care also, ML is doing a fabulous job. Researchers and scientists have prepared
models to train machines for detecting cancerjust by looking at slide – cell images. For humans to
perform this task it would have taken a lot of time. But now, no more delay, machines predict the
chances of having or not having cancer with some accuracy and doctors just have to give an
assurance call, that’s it. The answer to – how is this possible is very simple -all that is required, is,
high computation machine, a large amount of good quality image data, ML model with good
algorithms to achieve state-of-the-art results.
Doctors are using ML even to diagnose patients based on different parameters under consideration.
 You all might have use IMDB ratings, Google Photos where it recognizes faces, Google Lens
where the ML image-text recognition model can extract text from the images you feed in, Gmail
which categories E-mail as social, promotion, updates or forum using text classification,which is a
part of ML.

5. Machine Learning – Applications

Applications of Machine Learning include:

 Web Search Engine: One of the reasons why search engines like google, bing etc work so well is
because the system has learnt how to rank pages through a complex learning algorithm.
 Photo tagging Applications: Be it facebook or any other photo tagging application, the ability to tag
friends makes it even more happening. It is all possible because of a face recognition algorithm that
runs behind the application.
 Spam Detector: Our mail agent like Gmail or Hotmail does a lot of hard work for us in classifying
the mails and moving the spam mails to spam folder. This is again achieved by a spam classifier
running in the back end of mail application.
Today, companies are using Machine Learning to improve business decisions,increase productivity,
detect disease, forecast weather, and do many more things. With the exponential growth of
technology, we not only need better tools to understand the data we currently have, but we also
need to prepare ourselves for the data we will have. To achieve this goal we need to build
intelligent machines. We can write a program to do simple things. But for most of times
Hardwiring Intelligence in it is difficult. Best way to do it is to have some way for machines to
learn things themselves. A mechanism for learning – if a machine can learn from input then it

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon


does the hard work for us. This is where Machine Learning comes in action. Some examples of
machine learning are:

6. Data in Machine Learning


DATA : It can be any unprocessed fact, value, text, sound or picture that is not being interpreted
and analyzed. Data is the most important part of all Data Analytics, Machine Learning, Artificial
Intelligence. Without data, we can’t train any model and all modern research and automation will
go vain. Big Enterprises are spending loads of money just to gather as much certain data as
possible.
Example: Why did Facebook acquire WhatsApp by paying a huge price of $19 billion?
The answer is very simple and logical – it is to have access to the users’ information that Facebook
may not have but WhatsApp will have. This information of their users is of paramount importance
to Facebook as it will facilitate the task of improvement in their services.
INFORMATION : Data that has been interpreted and manipulated and has now some meaningful
inference for the users.
KNOWLEDGE : Combination of inferred information, experiences, learning and insights. Results
in awareness or concept building for an individual or organization.

How we split data in Machine Learning?


 Training Data: The part of data we use to train our model. This is the data which your model
actually sees(both input and output) and learn from.
 Validation Data: The part of data which is used to do a frequent evaluation of model, fit on
training dataset along with improving involved hyperparameters (initially set parameters before the
model begins learning). This data plays it’s part when the model is actually training.
 Testing Data: Once our model is completely trained, testing data provides the unbiased evaluation.
When we feed in the inputs of Testing data, our model will predict some values(without seeing
actual output). After prediction, we evaluate our model by comparing it with actual output present
in the testing data. This is how we evaluate and see how much our model has learned from the
experiences feed in as training data, set at the time of training.

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon


Consider an example:
There’s a Shopping Mart Owner who conducted a survey for which he has a long list of questions
and answers that he had asked from the customers, this list of questions and answers is DATA.
Now every time when he want to infer anything and can’t just go through each and every question
of thousands of customers to find something relevant as it would be time-consuming and not
helpful. In order to reduce this overhead and time wastage and to make work easier, data is
manipulated through software, calculations, graphs etc. as per own convenience, this inference
from manipulated data is Information. So, Data is must for Information. Now Knowledge has its
role in differentiating between two individuals having same information. Knowledge is actually not
a technical content but is linked to human thought process.
Properties of Data –
1. Volume : Scale of Data. With growing world population and technology at exposure, huge
data is being generated each and every millisecond.
2. Variety : Different forms of data – healthcare, images, videos, audio clippings.
3. Velocity : Rate of data streaming and generation.
4. Value : Meaningfulness of data in terms of information which researchers can infer from it.
5. Veracity : Certainty and correctness in data we are working on.
Some facts about Data:
 As compared to 2005, 300 times i.e. 40 Zettabytes (1ZB=10^21 bytes) of data will be
generated by 2020.
 By 2011, healthcare sector has a data of 161 Billion Gigabytes
 400 Million tweets are sent by about 200 million active users per day
 Each month, more than 4 Billion hours of video streaming is done by the users.
 30 Billion different types of contents are shared every month by the user.
 It is reported that about 27% of data is inaccurate and so 1 in 3 business idealists or leaders
don’t trust the information on which they are making decisions.

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon


The above-mentioned facts are just a glimpse of the actually existing huge data statistics. When we
talk in terms of real world scenario, the size of data currently present and is getting generated each
and every moment is beyond our mental horizons to imagine.

6. Steps in Machine Learning


Step 1:
Gathering past data in any form suitable for processing.The better the quality of data, the
more suitable it will be for modeling
Step 2:
Data Processing – Sometimes, the data collected is in the raw form and it needs to be pre-
processed.
Example: Some tuples may have missing values for certain attributes, an, in this case, it has to be
filled with suitable values in order to perform machine learning or any form of data mining.
Missing values for numerical attributes such as the price of the house may be replaced with the
mean value of the attribute whereas missing values for categorical attributes may be replaced with
the attribute with the highest mode. This invariably depends on the types of filters we use. If data is
in the form of text or images then converting it to numerical form will be required, be it a list or
array or matrix. Simply, Data is to be made relevant and consistent. It is to be converted into a
format understandable by the machine
Step 3:
Divide the input data into training,cross-validation and test sets. The ratio between the
respective sets must be 6:2:2
Step 4:
Building models with suitable algorithms and techniques on the training set.
Step 5:
Testing our conceptualized model with data which was not fed to the model at the time of
training and evaluating its performance using metrics such as F1 score, precision and recall.

7. Various technique of Machine Learning


Classification of Machine Learning

Machine learning implementations are classified into three major categories, depending on the
nature of the learning “signal” or “response” available to a learning system which are as follows:-

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon


1.Supervised learning :
When an algorithm learns from example data and associated target responses that can
consist of numeric values or string labels, such as classes or tags, in order to later predict the
correct response when posed with new examples comes under the category of Supervised learning.
This approach is indeed similar to human learning under the supervision of a teacher. The teacher
provides good examples for the student to memorize, and the student then derives general rules
from these specific examples.

A machine is said to be learning from past Experiences(data feed in) with respect to some class of
Tasks, if it’s Performance in a given Task improves with the Experience. Supervised learning is
when the model is getting trained on a labelled dataset. Labelled dataset is one which have both
input and output parameters. In this type of learning both training and validation datasets are
labelled as shown in the figures below.

Both the above figures have labelled data set –

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon


 Figure A: It is a dataset of a shopping store which is useful in predicting whether a customer
will purchase a particular product under consideration or not based on his/ her gender, age and
salary.
Input : Gender, Age, Salary
Output : Purchased i.e. 0 or 1 ; 1 means yes the customer will purchase and 0 means that
customer won’t purchase it.
 Figure B: It is a Meteorological dataset which serves the purpose of predicting wind speed
based on different parameters.
Input : Dew Point, Temperature, Pressure, Relative Humidity, Wind Direction
Output : Wind Speed
Training the system: While training the model, data is usually split in the ratio of 80:20 i.e. 80%
as training data and rest as testing data. In training data, we feed input as well as output for 80%
data. The model learns from training data only. We use different machine learning algorithms(which
we will discuss in detail in next articles) to build our model. By learning, it means that the model
will build some logic of its own. Once the model is ready then it is good to be tested. At the time of
testing, input is fed from remaining 20% data which the model has never seen before, the model
will predict some value and we will compare it with actual output and calculate the accuracy.

Types of Supervised Learning:


1. Classification : It is a Supervised Learning task where output is having defined labels(discrete
value). For example in above Figure A, Output – Purchased has defined labels i.e. 0 or 1 ; 1
means the customer will purchase and 0 means that customer won’t purchase. The goal here is
to predict discrete values belonging to a particular class and evaluate on the basis of accuracy.
It can be either binary or multi class classification. In binary classification, model predicts
either 0 or 1 ; yes or no but in case of multi classclassification, model predicts more than one

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon


class.
Example: Gmail classifies mails in more than one classes like social, promotions, updates,
forum.
2. Regression : It is a Supervised Learning task where output is having continuous value.
Example in above Figure B, Output – Wind Speed is not having any discrete value but is
continuous in the particular range. The goal here is to predict a value as much closer to actual
output value as our model can and then evaluation is done by calculating error value. The
smaller the error the greater the accuracy of our regression model.
Example of Supervised Learning Algorithms:

 Linear Regression

 Nearest Neighbor

 Guassian Naive Bayes

 Decision Trees

 Support Vector Machine (SVM)

 Random Forest

2.Unsupervised learning
Whereas when an algorithm learns from plain examples without any associated response, leaving
to the algorithm to determine the data patterns on its own. This type of algorithm tends to
restructure the data into something else, such as new features that may represent a class or a new
series of un-correlated values. They are quite useful in providing humans with insights into the
meaning of data and new useful inputs to supervised machine learning algorithms.
As a kind of learning, it resembles the methods humans use to figure out that certain objects or
events are from the same class, such as by observing the degree of similarity between objects.
Some recommendation systems that you find on the web in the form of marketing automation are
based on this type of learning.

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon


It’s a type of learning where we don’t give target to our model while training i.e. training model has
only input parameter values. The model by itself has to find which way it can learn. Data-set in
Figure A is mall data that contains information of its clients that subscribe to them. Once subscribed
they are provided a membership card and so the mall has complete information about customer and
his/her every purchase. Now using this data and unsupervised learning techniques, mall can easily
group clients based on the parameters we are feeding in.

Training data we are feeding is –

 Unstructured data: May contain noisy(meaningless) data, missing values or unknown data

 Unlabeled data : Data only contains value for input parameters, there is no targeted
value(output). It is easy to collect as compared to labelled one in Supervised approach.

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon


Types of Unsupervised Learning :-

 Clustering: Broadly this technique is applied to group data based on different patterns, our
machine model finds. For example in above figure we are not given output parameter value,
so this technique will be used to group clients based on the input parameters provided by our
data.
 Association: This technique is a rule based ML technique which finds out some very useful
relations between parameters of a large data set. For e.g. shopping stores use algorithms based
on this technique to find out relationship between sale of one product w.r.t to others sale based
on customer behavior. Once trained well, such models can be used to increase their sales by
planning different offers.
Some algorithms:

 K-Means Clustering

 DBSCAN – Density-Based Spatial Clustering of Applications with Noise

 BIRCH – Balanced Iterative Reducing and Clustering using Hierarchies

 Hierarchical Clustering

3.Reinforcement learning
As the name suggests, its working lies between Supervised and Unsupervised techniques. We use
these techniques when we are dealing with a data which is a little bit labelled and rest large portion
of it is unlabeled. We can use unsupervised technique to predict labels and then feed these labels to
supervised techniques. This technique is mostly applicable in case of image data-sets where usually
all images are not labelled.
When you present the algorithm with examples that lack labels, as in unsupervised learning.
However, you can accompany an example with positive or negative feedback according to the
solution the algorithm proposes comes under the category of Reinforcement learning, which is
connected to applications for which the algorithm must make decisions (so the product is

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon


prescriptive, not just descriptive, as in unsupervised learning), and the decisions bear consequences.
In the human world, it is just like learning by trial and error.
Errors help you learn because they have a penalty added (cost, loss of time, regret, pain, and so on),
teaching you that a certain course of action is less likely to succeed than others. An interesting
example of reinforcement learning occurs when computers learn to play video games by
themselves.
In this case, an application presents the algorithm with examples of specific situations, such as
having the gamer stuck in a maze while avoiding an enemy. The application lets the algorithm know
the outcome of actions it takes, and learning occurs while trying to avoid what it discovers to be
dan-gerous and to pursue survival. You can have a look at how the company Google DeepMind has
created a reinforcement learning program that plays old Atari’s videogames. When watching the
video, notice how the program is initially clumsy and unskilled but steadily improves with training
until it becomes a champion.

In this technique, model keeps on increasing its performance using a Reward Feedback to learn the
behavior or pattern. These algorithms are specific to a particular problem e.g. Google Self Driving
car, AlphaGo where a bot competes with human and even itself to getting better and better
performer of Go Game. Each time we feed in data, they learn and add the data to its knowledge that
is training data. So, more it learns the better it get trained and hence experienced.

 Agents observe input.

 Agent performs an action by making some decisions.

 After its performance, agent receives reward and accordingly reinforce and the model stores in
state-action pair of information.
Some algorithms:

 Temporal Difference (TD)

 Q-Learning

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon


 Deep Adversarial Networks
Reinforcement learning is an area of Machine Learning. Reinforcement. It is about taking suitable
action to maximize reward in a particular situation. It is employed by various software and
machines to find the best possible behavior or path it should take in a specific situation.
Reinforcement learning differs from the supervised learning in a way that in supervised learning the
training data has the answer key with it so the model is trained with the correct answer itself
whereas in reinforcement learning, there is no answer but the reinforcement agent decides what to
do to perform the given task. In the absence of training dataset, it is bound to learn from its
experience.

 Example : The problem is as follows: We have an agent and a reward, with many hurdles in

between. The agent is supposed to find the best possible path to reach the reward. The following
problem explains the problem more easily.

 The above image shows robot, diamond and fire. The goal of the robot is to get the reward that is

the diamond and avoid the hurdles that is fire. The robot learns by trying all the possible paths and
then choosing the path which gives him the reward with the least hurdles. Each right step will give
the robot a reward and each wrong step will subtract the reward of the robot. The total reward will
be calculated when it reaches the final reward that is the diamond.

 Main points in Reinforcement learning –

 Input: The input should be an initial state from which the model will start

 Output: There are many possible output as there are variety of solution to a particular problem

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon


 Training: The training is based upon the input, The model will return a state and the user will decide
to reward or punish the model based on its output.
 The model keeps continues to learn.

 The best solution is decided based on the maximum reward.


Types of Reinforcement: There are two types of Reinforcement:
Positive –
Positive Reinforcement is defined as when an event, occurs due to a particular
behavior, increases the strength and the frequency of the behavior. In other
words it has a positive effect on the behavior.
 Advantages of reinforcement learning are:

 Maximizes Performance

 Sustain Change for a long period of time

 Disadvantages of reinforcement learning:

 Too much Reinforcement can lead to overload of states which


can diminish the results
Negative –
Negative Reinforcement is defined as strengthening of a behavior because a
negative condition is stopped or avoided.
 Advantages of reinforcement learning:

 Increases Behavior

 Provide defiance to minimum standard of performance

 Disadvantages of reinforcement learning:

 It Only provides enough to meet up the minimum behavior


Various Practical applications of Reinforcement Learning –

 RL can be used in robotics for industrial automation.

 RL can be used in machine learning and data processing

 RL can be used to create training systems that provide custom instruction


and materials according to the requirement of students.
 RL can be used in large environments in the following situations:

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon


 A model of the environment is known, but an analytic solution is not
available;
 Only a simulation model of the environment is given (the subject of
simulation-based optimization);[6]
The only way to collect information about the environment is to interact
with it.
 Difference between Reinforcement learning and Supervised learning:

 REINFORCEMENT LEARNING  SUPERVISED LEARNING


Reinforcement learning is all about making
decisions sequentially. In simple words we can In Supervised learning the decision is made on the
say that the out depends on the state of the
initial input or the input given at the start
current input and the next input depends on the
output of the previous input

In Reinforcement learning decision is


Supervised learning the decisions are independent
dependent, So we give labels to sequences of
of each other so labels are given to each decision.
dependent decisions

Example: Chess game Example: Object recognition

Mrs. Pradnya A. Vikhar, KCES's COEIT, Jalgaon

You might also like