Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Humans
You are free to copy, share, remix and reproduce this book, provided that you properly give
credit to original authors and you give readers the same freedom you enjoy.
Read the full terms at https://creativecommons.org/licenses/by-sa/3.0/
Contents
1 Introduction 1
1.1 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.2 Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.3 Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 What is Machine Learning? . . . . . . . . . . . . . . . . . . . . . . 2
2 Foundations 3
2.1 Describe the world . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 What is Data? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Find the edges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4 Find the center . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.5 Measure error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.6 Groups - clusters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.7 Probability and uncertainty . . . . . . . . . . . . . . . . . . . . . . 6
2.8 Supervised or unsupervised? . . . . . . . . . . . . . . . . . . . . . . 7
3 Visualization 8
3.1 Intro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2 Scatterplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4 Supervised Learning 10
4.1 Nearest Neigbors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.1.1 What? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.1.2 Why? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.1.3 How? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.1.4 Try it. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2 Classification Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Contents 3 / 20
4.2.1 What? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2.2 Why? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2.3 How? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2.4 Try it. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.3 Linear Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.3.1 What? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.3.2 Why? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.3.3 Try it out . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.4 Logistic Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.4.1 What? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.4.2 Why? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.4.3 How? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.4.4 Try it. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5 Unsupervised Learning 15
5.1 K-Means Clustering . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.1.1 Additional resources . . . . . . . . . . . . . . . . . . . . . . 16
6 Appendix 17
6.1 Further Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
6.1.1 Articles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
6.1.2 Books . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Chapter 1
Introduction
1.1 Purpose
1.1.1 Style
This book will attempt to avoid technical jargon and complicated mathematics
to the greatest extent possible. It is intended as a gentle introduction for a casual
reader. There are many resources available to continue learning more in-depth
concepts.
Where code examples are helpful we will use Python, since it is widely adopted
in the machine learning community and has friendly syntax.
1.1.2 Approach
We will focus on machine learning concepts from a high level, using diagrams
and visual programming where possible. When code is needed, it will be self-
contained. This means that each chapter should stand alone (aside from installing
dependencies for the book).
1.1.3 Structure
• What?
• Describe the concept, e.g. what the machine learning algorithm does
• Why?
• How?
Chapter 1. Introduction 2 / 20
• Try it.
This structure is intended to give the reader a framework for understanding, and
practical hands-on exercises. The try it exercises should be relatively easy to
complete, so the reader has a quick sense of accomplishment.
1.2 Tools
The two dependencies listed above are built on other, lower-level dependencies
that were not mentioned for simplicity. As we explore the machine learning code
examples, we will encounter the other dependencies.
• Unsupervised Learning: When our system looks at the data and tries to
formulate or make sense of the weakly defined or visible rules in the data.
• Reinforcement Learning: It is when system learns from the trial and error
method just like a new born kid.
Chapter 2. Foundations 3 / 20
Chapter 2
Foundations
Our process begins by describing the world in some way. We make a series of
observations of some type of object or phenomena. Each observation has one
or more qualities, commonly called attributes. Attributes can be thought of in
a couple of ways, names or numbers.
Names
Names are quite common, and are usually distinguished by different text. For
example, we might have different names for a quality we call color, which could
include red, orange, and blue.
Numbers
Numbers may contain more detail than names. For example numbers can tell us
how things are ordered, or how large they are when compared with one another.
We will see these types of measurement referred to as Ordinal, meaning ordered,
and Interval, meaning there is a regular distance from one number to the next
(hence magnitude).
Data is any piece of information or observation about any object or person organ-
ised into variables to make the processing easier. Variable are the basic building
blocks that hold information about any observation about the particular object.
In this table, rows are the observations and each column is the variables contain-
ing information about the object that is fruit.
Chapter 2. Foundations 4 / 20
• Categorical Variable: These are the variable that takes category or label
values from the finite set of values. In the above table, you can already
guess its the ” Shape ” variable that is categorical as it can only hold two
values Circular/Bumpy.
• Qualitative Variable: These are the variable that takes numerical values
and represent some kind of measurement. In the above table, “Weight” is
the qualitative value that contains the numerical value of measurements.
1.6
mode
1.4
median
1.2
mean
1.0
0.8
0.6 σ = 0.25
0.4
σ=1
0.2
0.0
0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2
Comparing Mean,
Median, and Mode. Notice how the shape of the ’distribution’ affects each
measurement. By Cmglee, CC BY-SA 3.0, Link
Mean
The Mean, commonly called ’average’, looks at for the center as a measurement
of how spread out the group members are and where most members reside. It
is subject to bias from the most far reaching members of the group, known as
outliers. Despite the strong influence of outliers, the Mean is a very common way
to find the center of a group, or distribution.
Chapter 2. Foundations 5 / 20
Median
Median is a way to find the center by dividing the set of observations exactly in
half. It doesn’t matter how many of each value there are, just that there are an
equal number of observations on each side.
Mode
Mode considers the center as the value that is seen most frequently. In other
words, the Mode is the value observed with the highest count.
When observations appear in groups, we often call those groups ’clusters’. Clus-
tering is process of dividing a set of observations into different clusters or groups
on the basis of attributes.
Chapter 2. Foundations 6 / 20
In many ways, the world around us is uncertain* [1]. We have developed ways to
describe our level of uncertainty, and attempt to predict uncertain events. When
an event might occur, we can say there is some probability* [2] that it might
happen.
Probability is typically expressed in percentages. For example, there might be a
30% probability of rain tomorrow. Predicting the outcome of some event is called
forecasting.* [3]
Conditional probability
Some events depend on previous events. For example, the weather tomorrow is
dependent* [4] on the weather today. Dynamic systems* [5]* [6]* [7] are those,
such as weather, where the current situation is sensitive to previous situations.
References
There are times when we want to group observations together. For example,
grouping animals by diet. Sometimes, the group ’labels’ are known in advance
and sometimes there are no clear labels. These two cases roughly divide the realm
of machine learning into two pillars: unsupervised and supervised learning.
Chapter 3. Visualization 8 / 20
Chapter 3
Visualization
3.1 Intro
3.2 Scatterplot
Example scatterplot
showing three variables: petal width, petal length, and species
Chapter 4. Supervised Learning 10 / 20
Chapter 4
Supervised Learning
4.1.1 What?
4.1.2 Why?
4.1.3 How?
4.2.1 What?
A classification tree, like its name implies, has a root and a series of branches,
eventually terminating at leaf nodes. Unlike regular trees, however, they tend
to grow upside down.
At the root are all observations in a data set and some decision boundary that
separates the observations into two groups.
Chapter 4. Supervised Learning 11 / 20
The two groups are again separated into two subsets each, along another dividing
point. This process repeats a given number of times, called depth.
At the end of the line, we can see the result of the series of decisions. Every
observation that enters at the top of the decision tree will pass through a number
of decision nodes and end up in one of the leaf nodes.
The nodes also tell us how many observations from the training data set would
be accurately classified with the given decision boundaries.
To improve accuracy, we can increase the depth of the decision tree, at the risk
of overfitting the training data set.
4.2.2 Why?
Classification trees provide us humans with an intuitive glimpse into the classi-
fication model. They can be used manually to guide decisions or to gain under-
standing of factors that distinguish observations. Classification trees are one of
the easier types of machine learning algorithms for humans to understand.
4.2.3 How?
4.3.1 What?
4.3.2 Why?
You may have a lot of data with a real valued attribute, such as temperature
observations. You may wish to see which ’direction’ the data is trending. A
linear regression would draw a line through the middle of your data, with as little
Chapter 4. Supervised Learning 12 / 20
error as possible. This gives you a quick glimpse of the data and a way to predict
an x value for any value of y.
Visualization of a linear
regression. Original author: Jake Vanderplas Introduction to Scikit-Learn: Machine
Learning with Python
Let’s say you have an input which when fed into a function gives you a certain
output. With that function you can predict any value (output) for any given
value (input). Mathematically it can be defined as follows :
output=F(input)
Our task in regression is of predicting the output accurately. For that purpose first
we need to get an approximate function F( ) so that when we give that function
an input it can predict those desired value for us. One thing that must be noted
is that the more our function is approximated accurately the more accurate our
predictions.
I have used the word approximated because in real world data no variable can be
strictly said to follow a specific pattern there can be noise, error or many other
ambiguities.
Okay lets first understand the data we will be dealing with.
Format of data :
• a variable X (Input)
• a variable y (Output). We have various instance of the X’s and their corre-
sponding y’s. Our aim is to find a function best describing these patterns
and which can also help us in predicting values for new X’s.
Notation :
Data points : (x,y) instances in our data
n - number of data points
Chapter 4. Supervised Learning 13 / 20
Task 1
Task 2
Task 3
4.4.1 What?
4.4.2 Why?
4.4.3 How?
Chapter 5
Unsupervised Learning
What?
Why?
How?
Limitations
One possible outcome is that there are no organic clusters in the
data; instead, all of the data fall along the continuous feature ranges
within one single group.* [1]
Chapter 6
Appendix
There are many great resources we can use to further explore machine learning.
Here are a few.
6.1.1 Articles
6.1.2 Books
Chapter 7
7.1 Text
• Course:Machine Learning for Humans/Introduction/Purpose Source: https://en.
wikitolearn.org/Course%3AMachine_Learning_for_Humans/Introduction/Purpose?oldid=
8861 Contributors: Brylie, Athale and Anonymous: 1
• Course:Machine Learning for Humans/Introduction/Tools Source: https://en.wikitolearn.
org/Course%3AMachine_Learning_for_Humans/Introduction/Tools?oldid=7699 Contrib-
utors: Brylie
• Course:Machine Learning for Humans/Introduction/What is Machine Learn-
ing? Source: https://en.wikitolearn.org/Course%3AMachine_Learning_for_Humans/Introduction/
What_is_Machine_Learning%3F?oldid=8681 Contributors: Vijaykrishnavanshi
• Course:Machine Learning for Humans/Foundations/Describe the world Source:
https://en.wikitolearn.org/Course%3AMachine_Learning_for_Humans/Foundations/Describe_
the_world?oldid=7749 Contributors: Brylie
• Course:Machine Learning for Humans/Foundations/What is Data? Source: https:
//en.wikitolearn.org/Course%3AMachine_Learning_for_Humans/Foundations/What_is_
Data%3F?oldid=11117 Contributors: Vijaykrishnavanshi and Bro666
• Course:Machine Learning for Humans/Foundations/Find the edges Source: https:
//en.wikitolearn.org/Course%3AMachine_Learning_for_Humans/Foundations/Find_the_
edges?oldid=7743 Contributors: Brylie
• Course:Machine Learning for Humans/Foundations/Find the center Source: https:
//en.wikitolearn.org/Course%3AMachine_Learning_for_Humans/Foundations/Find_the_
center?oldid=7737 Contributors: Brylie
• Course:Machine Learning for Humans/Foundations/Measure error Source: https:
//en.wikitolearn.org/Course%3AMachine_Learning_for_Humans/Foundations/Measure_
error?oldid=7739 Contributors: Brylie
• Course:Machine Learning for Humans/Foundations/Groups - clusters Source:
https://en.wikitolearn.org/Course%3AMachine_Learning_for_Humans/Foundations/Groups_
-_clusters?oldid=9064 Contributors: Valsdav and Brylie
• Course:Machine Learning for Humans/Foundations/Probability and uncertainty
Source: https://en.wikitolearn.org/Course%3AMachine_Learning_for_Humans/Foundations/
Probability_and_uncertainty?oldid=7788 Contributors: Brylie
• Course:Machine Learning for Humans/Foundations/Supervised or unsupervised?
Source: https://en.wikitolearn.org/Course%3AMachine_Learning_for_Humans/Foundations/
Supervised_or_unsupervised%3F?oldid=8845 Contributors: Brylie
• Course:Machine Learning for Humans/Visualization/Intro Source: https://en.wikitolearn.
org/Course%3AMachine_Learning_for_Humans/Visualization/Intro?oldid=7758 Contrib-
utors: Brylie
Chapter 7. Text and image sources, contributors, and licenses 19 / 20
7.2 Images
• File:Animation_of_k-means_clustering.gif Source: http://en.wikitolearn.org/images/
en/0/0d/Animation_of_k-means_clustering.gif License: ? Contributors: ? Original artist:
?
• File:Comparison_mean_median_mode.svg Source: http://en.wikitolearn.org/images/
en/d/de/Comparison_mean_median_mode.svg License: ? Contributors: ? Original artist:
?
• File:Data_with_clustered_points.png Source: http://en.wikitolearn.org/images/en/
e/e5/Data_with_clustered_points.png License: ? Contributors: ? Original artist: ?
• File:Decision-tree-orange-canvas-iris-dataset.png Source: http://en.wikitolearn.org/
images/en/3/3e/Decision-tree-orange-canvas-iris-dataset.png License: ? Contributors: ?
Original artist: ?
• File:Decision_tree_leaf_nodes_showing_accuracy_of_classification.png Source:
http://en.wikitolearn.org/images/en/1/15/Decision_tree_leaf_nodes_showing_accuracy_
of_classification.png License: ? Contributors: ? Original artist: ?
• File:Decision_tree_showing_decision_boundary.png Source: http://en.wikitolearn.
org/images/en/6/6a/Decision_tree_showing_decision_boundary.png License: ? Contrib-
utors: ? Original artist: ?
• File:K-means_clustering_visualization.png Source: http://en.wikitolearn.org/images/
en/0/01/K-means_clustering_visualization.png License: ? Contributors: ? Original artist:
?
• File:Linear_regression_visualization.png Source: http://en.wikitolearn.org/images/
en/9/9b/Linear_regression_visualization.png License: ? Contributors: ? Original artist:
?
• File:Scatterplot_example_showing_petal_length_with_petal_width.png Source:
http://en.wikitolearn.org/images/en/d/d3/Scatterplot_example_showing_petal_length_
with_petal_width.png License: ? Contributors: ? Original artist: ?
Chapter 7. Text and image sources, contributors, and licenses 20 / 20