Module 3 21cs752
Module 3 21cs752
Module 3
INTRODUCTION TO MACHINE L E A R N I N G
1.1 NEED FOR MACHINE LEARNING
Businessorganizations usehugeamount of data for their dailyactivities. They have now
started to use the latest technology, machinelearning, to manage the data.
Machine learning has become so popular because of three reasons:
AIT, TUMKUR
1
.
lOMoARcPSD|39472316
AIT, TUMKUR
2
.
lOMoARcPSD|39472316
AIT, TUMKUR
3
.
lOMoARcPSD|39472316
Figure 1.2: (a) A Learning System for Humans (b) A Learning Systemfor
Machine Learning
Often, the quality of data determines the quality of experience and, therefore, the quality ofthe
learning system. In statistical learning, the relationship between the input x and output y is
modeled as a function in the form y = f(x). Here, f is the learning function that maps the input xto
output y. Learning of function f is the crucial aspect of forming a model in statistical learning.In
machine learning, this is simply called mapping of input to output.
The learning program summarizes the raw data in a model. Formally stated, a model is anexplicit
description of patterns within the data in the form of:
1. Mathematical equation
2. Relational diagrams like trees/graphs
3. Logical if/else rules, or
4. Groupings called clusters
In summary, a model can be a formula, procedure or representation that can generate data
decisions. The difference between pattern and model is that the former is local and applicable onlyto
certain attributes but the latter is global and fits the entire dataset. For example, a model can behelpful
to examine whether a given email is spam or not. The point is that the model is generated automatically
from the given data.
Another pioneer of AI, Tom Mitchell’s definition of machine learning states that, “A computer
program is said to learn from experience E, with respect to task T and some performance measure
P,if its performance on T measured by P improves with experience E.” The important components of this
definition are experience E, task T, and performance measure P.
For example, the task T could be detecting an object in an image. The machine can gain the
knowledge of object using training dataset of thousands of images. This is called experience E.So,
the focus is to use this experience E for this task of object detection T. The ability of the systemto detect
the object is measured by performance measures like precision and recall. Based on the performance
measures, course correction can be done to improve the performance of the system.
Models of computer systems are equivalent to human experience. Experience is based on data.
Humans gain experience by various means. They gain knowledge by rote learning. They observe others
andimitateit. Humansgainalot of knowledgefrom teachersandbooks. Welearnmany things by trial and
error. Once the knowledge is gained, when a new problem is encountered, humans search for similar
past situations and then formulate the heuristics and use that for prediction. But, in systems,
experience is gathered by these steps:
1. Collection of data
AIT, TUMKUR
. 4
lOMoARcPSD|39472316
2. Once data is gathered, abstract concepts are formed out of that data. Abstraction is used to
generate concepts. This is equivalent to humans’ idea of objects, for example, we have some
idea about how an elephant looks like.
3. Generalization converts the abstraction into an actionable form of intelligence. It can
be viewed as ordering of all possible concepts. So, generalization involves ranking of concepts,
inferencing from them and formation of heuristics, an actionable aspect of intelligence.
Heuristics are educated guesses for all tasks. For example, if one runs or encounters a danger,
it is the resultant of human experience or his heuristics formation.In machines, it happens
the same way.
4. Heuristics normally works! But, occasionally, it may fail too. It is not the faultof
heuristics as it is just a ‘rule of thumb′. The course correction is done by taking
evaluation measures. Evaluation checks the thoroughness of the models and to-do course
correction, if necessary, to generate better formulations.
intelligence
AIT, TUMKUR
. 5
lOMoARcPSD|39472316
1.3.2 Machine Learning, Data Science, Data Mining, and Data Analytics
Data science is an ‘Umbrella’ term that encompasses many fields. Machine learning starts with data.
Therefore, data science and machine learning are interlinked. Machine learning is a branch of data
science. Data science deals with gathering of data for analysis. It is a broad field that includes:
Big Data Data science concerns about collection of data. Big data is a field of data science that deals
with data’s following characteristics:
1. Volume: Huge amount of data is generated by big companies like Facebook, Twitter,
YouTube.
2. Variety: Data is available in variety of forms like images, videos, and in different formats.
3. Velocity: It refers to the speed at which the data is generated and processed.
Big data is used by many machine learning algorithms for applications such as languagetrans-lation
and image recognition. Big data influences the growth of subjects like Deep learning. Deep learning is
a branch of machine learning that deals with constructing models using neural networks.
Data Mining Data mining’s original genesis is in the business. Like while mining the earth one gets
into precious resources, it is often believed that unearthing of the data produces hidden infor- mation
that otherwise would have eluded the attention of the management. Nowadays, many consider that
data mining and machine learning are same. There is no difference between these fields except that
data mining aims to extract the hidden patterns that are present in the data, whereas, machine learning
aims to use it for prediction.
Data Analytics Another branch of data science is data analytics. It aims to extract useful knowledge
from crude data. There are different types of analytics. Predictive data analytics is usedfor making
predictions. Machine learning is closely related to this branch of analytics and shares almost all
algorithms.
Pattern Recognition It is an engineering field. It uses machine learning algorithms to extract the
features for pattern analysis and pattern classification. One can view pattern recognition as a specific
application of machine learning.
These relations are summarized in Figure 1.4.
Data science
analytics
AIT, TUMKUR
. 6
lOMoARcPSD|39472316
methods look for regularity in data called patterns. Initially, statistics sets a hypothesis andperforms
experiments to verify and validate the hypothesis in order to find relationships among data.
Statistics requires knowledge of the statistical procedures and the guidance of a good statistician.
It is mathematics intensive and models are often complicated equations and involve many
assumptions. Statistical methods are developed in relation to the data being analyzed. In addition,
statistical methods are coherent and rigorous. It has strong theoretical foundations and interpretations
that require a strong statistical knowledge.
Machine learning, comparatively, has less assumptions and requires less statistical knowledge.
But, it often requires interaction with various tools to automate the process of learning.
Nevertheless, there is a school of thought that machine learning is just the latest version of ‘old
Statistics’ and hence this relationship should be recognized.
Cluster
analysis
Labelled and Unlabeled Data Data is a raw fact. Normally, data is represented in the formof a
table. Data also can be referred to as a data point, sample, or an example. Each row of the table
represents a data point. Features are attributes or characteristics of an object. Normally, the columns
of the table are attributes. Out of all attributes, one attribute is important and is called a label. Label is
the feature that we aim to predict. Thus, there are two types of data – labelled and unlabeled.
Labelled Data To illustrate labelled data, let us take one example dataset called Iris flower datasetor
Fisher’s Iris dataset. The dataset has 50 samples of Iris – with four attributes, length and width of sepals
and petals. The target variable is called class. There are three classes – Iris setosa, Iris virginica, and
Iris versicolor.
AIT, TUMKUR
. 7
lOMoARcPSD|39472316
Cat
(b)
AIT, TUMKUR
. 8
lOMoARcPSD|39472316
Classi𝑓ication
Classification is a supervised learning method. The input attributes of the classification algorithmsare
called independent variables. The target attribute is called label or dependent variable. The
relationship between the input and target variable is represented in the form of a structure which is
called a classification model. So, the focus of classification is to predict the ‘label’ that is in a discrete
form (a value from the set of finite values). An example is shown in Figure 1.7 where a classification
algorithm takes a set of labelled data images such as dogs and cats to construct a model that can later
be used to classify an unknown test image data.
AIT, TUMKUR
. 9
lOMoARcPSD|39472316
In classification, learning takes place in two stages. During the first stage, called training stage,the learning
algorithm takes a labelled dataset and starts learning. After the training set, samples are processed and
the model is generated. In the second stage, the constructed model is tested withtest or unknown sample
and assigned a label. This is the classification process.
This is illustrated in the above Figure 1.7. Initially, the classification learning algorithm learnswith
the collection of labelled data and constructs the model. Then, a test case is selected, and the model
assigns a label.
Similarly, in the case of Iris dataset, if the test is given as (6.3, 2.9, 5.6, 1.8, ?), the classification will
generate the label for this. This is called classification. One of the examples of classification is –Image
recognition, which includes classification of diseases like cancer, classification of plants, etc.
The classification models can be categorized based on the implementation technology like decision
trees, probabilistic methods, distance measures, and soft computing methods. Classificationmodels can
also be classified as generative models and discriminative models. Generative modelsdeal with the
process of data generation and its distribution. Probabilistic models are examples of
generative models. Discriminative models do not care about the generation of data. Instead, they
simply concentrate on classifying the given data.
Some of the key algorithms of classification are:
• Decision Tree
• Random Forest
• Support Vector Machines
• Naı¨ve Bayes
• Artificial Neural Network and Deep Learning networks like CNN
Regression Models
Regression models, unlike classification algorithms, predict continuous variables like price. In
other words, it is a number. A fitted regression model is shown in Figure 1.8 for a dataset that represent
weeks input x and product sales y.
4
3.5
y-axis - Product sales data (y)
2.5
1.5
1
1 2 3 4 5
x-axis - Week data (x)
Regression line (y = 0.66X + 0.54)
AIT, TUMKUR
. 10
lOMoARcPSD|39472316
data (x). For example, the prediction for unknown eighth week can be made bysubstituting x as 8 in that
regression formula to get y.
One of the most important regression algorithms is linear regression that is explained in the next
section.
Both regression and classification models are supervised algorithms. Both have a supervisor andthe
concepts of training and testing are applicable to both. What is the difference between classificationand
regression models? The main difference is that regression models predict continuous variablessuch as
product price, while classification concentrates on assigning labels such as class.
1.4.2 Unsupervised Learning
The second kind of learning is by self-instruction. As the name suggests, there are no supervisor or
teacher components. In the absence of a supervisor or teacher, self-instruction is the most commonkind
of learning process. This process of self-instruction is based on the concept of trial and error.
Here, the program is supplied with objects, but no labels are defined. The algorithm itself observes
the examples and recognizes patterns based on the principles of grouping. Grouping is done in ways
that similar objects form the same group.
Cluster analysis and Dimensional reduction algorithms are examples of unsupervised algorithms.
Cluster Analysis
Cluster analysis is an example of unsupervised learning. It aims to group objects into disjoint clusters
or groups. Cluster analysis clusters objects based on its attributes. All the data objectsof the
partitions are similar in some aspect and vary from the data objects in the other partitions significantly.
Some of the examples of clustering processes are — segmentation of a region of interest in an
image, detection of abnormal growth in a medical image, and determining clusters of signatures in a
gene database.
An example of clustering scheme is shown in Figure 1.9 where the clustering algorithm takes a set
of dogs and cats images and groups it as two clusters-dogs and cats. It can be observed that the samples
belonging to a cluster are similar and samples are different radically across clusters.
AIT, TUMKUR
. 11
lOMoARcPSD|39472316
The differences between supervised and unsupervised learning are listed in the following
Table 1.2.
Table 1.2: Differences between Supervised and Unsupervised Learning
Goal
Danger
AIT, TUMKUR
. 12
lOMoARcPSD|39472316
In this grid game, the gray tile indicates the danger, black is a block, and the tile with diagonallines
is the goal. The aim is to start, say from bottom-left grid, using the actions left, right, top andbottom to
reach the goal state.
To solve this sort of problem, there is no data. The agent interacts with the environment toget
experience. In the above case, the agent tries to create a model by simulating many paths and finding
rewarding paths. This experience helps in constructing a model.
It can be said in summary, compared to supervised learning, there is no supervisor orlabelled
dataset. Many sequential decisions need to be taken to reach the final decision. Therefore,
reinforcement algorithms are reward-based, goal-oriented algorithms.
1, 1 1
2, 1 2
3, 1 3
4, 1 4
5, 1 5
Can a model for this test data be multiplication? That is, y x x . Well! It is true! But, this is
1 2
equally true that y may be y x x , or y x x2. So, there are three functions that fit the data.
1 2 1
This means that the problem is ill-posed. To solve this problem, one needs more example to
check the model. Puzzles and games that do not have sufficient specification may become anill-
posed problem and scientific computation has many ill-posed problems.
AIT, TUMKUR
. 13
lOMoARcPSD|39472316
2. Huge data – This is a primary requirement of machine learning. Availability of a quality data is
a challenge. A quality data means it should be large and should not have data problems such
as missing data or incorrect data.
3. High computation power – With the availability of Big Data, the computational resource
requirement has also increased. Systems with Graphics Processing Unit (GPU) or even Tensor
Processing Unit (TPU) are required to execute machine learning algorithms. Also, machine
learning tasks have become complex and hence time complexity has increased, and that can
be solved only with high computing power.
4. Complexity of the algorithms – The selection of algorithms, describing the algorithms,
application of algorithms to solve machine learning task, and comparison of algorithms have
become necessary for machine learning or data scientists now. Algorithms have become a big
topic of discussion and it is a challenge for machine learning professionals todesign, select, and
evaluate optimal algorithms.
5. Bias/Variance – Variance is the error of the model. This leads to a problem called bias/
variance tradeoff. A model that fits the training data correctly but fails for test data, in general
lacks generalization, is called overfitting. The reverse problem is called underfitting where the
model fails for training data but has good generalization. Overfitting and underfitting are great
challenges for machine learning algorithms.
Understand the
business
preprocessing
Model evaluation
Model deployment
14
.
lOMoARcPSD|39472316
1. Understanding the business – This step involves understanding the objectives and
requirements of the business organization. Generally, a single data mining algorithm is enough
for giving the solution. This step also involves the formulation of the problem statement for
the data mining process.
2. Understanding the data – It involves the steps like data collection, study of the charac teristics
of the data, formulation of hypothesis, and matching of patterns to the selected hypothesis.
3. Preparation of data – This step involves producing the final dataset by cleaning the raw data
and preparation of data for the data mining process. The missing values may cause problems
during both training and testing phases. Missing data forces classifiers to produceinaccurate
results. This is a perennial problem for the classification models. Hence, suitablestrategies
should be adopted to handle the missing data.
4. Modelling – This step plays a role in the application of data mining algorithm for the datato
obtain a model or pattern.
5. Evaluate – This step involves the evaluation of the data mining results using statistical analysis
and visualization methods. The performance of the classifier is determined by evaluating the
accuracy of the classifier. The process of classification is a fuzzy issue.For example,
classification of emails requires extensive domain knowledge and requires domain experts.
Hence, performance of the classifier is very crucial.
6. Deployment – This step involves the deployment of results of the data mining algorithm to
improve the existing process or for a new situation.
15
.
lOMoARcPSD|39472316
7. Games Game programs for Chess, GO, and Atari video games
8. Natural Language Google Translate, Text summarization, and sentiment analysis
Translation
9. Web Analysis and Identification of access patterns, detection of e-mail spams, viruses,
Services personalized web services, search engines like Google, detection of
promotion of user websites, and finding loyalty of users after web page
layout modification
12. Scientific Domain Discovery of new galaxies, identification of groups of houses basedon
house type/geographical location, identification of earthquake
epicenters, and identification of similar land use
Key Terms:
• Machine Learning – A branch of AI that concerns about machines to learn automatically withoutbeing
explicitly programmed.
• Data – A raw fact.
• Model – An explicit description of patterns in a data.
• Experience – A collection of knowledge and heuristics in humans and historical training data in case of
machines.
• Predictive Modelling – A technique of developing models and making a prediction of unseen data.
• Deep Learning – A branch of machine learning that deals with constructing models using neural
networks.
• Data Science – A field of study that encompasses capturing of data to its analysis covering all stagesof
data management.
• Data Analytics – A field of study that deals with analysis of data.
16
.
lOMoARcPSD|39472316
• Big Data – A study of data that has characteristics of volume, variety, and velocity.
• Statistics – A branch of mathematics that deals with learning from data using statistical methods.
• Hypothesis – An initial assumption of an experiment.
• Learning – Adapting to the environment that happens because of interaction of an agent with the
environment.
• Label – A target attribute.
• Labelled Data – A data that is associated with a label.
• Unlabelled Data – A data without labels.
• Supervised Learning – A type of machine learning that uses labelled data and learns with the help of a
supervisor or teacher component.
• Classification Program – A supervisory learning method that takes an unknown input and assigns a
label for it. In simple words, finds the category of class of the input attributes.
• Regression Analysis – A supervisory method that predicts the continuous variables based on the input
variables.
• Unsupervised Learning – A type of machine leaning that uses unlabelled data and groups the attributes
to clusters using a trial and error approach.
• Cluster Analysis – A type of unsupervised approach that groups the objects based on attributesso
that similar objects or data points form a cluster.
• Semi-supervised Learning – A type of machine learning that uses limited labelled and largeunlabelled
data. It first labels unlabelled data using labelled data and combines it for learning purposes.
• Reinforcement Learning – A type of machine learning that uses agents and environment interactionfor
creating labelled data for learning.
• Well-posed Problem – A problem that has well-defined specifications. Otherwise, the problem is called
ill-posed.
• Bias/Variance – The inability of the machine learning algorithm to predict correctly due to lackof
generalization is called bias. Variance is the error of the model for training data. This leads to problems
called overfitting and underfitting.
• Model Deployment – A method of deploying machine learning algorithms to improve the existing
business processes for a new situation.
17
.
lOMoARcPSD|39472316
Some of the other forms of Vs that are often quoted in the literature as characteristics of
Big data are:
4. Veracity of data – Veracity of data deals with aspects like conformity to the facts, truthfulness,
believablity, and confidence in data. There may be many sources of error such as technical
errors, typographical errors, and human errors. So, veracity is one of the most important
aspects of data.
5. Validity – Validity is the accuracy of the data for taking decisions or for any other goals that
are needed by the given problem.
6. Value – Value is the characteristic of big data that indicates the value of the information that
is extracted from the data and its influence on the decisions that are taken based on it.
Thus, these 6 Vs are helpful to characterize the big data. The data quality of the numeric
attributes is determined by factors like precision, bias, and accuracy.
18
.
lOMoARcPSD|39472316
Structured Data
In structured data, data is stored in an organized manner such as a database where it is available in
the form of a table. The data can also be retrieved in an organized manner using tools like SQL. The
structured data frequently encountered in machine learning are listed below:
Record Data A dataset is a collection of measurements taken from a process. We have a collection
of objects in a dataset and each object has a set of measurements. The measurements can be
arranged in the form of a matrix. Rows in the matrix represent an object and can be called as entities,
cases, or records. The columns of the dataset are called attributes, features, or fields. The table is
filled with observed data. Also, it is better to note the general jargons that are associated with the
dataset. Label is the term that is used to describe the individual observations.
Data Matrix It is a variation of the record type because it consists of numeric attributes. The
standard matrix operations can be applied on these data. The data is thought of as points or vectors
in the multidimensional space where every attribute is a dimension describing the object.
Graph Data It involves the relationships among objects. For example, a web page can refer to
another web page. This can be modeled as a graph. The modes are web pages and the hyperlink is
an edge that connects the nodes.
Ordered Data Ordered data objects involve attributes that have an implicit order among them.
The examples of ordered data are:
Temporal data – It is the data whose attributes are associated with time. For example, the
customer purchasing patterns during festival time is sequential data. Time series data is a
special type of sequence data where the data is a series of measurements over time.
Sequence data – It is like sequential data but does not have time stamps. This data involves the
sequence of words or letters. For example, DNA data is a sequence of four characters – A T G C.
Spatial data – It has attributes such as positions or areas. For example, maps are spatial data
where the points are related by location.
Unstructured Data
Unstructured data includes video, image, and audio. It also includes textual documents, programs,
and blog data. It is estimated that 80% of the data are unstructured data.
Semi-Structured Data
Semi-structured data are partially structured and partially unstructured. These include data like
XML/JSON data, RSS feeds, and hierarchical data.
19
.
lOMoARcPSD|39472316
Once the dataset is assembled, it must be stored in a structure that is suitable for data analysis. The
goal of data storage management is to make data available for analysis. There are different
approaches to organize and manage data in storage files and systems from flat file to data
warehouses. Some of them are listed below:
Flat Files These are the simplest and most commonly available data source. It is also the cheapest
way of organizing the data. These flat files are the files where data is stored in plain ASCII or EBCDIC
format. Minor changes of data in flat files affect the results of the data mining algorithms.
Hence, flat file is suitable only for storing small dataset and not desirable if the dataset becomes
larger.
Some of the popular spreadsheet formats are listed below:
• CSV files – CSV stands for comma-separated value files where the values are separated by
commas. These are used by spreadsheet and database applications. The first row may have
attributes and the rest of the rows represent the data.
• TSV files – TSV stands for Tab separated values files where values are separated by Tab. Both
CSV and TSV files are generic in nature and can be shared. There are many tools like Google Sheets
and Microsoft Excel to process these files.
Database System It normally consists of database files and a database management system
(DBMS). Database files contain original data and metadata. DBMS aims to manage data and improve
operator performance by including various tools like database administrator, query processing, and
transaction manager. A relational database consists of sets of tables. The tables have rows and
columns. The columns represent the attributes and rows represent tuples. A tuple corresponds to
either an object or a relationship between objects. A user can access and manipulate the data in the
database using SQL.
20
.
lOMoARcPSD|39472316
market activities. Data analysis is an activity that takes the data and generates useful information
and insights for assisting the organizations.
Data analysis and data analytics are terms that are used interchangeably to refer to the same
concept. However, there is a subtle difference. Data analytics is a general term and data analysis is a
part of it. Data analytics refers to the process of data collection, preprocessing and analysis. It deals
with the complete cycle of data management. Data analysis is just analysis and is a part of data
analytics. It takes historical data and does the analysis.
Data analytics, instead, concentrates more on future and helps in prediction.
There are four types of data analytics:
1. Descriptive analytics
2. Diagnostic analytics
3. Predictive analytics
4. Prescriptive analytics
Descriptive Analytics It is about describing the main features of the data. After data collection is
done, descriptive analytics deals with the collected data and quantifies it. It is often stated that
analytics is essentially statistics. There are two aspects of statistics – Descriptive and Inference.
Descriptive analytics only focuses on the description part of the data and not the inference part.
Diagnostic Analytics It deals with the question – ‘Why?’. This is also known as causal analysis, as
it aims to find out the cause and effect of the events. For example, if a product is not selling,
diagnostic analytics aims to find out the reason. There may be multiple reasons and associated
effects are analyzed as part of it.
Predictive Analytics It deals with the future. It deals with the question – ‘What will happen in
future given this data?’. This involves the application of algorithms to identify the patterns to predict
the future. The entire course of machine learning is mostly about predictive analytics and forms the
core of this book.
Prescriptive Analytics It is about the finding the best course of action for the business
organizations. Prescriptive analytics goes beyond prediction and helps in decision making by giving
a set of actions. It helps the organizations to plan better for the future and to mitigate the risks that
are involved.
Data Management Layer It performs preprocessing of data. The purpose of this layer is to
allow parallel execution of queries, and read, write and data management tasks. There may be
many schemes that can be implemented by this layer such as data-in-place, where the data is
not moved at all, or constructing data repositories such as data warehouses and pull data
on-demand mechanisms.
Data Analytic Layer It has many functionalities such as statistical tests, machine learning
algorithms to understand, and construction of machine learning models. This layer implements
many model validation mechanisms too. The processing is done as shown in Box 2.1.
Presentation Layer It has mechanisms such as dashboards, and applications that display the
21
.
lOMoARcPSD|39472316
Broadly, the data source can be classified as open/public data, social media data and multimodal
data.
1. Open or public data source – It is a data source that does not have any stringent copyright
rules or restrictions. Its data can be primarily used for many purposes. Government census
data are good examples of open data:
• Digital libraries that have huge amount of text data as well as document images
• Scientific domains with a huge collection of experimental data like genomic data
and biological data
• Healthcare systems that use extensive databases like patient databases, health insurance
data, doctors’ information, and bioinformatics information
2. Social media – It is the data that is generated by various social media platforms like
Twitter,
Facebook, YouTube, and Instagram. An enormous amount of data is generated by these
platforms.
3. Multimodal data – It includes data that involves many modes such as text, video, audio
and mixed types. Some of them are listed below:
• Image archives contain larger image databases along with numeric and text data
• The World Wide Web (WWW) has huge amount of data that is distributed on the Internet.
These data are heterogeneous in nature.
22
.
lOMoARcPSD|39472316
measurement and structural errors like improper data formats. Data errors can also arise from
omission and duplication of attributes. Noise is a random component and involves distortion of
a value or introduction of spurious objects. Often, the noise is used if the data is a spatial or
temporal component. Certain deterministic distortions in the form of a streak are known as
artifacts.
Consider, for example, the following patient Table 2.1. The ‘bad’ or ‘dirty’ data can be observed
in this table.
23
.
lOMoARcPSD|39472316
It can be observed that data like Salary = ’ ’ is incomplete data. The DoB of patients, John, Andre, and
Raju, is the missing data. The age of David is recorded as ‘5’ but his DoB indicates it is 10/10/1980.
This is called inconsistent data.
Inconsistent data occurs due to problems in conversions, inconsistent formats, and difference in
units. Salary for John is -1500. It cannot be less than ‘0’. It is an instance of noisy data. Outliers are
data that exhibit the characteristics that are different from other data and have very unusual values.
The age of Raju cannot be 136. It might be a typographical error. It is often required to distinguish
between noise and outlier data.
Outliers may be legitimate data and sometimes are of interest to the data mining algorithms. These
errors often come during data collection stage. These must be removed so that machine learning
algorithms yield better results as the quality of results is determined by the quality of input data.
This removal process is called data cleaning.
24
.
lOMoARcPSD|39472316
Example 2.1: Consider the following set: S = {12, 14, 19, 22, 24, 26, 28, 31, 34}. Apply various
binning techniques and show the result.
Solution: By equal-frequency bin method, the data should be distributed across bins. Let us
assume the bins of size 3, then the above data is distributed across the bins as shown below:
Bin 1 : 12 , 14, 19
Bin 2 : 22, 24, 26
Bin 3 : 28, 31, 32
By smoothing bins method, the bins are replaced by the bin means. This method results in:
Bin 1 : 15, 15, 15
Bin 2 : 24, 24, 24
Bin 3 : 30.3, 30.3, 30.3
Using smoothing by bin boundaries method, the bins' values would be like:
Bin 1 : 12, 12, 19
Bin 2 : 22, 22, 26
Bin 3 : 28, 32, 32
As per the method, the minimum and maximum values of the bin are determined, and it serves
as bin boundary and does not change. Rest of the values are transformed to the nearest value. It
can be observed in Bin 1, the middle value 14 is compared with the boundary values 12 and 19
and changed to the closest value, that is 12. This process is repeated for all bins.
Here max-min is the range. Min and max are the minimum and maximum of the given data,
new max and new min are the minimum and maximum of the target range, say 0 and 1.
Example 2.2: Consider the set: V = {88, 90, 92, 94}. Apply Min-Max procedure and map the marks
25
.
lOMoARcPSD|39472316
So, it can be observed that the marks {88, 90, 92, 94} are mapped to the new range {0, 0.33, 0.66,
1}. Thus, the Min-Max normalization range is between 0 and 1.
z-Score Normalization This procedure works by taking the difference between the field value
and mean value, and by scaling this difference by standard deviation of the attribute.
Here, s is the standard deviation of the list V and m is the mean of the list V.
Example 2.3: Consider the mark list V = {10, 20, 30}, convert the marks to z-score.
Solution: The mean and Sample Standard deviation (s) values of the list V are 20 and 10, respec-
tively. So the z-scores of these marks are calculated using Eq. (2.2) as:
Hence, the z-score of the marks 10, 20, 30 are -1, 0 and 1, respectively.
Data Reduction
Data reduction reduces data size but produces the same results. There are different ways in which
data reduction can be carried out such as data aggregation, feature selection, and dimensionality
reduction.
26
.
lOMoARcPSD|39472316
For example, consider the following database shown in sample Table 2.2.
Every attribute should be associated with a value. This process is called measurement.
The type of attribute determines the data types, often referred to as measurement scale types.
The data types are shown in Figure 2.1.
27
.
lOMoARcPSD|39472316
Categorical or Qualitative Data The categorical data can be divided into two types. They are
nominal type and ordinal type.
• Nominal Data – In Table 2.2, patient ID is nominal data. Nominal data are symbols and
cannot be processed like a number. For example, the average of a patient ID does not make
any statistical sense. Nominal data type provides only information but has no ordering
among data. Only operations like (=, ≠) are meaningful for these data. For example, the
patient ID can be checked for equality and nothing else.
• Ordinal Data – It provides enough information and has natural order. For example, Fever
= {Low, Medium, High} is an ordinal data. Certainly, low is less than medium and medium
is less than high, irrespective of the value. Any transformation can be applied to these data
to get a new value.
Numeric or Qualitative Data It can be divided into two categories. They are interval type and
ratio type.
• Interval Data – Interval data is a numeric data for which the differences between values
are meaningful. For example, there is a difference between 30 degree and 40 degree. Only
the permissible operations are + and -.
• Ratio Data – For ratio data, both differences and ratio are meaningful. The difference
between the ratio and interval data is the position of zero in the scale. For example,
take the Centigrade-Fahrenheit conversion. The zeroes of both scales do not match.
Hence, these are interval data.
28
.
lOMoARcPSD|39472316
on that, the data can be classified as univariate data, bivariate data, and multivariate data. This is
shown in Figure 2.2.
Bar Chart A Bar chart (or Bar graph) is used to display the frequency distribution for variables.
Bar charts are used to illustrate discrete data. The charts can also help to explain the counts of
nominal data. It also helps in comparing the frequency of different groups.
The bar chart for students' marks {45, 60, 60, 80, 85} with Student ID = {1, 2, 3, 4, 5} is shown
below in Figure 2.3.
Pie Chart These are equally helpful in illustrating the univariate data. The percentage frequency
distribution of students' marks {22, 22, 40, 40, 70, 70, 70, 85, 90, 90} is below in Figure 2.4.
It can be observed that the number of students with 22 marks are 2. The total number of
students are 10. So, 2/10 × 100 = 20% space in a pie of 100% is allotted for marks 22 in Figure 2.4.
29
.
lOMoARcPSD|39472316
Histogram It plays an important role in data mining for showing frequency distributions.
The histogram for students’ marks {45, 60, 60, 80, 85} in the group range of 0-25, 26-50, 51-75,
76-100 is given below in Figure 2.5. One can visually inspect from Figure 2.5 that the number of
students in the range 76-100 is 2.
Histogram conveys useful information like nature of data and its mode. Mode indicates the
peak of dataset. In other words, histograms can be used as charts to show frequency, skewness
present in the data, and shape.
Dot Plots These are similar to bar charts. They are less clustered as compared to bar charts,
as they illustrate the bars only with single points. The dot plot of English marks for five students
with ID as {1, 2, 3, 4, 5} and marks {45, 60, 60, 80, 85} is given in Figure 2.6. The advantage
is that by visual inspection one can find out who got more marks.
For example, the mean of the three numbers 10, 20, and 30 is 20
30
.
lOMoARcPSD|39472316
• Weighted mean – Unlike arithmetic mean that gives the weightage of all items equally,
weighted mean gives different importance to all items as the item importance varies.
Hence, different weightage can be given to items. In case of frequency distribution, mid values of
the range are taken for computation. This is illustrated in the following computation.
In weighted mean, the mean is computed by adding the product of proportion and
group mean. It is mostly used when the sample sizes are unequal.
• Geometric mean – Let x1, x2, … , xN be a set of ‘N’ values or observations. Geometric mean
is the Nth root of the product of N items. The formula for computing geometric mean is
given as follows:
Here, n is the number of items and xi are values. For example, if the values are 6 and 8, the
geometric mean is given as In larger cases, computing geometric mean is difficult. Hence, it is
usually calculated as:
The problem of mean is its extreme sensitiveness to noise. Even small changes in the input
affect the mean drastically. Hence, often the top 2% is chopped off and then the mean is calcu-
lated for a larger dataset.
2. Median – The middle value in the distribution is called median. If the total number of items
in the distribution is odd, then the middle value is called median. A median class is that class
where (N/2)th item is present.
In the continuous case, the median is given by the formula:
Median class is that class where N/2th item is present. Here, i is the class interval of the
median class and L1 is the lower limit of median class, f is the frequency of the median class, and
cf is the cumulative frequency of all classes preceding median.
3. Mode – Mode is the value that occurs more frequently in the dataset. In other words, the
value that has the highest frequency is called mode.
2.5.3 Dispersion
The spreadout of a set of data around the central tendency (mean, median or mode) is called
dispersion. Dispersion is represented by various ways such as range, variance, standard deviation,
and standard error. These are second order measures. The most common measures of the
dispersion data are listed below:
Range Range is the difference between the maximum and minimum of values of the given list
of data.
Standard Deviation The mean does not convey much more than a middle point. For example,
the following datasets {10, 20, 30} and {10, 50, 0} both have a mean of 20. The difference between
these two sets is the spread of data. Standard deviation is the average distance from the mean of
the dataset to each point.
31
.
lOMoARcPSD|39472316
Here, N is the size of the population, xi is observation or value from the population and m is
the population mean. Often, N – 1 is used instead of N in the denominator of Eq. (2.8).
Quartiles and Inter Quartile Range It is sometimes convenient to subdivide the dataset using
coordinates. Percentiles are about data that are less than the coordinates by some percentage of
the total value. kth percentile is the property that the k% of the data lies at or below Xi. For
example, median is 50th percentile and can be denoted as Q0.50. The 25th percentile is called first
quartile (Q1) and the 75th percentile is called third quartile (Q3). Another measure that is useful
to measure dispersion is Inter Quartile Range (IQR). The IQR is the difference between Q3 and Q1.
Interquartile percentile = Q3 – Q1 (2.9)
Outliers are normally the values falling apart at least by the amount 1.5 × IQR above the third
quartile or below the first quartile.
Interquartile is defined by Q0.75 – Q0.25. (2.10)
Example 2.4: For patients’ age list {12, 14, 19, 22, 24, 26, 28, 31, 34}, find the IQR.
Solution: The median is in the fifth position. In this case, 24 is the median. The first quartile is
median of the scores below the mean i.e., {12, 14, 19, 22}. Hence, it’s the median of the list below
24. In this case, the median is the average of the second and third values, that is, Q0.25 = 16.5.
Similarly, the third quartile is the median of the values above the median, that is {26, 28, 31, 34}.
So, Q0.75 is the average of the seventh and eighth score. In this case, it is 28 + 31/2 = 59/2 = 29.5.
Hence, the IQR using Eq. (2.10) is:
= Q0.75 – Q0.25
= 29.5-16.5 = 13
Five-point Summary and Box Plots The median, quartiles Q1 and Q3, and minimum
and maximum written in the order < Minimum, Q1, Median, Q3, Maximum > is known as
five-point summary.
Example 2.5: Find the 5-point summary of the list {13, 11, 2, 3, 4, 8, 9}.
Solution: The minimum is 2 and the maximum is 13. The Q1, Q2 and Q3 are 3, 8 and 11, respectively.
Hence, 5-point summary is {2, 3, 8, 11, 13}, that is, {minimum, Q1, median, Q3, maximum}. Box plots
are useful for describing 5-point summary. The Box plot for the set is given in
Figure 2.7.
2.5.4 Shape
Skewness and Kurtosis (called moments) indicate the symmetry/asymmetry and peak location of
the dataset.
Skewness
The measures of direction and degree of symmetry are called measures of third order. Ideally,
skewness should be zero as in ideal normal distribution. More often, the given dataset may not
32
.
lOMoARcPSD|39472316
Generally, for negatively skewed distribution, the median is more than the mean. The relationship
between skew and the relative size of the mean and median can be summarized by a convenient
numerical skew index known as Pearson 2 skewness coefficient.
Also, the following measure is more commonly used to measure skewness. Let X1, X2, …, XN
be a set of ‘N’ values or observations then the skewness can be given as:
Here, m is the population mean and s is the population standard deviation of the univariate
data. Sometimes, for bias correction instead of N, N - 1 is used.
Kurtosis
Kurtosis also indicates the peaks of data. If the data is high peak, then it indicates higher kurtosis
and vice versa. Kurtosis is measured using the formula given below:
It can be observed that N - 1 is used instead of N in the numerator of Eq. (2.14) for bias correction.
Here, x and s are the mean and standard deviation of the univariate data, respectively.
Some of the other useful measures for finding the shape of the univariate dataset are mean
absolute deviation (MAD) and coefficient of variation (CV).
33
.
lOMoARcPSD|39472316
Figure 2.9.
It can be seen from Figure 2.9 that the first column is stem and the second column is leaf.
For the given English marks, two students with 60 marks are shown in stem and leaf plot as stem-
6 with 2 leaves with 0. The normal Q-Q plot for marks x = [13 11 2 3 4 8 9] is given below in
Figure 2.10.
Here, the aim of bivariate analysis is to find relationships among variables. The relationships can
then be used in comparisons, finding causes, and in further explorations. To do that, graphical
display of the data is necessary. One such graph method is called scatter plot.
Scatter plot is used to visualize bivariate data. It is useful to plot two variables with or without
34