# Machine Learning Demystified

This blog post will help you understand complex world of machine learning by using every day examples. Check out sample machine learning Python code using a popular Iris data set -https://adityak6798.github.io/ml-walkthrough.html

### Simplified way to understand Machine Learning

You do online shopping and as soon as you login you see items displayed to you based on your previous searches or purchases.

*Ever wondered what goes behind the scene?*

Most of the online shopping sites use machine learning to recommend items that you may be interested in. Item recommendation is based on your previous searches or your shopping history or based on what other customers purchased similar to the item you are searching for.

This is Machine Learning-ML, where patterns in historical data is used to predict future behavior

#### Official Definition of Machine Learning

**A computer program is said to learn from an experience E with respect to some class of task T and performance measure P, if it is performance P for task T improves with experience E.**

*But wait! What does this cryptic stuff mean? Layman’s terms please.*

Expanding on the online shopping example, Computer program will learn and recommend Items for purchase based on your shopping history and searches and shopping history of other customers — this is termed as experience E and online shopping is Task T. Performance P is a measure of how well the site displays the right Items or Products you may be interested in.

*I hope this helped clarify how we use machine learning in everyday life*

#### Summarizing machine learning

Machine Learning is a science of teaching computers to learn and understand patterns from historical data to make predictions for better decision making.

Moving forward, Machine learning is classified into Supervised and Unsupervised

#### Supervised Machine Learning:

The Geeky Stuff:

*For each observation of the predictor measurement(s) Xi, i = 1,…,n there is an associated response measurement Yi.*

*Our goal is to fit a model that has learnt the patterns from the data from historical observation to accurately predict the response for future observations. It does this by understanding relationship between the response(Y) and the predictors (X)*

*What does it even mean?*

Using another example that we all have gone through in life

Imagine a child’s learning under supervision of a teacher where they use historical information to guide the child and furthermore trains the child to make better decisions.

Consider a parent is teaching a child to walk on different surfaces holding the child’s hand. With the parent’s historical experience they know that if the child is to fall on the soft surface it will not hurt, but if the child falls on hard surface it will hurt. This experience is then turned into patterns which further helps the child understand difference between falling on hard or soft surfaces. That is what we call supervised learning.

In supervised learning, we are given a data set in which we already know the output and can identify a relationship between the input and output.

In our example above, based on the child’s experience of walking on hard or soft surfaces the child now knows the output due to the parent’s past experiences- how much it will hurt if the child falls.

*Ah . Okay.*

Supervised Machine learning are of two types

**Regression **— The output is a continuous variable (eg. Predict Housing Prices)

**Classification **— The output is a discrete variable (eg. Cat vs Dog)

*Continuous? Discrete? Help please?*

**Continuous means **it’s a number that can take any value like a house price can be 105K, 212K etc.

**Discrete **means it takes on only a few values(like 0–1) like an email can be spam or not a spam.

### Unsupervised Machine Learning:

The Geeky Stuff:

*Unsupervised learning describes the somewhat more challenging situation. For every observation i = 1,…,n, for input variables Xi there is no associated response Yi.*

*It is not possible to fit a linear regression model, since there is no response variable to predict. In this setting, since we do not have any supervision, we are in some sense working blind.*

*This situation is referred to as unsupervised learning because we lack a response variable that can supervise our analysis.*

*Okay…*

Unsupervised Learning happens when no historical response is fed in and a data pattern emerges on its own based on the predictors alone.

Taking the same example as above, when no ones teaches the kid and kid experiences things on their own to identify the difference between hard and soft surfaces.

In the future, kid is more careful when walking on hard surfaces based on the data pattern or experiences they had and hence in future that is used for better decision making.

This helps to identify complex processes and patterns without any supervision or guidance. Trying to find a structure in an unlabeled data.

At a high level the difference between Supervised and Unsupervised Machine Learning

**Supervised Machine Learning**

Target or output variable is already known.

Each observation is labelled with a correct answer

Supervised learning is advanced predictive modelling

Examples :

To classify an email as spam or not a spam or

What would be the percentage of a patient having a cancer based on certain key parameters

Common models:

Regression model is used for predicting quantitative data

Classification models are used for predicting categorical data

**Unsupervised Machine Learning**

Target or output variable is unknown

There is no correct answer for the observations. A pattern must emerge based on the data without any guidance

Automated data analysis

Example:

Recommending books or movies to customers or

Market segmentation to target the right customers

Common Models:

Clustering, where you find groups within the data

Recommender systems to recommend movies or products

**Terms often used in Machine learning:**

*I hear lots of technical jargon in Machine Learning. Can you help with that…?*

Sure. Consider this as a cheat sheet. These terms are commonly used in Machine Learning(ML)

** Observations**: Each example in the dataset, which is also referred as historical data. It can consist of multiple variables. All input variables (remember them from before?) have a certain value for each example. Together, they are known as observations.

Some times the dataset can have a response variable (remember Supervised learning). When response variable is not present then we may opt for unsupervised learning

** Features or Input variable or Predictors**: Independent variables in the dataset that is used to make predictions. These are the variables that have an impact on the output or target variable.

*What is Independent variables? Can you explain more on this…*

The input values, which do not affect each other -like area of a house or number of windows in the house or how close the house is to a school. Remember, these values are used as inputs to the (machine learning) ML algorithm.

*Target Variable or Output Variable** : *Variable that you are trying to predict from the dataset. Also called as Output variable or Dependent variable or Target variables.

For example, to predict the drinking habit of college students. Here the target variable will be whether the student will have a drinking problem yes or no based on certain independent variables like if someone in family smokes and drinks, if they have friends or siblings smoking etc.

** Training Set** : Dataset that is used to train the ML algorithm.

** Test set** : Dataset that is used to validate the ML algorithm’s performance.

*Model**:* Set of patterns learned from the data. Also known as the ML algorithm, as the algorithm learns the patterns from the training Set.

** Machine Learning Algorithm**: specific ML algorithms used to train the model. Example : Linear Regression, K-Nearest Neighbor, Support Vector Machines(SVM) etc.

*Now, for some math terminology. Don’t worry about these terms, they are very mathematical. You’ll get the hang of it later. These are mainly used to talk about the data.*

*Bi-variate Analysis**:* Analyzing the relationship between two(bi) variables. Use scatter plots to understand bi-variate relationships.

*What is a Scatter plot?*

A type of plot, where you plot the values of one variable on one axis, and the other variable on the other to understand their relationship. Thus for a given set of examples, you plot each point, and you can visualize the relationship between them(if any).

Below diagram shows a scatter plot between total Bill amount and it’s relationship to the tip amount

** Co-variance**: A measure to specify if two variables covary together. It is about the direction of change between two variables. The strength of the relationship between two variables is determined by correlation.

It can be positive co-variance, near zero or negative co-variance.

When a change in one variable has a linear impact on the other variable. In the above example as the bill amount increases there is an increase in tip amount.

Co-variance has no lower or upper bound and its scale is dependent on the scale of the variables.

** Correlation**: describes the direction and strength between two variables.

Correlation varies between +1 to -1 and is standardized. Value of correlation is independent of the scale of the variable .

An example of correlation between outside temperature and energy consumption. Both — Temperature and energy consumption, is measured in different units but there correlation and it will always be within +1 and -1

Correlation does not always mean causation.

*What is Causation?*

When one thing causes another. Like when raining, it makes grass wet.

Looks like you followed along! Congrats! You are now ready to dive deep into ML

*Okay. Say I’ve got data, and trained a model. What next and how do I know which model is best for my use case?*

Good! You are on the right-thinking process. Now read ahead… for more deeper understanding

### How Do you evaluate an Algorithm,

A Machine Learning algorithm is evaluated by

Ease of interpreting the output

Calculation time

Predictive Power

*For a real life machine learning program, we do the following steps. We will discuss these in detail in the next series*

Steps for Machine Learning

1. Data Exploration and Data Visualization

3. Feature Engineering

4. Algorithm selection

5. Model Training

6. Test the model

7. Measure the model performance

8. Monitor the real world results and adjust the model

Credits:

https://www.youtube.com/user/BCFoltz

**Medium - a place to read and write big ideas and important stories**

*Welcome to Medium, a place where words matter. Medium taps into the brains of the world's most insightful writers…*medium.com