PC - Collections Sous Python
PC - Collections Sous Python
Chapitre 4
TUPLES
Creation of tuples and data access
#définition d'un tuple The ( ) are important to indicate that it is a
t1 = (2,6,8,10,15,26) tuple, « , » separates the items.
print(t1)
#taille du tuple (2,6,8,10,15,26)
print(len(t1)) 6 items
#accès indicé
Firstitem, indices go from 0 to len(t1)-1
a = t1[0]
print(a) Note: a is not a tuple
#modification ?
t1[2] = 3 ERROR
#plage d'indices
b = t1[2:5] Warning: we recover from n°2 (included) ton°5
print(b) (not-included) i.e.. the indices 2, 3, 4
#autre plage Result : b is a tuple with (8,10,15)
c = t1[:4]
print(c) The 4 first items i.e. the indices 0, 1, 2, 3 : we obtain the tuple
#indiçage négatif (2, 6, 8, 10).
d = t1[-1]
print(d) Le 1er last from the end :26
#indiçage négatif
e = t1[-3:]
print(e) The 3 last items : (10,15,26)
#concatenation
t2 = (7, 9,31) (2,6,8,10,15,26,7,9,31)
t3 = t1 + t2
print(t3)
(7,9,31,7,9,31)
#replication
t4 = 2 * t2
print(t4) it poses no problem
#tuples heterogeneous objects
v1 = (3,6,"toto",True,34.1)
print(v1)
Kind of 2-dimensional array
#tuple of tuples
x = ((2,3,5),(6,7,9),(1,8))
print(x)
x[0] → (2,3,5) Organisationf of
# indexed access x[1] → (6,7,9) the structure
print(x[2][1]) → 8 x[2] → (1,8)
#access to size
print(len(x)) → 3 3 items on the 1ère dimension
print(len(x[2])) → 2 2 items in the tuple referenced by x[2]
Review of tuples
LISTS
List – type list
Objective : a simple (and concise) mechanism to generate a list from another list
source = [1,5,8,12,7]
resultat = [] resultat = [v**2 for v insource]
for v in source: print(resultat)
[Link](v**2)
print(resultat)
source = [1,5,8,12,7]
resultat = []
for v in source: resultat = [v**2 for v in source if (v %2== 0)]
if (v % 2 == 0): print(resultat)
[Link](v**2)
print(resultat)
Content Processing
L2 = [21,69,69,32,34,55]
#search for item
trouve = 32 in L2 Return True since the value
print(trouve) 32 is in the list
#index
Return 4 since the value 34 appears at
id = [Link](34)
index n°4 (index of the 1st found)
print(id)
#L3
L3 = [61,92,17]
L4[1] = 55
print(L4) → [61,55,17]
A list is directly
“iterable”, there is no need to
use an index
Exercice
8.Écris un programme qui compte combien de fois un élément apparaît dans une
liste.
A special case of list
String
A string is a particular list with associated methods
#définir une chaîne
s1 = "bonjour le monde"
Quotes to delimit a string
print(s1)
#longueur
long = len(s1) Mechanism identical to
print(long) tuples and lists
#accès indicé
s2 = s1[:7]
print(s2) ERROR. A string cannot be edited. It is necessary to put
#non modifiable
#s1[0] = "B" the result of a manipulation in another chain.
#méthodes associées
S = [Link]()
print(S)
#recherche d'une sous-chaîne
id = [Link]("JO") Specific methods allow you to
print(id) 3 (1ère occurrence si plusieurs) manipulate strings. See
#nb d'occurences [Link]
nb = [Link]("ON") [Link]#text-sequence-type-str
print(nb) 2
#remplacement de « O » par « A »
SA = [Link]("O","A")
print(SA)
Explicit transformation into a list (for processing)
DICTIONARIES
Dictionnary - The type dict Dictionnaire : unordred
#définition d'un dictionnaire
d1 = {'Pierre':17, 'Paul':15,'Jacques':16}
(unindexed) collection of
print(d1) objects (simple or
#ou complex) based on the
Noter le rôle de { }, de « :»
print([Link]())
et « ,» associative mechanism
#nombre d'élements « key – value ».
print(len(d1)) → 3 items
In thisexample :
• Key is a tuple;
• value is a list.
Example
Example :
Kate 15.0
Pipa 23.5
William 10.7
49.2
Exercice
3. Crée un dictionnaire qui compte le nombre de lettres dans un mot saisi par
l’utilisateur.
Machine
Learning A-Z
Course Slides
Data
Preprocessin
g
The Machine
Learning
Process
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
The Machine Learning Process
Data Pre-Processing
• Import the data
• Clean the data
• Split into training & test sets
• Feature Scaling
Modelling
• Build the model
• Train the model
• Make predictions
Evaluation
• Calculate performance metrics
• Make a verdict
Training Set
& Test Set
Training Set &Test Set
~
Train
80% 𝑦 = 𝑏0 + 𝑏1𝑋1 + 𝑏2𝑋2
Test
20% V.S.
Predicted values 𝑦! Actual values 𝑦
Feature
Scaling
Feature Scaling
Feature Scaling
Normalization Standardization
𝑋 − 𝑋𝑚𝑖𝑛 𝑋−𝜇
𝑋! = 𝑋! =
𝑋𝑚𝑎𝑥 − 𝑋𝑚𝑖𝑛 𝜎
70,000 $ 45 yrs
10,000 1
60,000 $ 44 yrs
8,000 4
52,000 $ 40 yrs
Feature Scaling
Normalization
!
𝑋 − 𝑋 𝑚𝑖𝑛
𝑋 =
𝑋𝑚𝑎𝑥 − 𝑋𝑚𝑖𝑛
[0 ;1]
Feature Scaling
70,000 $ 45 yrs
60,000 $ 44 yrs
52,000 $ 40 yrs
Feature Scaling
1 45 yrs
0.444 44 yrs
0 40 yrs
Feature Scaling
1 1
0.444 0.7
5
0 0
Regression
©SuperDataScience
Simple Linear
Regression
Simple Linear Regression
𝑦! = 𝑏0 + 𝑏1 𝑋1
Dependent variable Independent variable
y-intercept (constant)
Slope coefficient
Simple Linear Regression
Each point represents
𝑦 [tonnes] a separate harvest
(Potato yield)
~
+3𝑡
𝑦= 𝑏0 + 𝑏1𝑋1
𝑃𝑜𝑡𝑎𝑡𝑜𝑒𝑠 𝑡 = 𝑏0 + 𝑏1×𝐹𝑒𝑟𝑡𝑖𝑙𝑖𝑧𝑒𝑟 𝑘𝑔
8𝑡
𝑏0 = 8[𝑡]
𝑡 𝑋1 [kg]
+1𝑘𝑔
𝑏1 = 3[ ] (Nitrogen Fertilizer)
𝑘𝑔
Ordinary
Least Squares
Simple Linear Regression
𝑦 [tonnes]
Ordinary Least Squares: (Potato yield)
𝑦𝑖
𝑟𝑒𝑠𝑖𝑑𝑢𝑎𝑙: 𝜀𝑖 = 𝑦𝑖 − 𝑦^𝑖
𝑦^𝑖
𝑦𝑖
𝑦 = 𝑏0 + 𝑏1𝑋1 𝑦^𝑖
𝑦= 𝑏0 + 𝑏1 𝑋1 + 𝑏2𝑋2 + ⋯ + 𝑏𝑛 𝑋𝑛
Dependent variable Independent variable 1 Independent variable 2 Independent variable n
~
𝑡 𝑡 𝑡
𝑃𝑜𝑡𝑎𝑡𝑜𝑒𝑠 𝑡 = 8𝑡 + 3 ×𝐹𝑒𝑟𝑡𝑖𝑙𝑖𝑧𝑒𝑟 𝑘𝑔 − 0.54 ×𝐴𝑣𝑔𝑇𝑒𝑚𝑝 °𝐶 + 0.04 ×𝑅𝑎𝑖𝑛[𝑚𝑚]
𝑘g °𝐶 𝑚𝑚
R Squared
R Squared
𝑦 [tonnes] Regression: 𝑦 [tonnes] Average:
(Potato yield) (Potato yield)
𝑦𝐴𝑣g
𝑦𝑖 𝑦𝑖
𝑦! 𝑖
𝑋1 [kg] 𝑋1 [kg]
(Nitrogen Fertilizer) (Nitrogen Fertilizer)
©SuperDataScience
Adjusted R Squared
𝑆𝑆𝑟𝑒𝑠
𝑅2 = 1 − R2 – Goodness of fit
𝑆𝑆𝑡𝑜𝑡 (greater is better)
Problem:
𝑦
^ = 𝑏0 + 𝑏1𝑋1 + 𝑏2𝑋2 + 𝑏3𝑋3 𝑆𝑆𝑟𝑒𝑠 = 𝑆𝑈𝑀(𝑦𝑖 − 𝑦! 𝑖 ) 2
𝑆𝑆𝑡𝑜𝑡 doesn’t change
𝑆𝑆𝑟𝑒𝑠 will decrease or stay the same (This is because of Ordinary Least Squares: 𝑆𝑆𝑟𝑒𝑠->Min)
Solution:
𝑛−1
𝐴𝑑𝑗 𝑅2 = 1 − 1 − 𝑅2 ×
𝑛−𝑘−1
k – number of independent variables
n – sample size
Assumptions Of
Linear
Regression
Assumptions of Linear Regression
𝑋1~ 𝑋2 𝑋1~ 𝑋2
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Profit R&D Spend Ad min Marketing State
X1 y X7
Why?
Machine Learning A-Z
1)
2)
STEP 3: Consider the predictor with the highest P-value. If P >SL, go to STEP 4, otherwise go to FIN
STEP 2: Fit all simple regression models y ~ xn Select the one with the lowest P-value
STEP 3: Keep this variable and fit all possible models with one extra predictor added to the one(s) you
already have
STEP 4: Consider the predictor with the lowest P-value. If P <SL, go to STEP 3, otherwise go to FIN
STEP 2: Perform the next step of Forward Selection (new variables must have: P <SLENTER to enter)
STEP 3: Perform ALL steps of Backward Elimination (old variables must have P <SLSTAY to stay)
STEP 4: No new variables can enter and no old variables can exit
Example:
FIN: Your Model Is Ready 10 columns means
1,023 models
Multiple
Linear
Regression
Polynomial
Linear
Regression
x1
x1
x1
ε
ε
x1 x1
ξ5 ε
ξ3
ξ2 ε
ξ4*
ξ1*
x1 x1
Link:
[Link]
1 Copy of support_vector_regression.ipynb
c o @ Comment Share @
File Edit View Insert Runtime Tools HeJp AII chąngessaved
RAM
+ Code + Text Disk -
Editing •••
:= Files
6 Upload C Refresh Mount Drive Position_SaIaries.csv X
Visualising the SVR results (for higher resolution and smoother curve) C-level
CEO
9
1D
500000
1000000
Show ”zo t per page
1 x_grid = [Link](min(ec_X.inveree_transform(X)), max(sc_X.inveree_trane£orm(X)), 0.1)
2 x_grid = X_grid.reshape((len(X_grid), 1))
3 [Link](sc_x.inverse_transform(x), sc_y.inverse_tranaform(y1, color = 'red’)
sc_y.inyerse tranp€orm([Link](sq_X.transform(X_grid))), color = ’blue')
Bluff (Support Vector Regression)')
6 [Link]('Position level')
7 [Link]('Salary')
8 [Link]()
Split 3
200
Split 2
170
Split 4
20 40 X1
20
X2
Yes
20
X2
170
Yes
Yes
No
X1<20
Yes
Split 3
200
Split 2
170
20 X1
Yes
No
X1<20
Yes
Yes No
X2 <200 X2 <170
Yes No Yes No
Split 3
200
Split 2
170
Split 4
20 40 X1
Yes No
X2 <200 X2 <170
Yes No Yes No
Yes No
X2 <200 X2 <170
Yes No Yes No
X1 <40
Yes No
65.7
Split 3 1023
200
Split 2
170
Split 4
20 40 X1
Yes No
X2 <200 X2 <170
Yes No Yes No
X1 <40
Yes No
Yes No
X2 <200 X2 <170
Yes No Yes No
Yes No
-64.1 0.7
STEP 3: Choose the number Ntree of trees you want to build and repeat STEPS 1& 2
STEP 4: For a new data point, make each one of your Ntree trees predict the value of Y to
for the data point in question, and assign the new data point the average across all of the
predicted Y values.
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
R Squared
𝑦 [tonnes] 𝑦 [tonnes]
Regression: Average:
(Potato yield) (Potato yield)
𝑦𝐴𝑣g
𝑦𝑖 𝑦𝑖
𝑦! 𝑖
𝑋1 [kg] 𝑋1 [kg]
(Nitrogen Fertilizer) (Nitrogen Fertilizer)
©SuperDataScience
Adjusted
R Squared
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Adjusted R Squared
𝑆𝑆𝑟𝑒𝑠
𝑅2 = 1 − R2 – Goodness of fit
𝑆𝑆𝑡𝑜𝑡 (greater is better)
Problem:
𝑦
^ = 𝑏0 + 𝑏1𝑋1 + 𝑏2𝑋2 + 𝑏3𝑋3 𝑆𝑆𝑟𝑒𝑠 = 𝑆𝑈𝑀(𝑦𝑖 − 𝑦! 𝑖 ) 2
𝑆𝑆𝑡𝑜𝑡 doesn’t change
𝑆𝑆𝑟𝑒𝑠 will decrease or stay the same (This is because of Ordinary Least Squares: 𝑆𝑆𝑟𝑒𝑠->Min)
Solution:
𝑛−1
𝐴𝑑𝑗 𝑅2 = 1 − 1 − 𝑅2 ×
𝑛−𝑘−1
k – number of independent variables
n – sample size
©SuperDataScience
Classification
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
What is Classification?
Classification: a Machine Learning technique to identify the
category of new observations based on training data.
©SuperDataScience
Logistic
Regressio
n
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Logistic Regression
Logistic regression: predict a categorical 𝑦 [yes/no]
dependent variable from a number of (Took up offer?)
independent variables.
YES
~ YES
81%
≥ 50%
Will purchase Age
< 50%
health insurance:
Yes / No 42%
𝑝 NO
ln = 𝑏0 + 𝑏1𝑋1 NO
1−𝑝 18 35 45 60
𝑋1 [yrs]
(Age)
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Logistic Regression
~
Will purchase Age Income Level of Family or
health insurance: Education Single
Yes / No
𝑝
ln = 𝑏0 + 𝑏1𝑋1 + 𝑏2𝑋2 + 𝑏3𝑋3 + 𝑏4𝑋4
1–𝑝
©SuperDataScience
Maximum
Likelihood
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Maximum Likelihood
𝑦 [yes/no] 𝑦 [yes/no]
(Took up offer?) (Took up offer?)
YES YES
0.95 0.98 1-0.96
0.92
1-0.58
0.54
1-0.10
0.03 1- 0.01 1-0.04
NO NO
𝑋1 [yrs] 𝑋1 [yrs]
18 60 18 60
(Age) (Age)
Likelihood =0.03 x 0.54 x 0.92 x 0.95 x 0.98 x (1– 0.01) x (1– 0.04) x (1– 0.10) x (1– 0.58) x (1– 0.96)
Likelihood =0.00019939
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Maximum Likelihood
𝑦 [yes/no]
(Took up offer?)
Likelihood =0.00007418
Likelihood =0.00012845
Likelihood =0.00019939
NO
𝑋1 [yrs]
18 60
(Age)
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Before K-NN After K-NN
X2 x2
Category 2 Category 2
Category 1 Category 1
x1 x1
STEP 2: Take the K nearest neighbors of the new data point, according to the Euclidean distance
STEP 3: Among these K neighbors, count the number of data points in each category
STEP 4: Assign the new data point to the category where you counted the most neighbors
Category 2
Category 1
x1
y2 P2(x2,y2)
y1
P1(x1,y1)
x1 x2 x
Category 1
x1
x2
Support
Vectors
x1
x2 Positive Hyperplane
Maximum Margin
Hyperplane
(Maximum Margin Classifier)
Support
Vectors
Negative Hyperplane
x1
x1
x2
x1 x1
x1
0
x1
0
x1
0
Hyperplane
Mapping Function
x2
x1
x1
Machine Learning A-Z ©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
2D Space
z 3D Space x2
Projection
x2
x1
x1
Machine Learning A-Z ©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Mapping to a Higher Dimensional Space
can be highly compute-intensive
2
𝑥→−𝑙→𝑖
𝐾 𝑥⃗, 𝑙⃗𝑖 = 𝑒− 2σ 2
x1
2
𝑥→−𝑙→𝑖
𝐾 𝑥⃗, 𝑙⃗𝑖 = 𝑒− 2σ 2
x1
2
𝑥→−𝑙→𝑖
𝐾 𝑥⃗, 𝑙⃗𝑖 = 𝑒− 2σ 2
x1
Green when:
𝐾 𝑥⃗, 𝑙⃗1 + 𝐾 𝑥⃗, 𝑙⃗2 >
Red when:
𝐾 𝑥⃗, 𝑙⃗1 + 𝐾 𝑥⃗, 𝑙⃗2 =
x1
Y Y
X X
Y Y
X X
Y Y
X X
m2 m2 m2 m2 m2 m2 m2 m2 m2 m2
CW
ata
elgko
s ry 1
Age
X1
Walks
Age
𝑃 𝑋 𝑊𝑎𝑙𝑘𝑠 ∗ 𝑃(𝑊𝑎𝑙𝑘𝑠)
𝑃 𝑊𝑎𝑙𝑘𝑠 𝑋 =
𝑃(𝑋)
#2 Marginal Likelihood
𝑃 𝑋 𝐷𝑟𝑖𝑣𝑒𝑠 ∗ 𝑃(𝐷𝑟𝑖𝑣𝑒𝑠)
𝑃 𝐷𝑟𝑖𝑣𝑒𝑠 𝑋 =
𝑃(𝑋)
#2 Marginal Likelihood
Walks
Salary
Age
𝑃 𝑋 𝑊𝑎𝑙𝑘𝑠 ∗ 𝑃(𝑊𝑎𝑙𝑘𝑠)
𝑃 𝑊𝑎𝑙𝑘𝑠 𝑋 =
𝑃(𝑋)
#2 Marginal Likelihood
Age
𝑃 𝑋 𝑊𝑎𝑙𝑘𝑠 ∗ 𝑃(𝑊𝑎𝑙𝑘𝑠)
𝑃 𝑊𝑎𝑙𝑘𝑠 𝑋 =
𝑃(𝑋)
#2 Marginal Likelihood
Age
𝑃 𝑋 𝑊𝑎𝑙𝑘𝑠 ∗ 𝑃(𝑊𝑎𝑙𝑘𝑠)
𝑃 𝑊𝑎𝑙𝑘𝑠 𝑋 =
𝑃(𝑋)
#2 Marginal Likelihood
3 ∗ 10
𝑃 𝑊𝑎𝑙𝑘𝑠 𝑋 = 10 4 30 = 0.75
30
#2 Marginal Likelihood
𝑃 𝑋 𝐷𝑟𝑖𝑣𝑒𝑠 ∗ 𝑃(𝐷𝑟𝑖𝑣𝑒𝑠)
𝑃 𝐷𝑟𝑖𝑣𝑒𝑠 𝑋 =
𝑃(𝑋)
#2 Marginal Likelihood
1 ∗ 20
𝑃 𝐷𝑟𝑖𝑣𝑒𝑠 𝑋 = 20 4 30 = 0.25
30
#2 Marginal Likelihood
Walks
Age
Walks
Age
𝑃 𝑋 𝐷𝑟𝑖𝑣𝑒𝑠 ∗ 𝑃(𝐷𝑟𝑖𝑣𝑒𝑠)
𝑃 𝐷𝑟𝑖𝑣𝑒𝑠 𝑋 =
𝑃(𝑋)
#2 Marginal Likelihood
Walks
Salary
Age
𝑃 𝑋 𝐷𝑟𝑖𝑣𝑒𝑠 ∗ 𝑃(𝐷𝑟𝑖𝑣𝑒𝑠)
𝑃 𝐷𝑟𝑖𝑣𝑒𝑠 𝑋 =
𝑃(𝑋)
#2 Marginal Likelihood
Age
𝑃 𝑋 𝐷𝑟𝑖𝑣𝑒𝑠 ∗ 𝑃(𝐷𝑟𝑖𝑣𝑒𝑠)
𝑃 𝐷𝑟𝑖𝑣𝑒𝑠 𝑋 =
𝑃(𝑋)
#2 Marginal Likelihood
Age
𝑃 𝑋 𝐷𝑟𝑖𝑣𝑒𝑠 ∗ 𝑃(𝐷𝑟𝑖𝑣𝑒𝑠)
𝑃 𝐷𝑟𝑖𝑣𝑒𝑠 𝑋 =
𝑃(𝑋)
#2 Marginal Likelihood
1 ∗ 20
𝑃 𝐷𝑟𝑖𝑣𝑒𝑠 𝑋 = 20 4 30 = 0.25
30
#2 Marginal Likelihood
Walks
Age
Age
NOTE: Same both times
𝑃 𝑋 𝑊𝑎𝑙𝑘𝑠 ∗ 𝑃(𝑊𝑎𝑙𝑘𝑠)
𝑃 𝑊𝑎𝑙𝑘𝑠 𝑋 =
𝑃(𝑋)
#2 Marginal Likelihood
𝑃 𝑋 𝐷𝑟𝑖𝑣𝑒𝑠 ∗ 𝑃(𝐷𝑟𝑖𝑣𝑒𝑠)
𝑃 𝐷𝑟𝑖𝑣𝑒𝑠 𝑋 =
𝑃(𝑋)
#2 Marginal Likelihood
x1
60
x2
x1
Split 2
50
60
x2
60 Split 3 Split 1
50 70
x1
60 Split 3 Split 1
Split 4
50 70
x1
x1
60
x2
Yes
x1
Split 2
50
60
x2
Yes
No
X2 <60
Yes
60 Split 3 Split 1
50 70
x1
Yes No
X1 <70 X1 <50
Yes No Yes No
60 Split 3 Split 1
20 Split 4
50 70
x1
Yes No
X1 <70 X1 <50
Yes No Yes No
X2 <20
Yes No
STEP 3: Choose the number Ntree of trees you want to build and repeat STEPS 1& 2
STEP 4: For a new data point, make each one of your Ntree trees predict the category to
which the data points belongs, and assign the new data point to the category that wins
the majority vote.
ŷ =1 ŷ =1
1
0.5
X
ŷ =0 ŷ =0
20 30 40 50
#2 #4
1
0.5
#1 #3
X
ŷ (Predicted DV) #2 #4
1
0.5
#1 #3
X
False Negative
(Type II Error) Fin.
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Confusion Matrix &
Accuracy Prediction
NEG POS
TRU FALS
NEG
E E
NE PO
Actual
G S
FALS TRU
POS
E E
NE PO
Type II Error Type I Error
G
(False Negatives) S (False Positives) Image source: [Link]
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Confusion Matrix &
Accuracy Prediction
NEG POS Accuracy Rate and Error Rate:
𝐶𝑜𝑟𝑟𝑒𝑐𝑡 𝑇𝑁 + 𝑇𝑃 84
𝐴𝑅 = = = = 84%
𝑇𝑜𝑡𝑎𝑙 𝑇𝑜𝑡𝑎𝑙 100
NEG 43 12
Actual
𝐼𝑛𝑐𝑜𝑟𝑟𝑒𝑐𝑡 𝐹𝑃 + 𝐹𝑁 16
𝐸𝑅 = = = = 16%
𝑇𝑜𝑡𝑎𝑙 𝑇𝑜𝑡𝑎𝑙 100
POS 4 41
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Additional Reading
Link:
[Link]
confusion-matrix-from-scikit-learn-c51d88929c79
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
ŷ (Predicted DV) Scenario 1:
0 9,700 150
y (Actual
1 50 100
DV)
0 9,850 0 Scenario 2:
y (Actual
10,000
8,000
6,000
4,000
2,000
0
0 20,000 40,000 60,000 80,000 100,000 Total Contacted
100%
80%
60%
Poor Model
40%
Random
20%
0
10%
0 20% 40% 60% 80% 100% Total Contacted
100%
80%
60%
40%
Random
20%
0
0 20% 40% 60% 80% 100% Total Contacted
100%
80%
aP
aR
60%
aR
AR = aP
40%
Random Model
20%
0
0 20% 40% 60% 80% 100% Total Contacted
100%
X%
80%
90% <X <100% Too Good
80% <X <90% Very Good
60% 70% <X <80% Good
60% <X <70% Poor
X <60% Rubbish
40%
Random Model
20%
0
50%
0 20% 40% 60% 80% 100% Total Contacted
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
What is Clustering?
Clustering – grouping
unlabelled data
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
What is
Clustering? Supervised Learning
(e.g. Regression, Classification)
Unsupervised Learning
(e.g. Clustering)
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
What is Clustering?
Spending Score Spending Score
Clustering
©SuperDataScience
K-Means
Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means Clustering
©SuperDataScience
The Elbow
Method
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
The Elbow Method
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
The Elbow Method
...
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
The Elbow Method
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Cluster 1
C1
The Elbow Method
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Cluster 2
C2
Cluster 1
The Elbow Method
C1
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
The Elbow Method
C2 Cluster 2
C1
Cluster 1
Cluster 3
C3
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
The Elbow Method
The Elbow Method
©SuperDataScience
K-Means++
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means++
Cluster 2
K-Means
Cluster 1
Cluster 3
Different results
Cluster 2
K-Means
Cluster 3
Cluster 1
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means++
K-Means++ Initialization Algorithm:
Step 2: For each of the remaining data points compute the distance (D)
to the nearest out of already selected centroids
Step 4:Repeat Steps 2 and 3 until all k centroids have been selected
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means++
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means++
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means++
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means++
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
K-Means++
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Cluster 2
Cluster 3
Cluster 1
K-Means++
©SuperDataScience
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
After HC
STEP 2: Take the two closest data points and make them one cluster That forms N-1
clusters
STEP 3: Take the two closest clusters and make them one cluster That forms N - 2
clusters
FIN
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
x
P2(x2,y2)
x2
P1(x1,y1)
x1
y2
y1
y
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Distance Between Two Clusters:
FIN
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link] [Link]
©SuperDataScience
P6
P5
P4
P3
P2
P1
P1
P3
P2
P6
P5
NOT FOR DISTRIB UTION © SUPERDATASCIENCE [Link] [Link]
©SuperDataScience
P6
P5
P4
P3
P2
P1
P1
P3
P2
P6
P5
NOT FOR DISTRIB UTION © SUPERDATASCIENCE [Link] [Link]
©SuperDataScience
P6
P5
P4
P3
P2
P1
P1
P3
P2
P6
P5
NOT FOR DISTRIB UTION © SUPERDATASCIENCE [Link] [Link]
©SuperDataScience
P6
P5
P4
P3
P2
P1
P1
P3
P2
P6
P5
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link] [Link]
©SuperDataScience
P6
P5
P4
P3
P2
P1
P1
P3
P2
P6
P5
NOT FOR DISTRIB UTION © SUPERDATASCIENCE [Link] [Link]
©SuperDataScience
P6
P5
P4
P3
P2
P1
P1
P3
P2
P6
P5
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link] [Link]
©SuperDataScience
P1
P3
P2
P6
P5
NOT FOR DISTRIB UTION © SUPERDATASCIENCE [Link] [Link]
©SuperDataScience
2 clusters
P1
P3
P2
P6
P5
NOT FOR DISTRIB UTION © SUPERDATASCIENCE [Link] [Link]
©SuperDataScience
4 clusters
P1
P3
P2
P6
P5
NOT FOR DISTRIB UTION © SUPERDATASCIENCE [Link] [Link]
©SuperDataScience
6 clusters
P1
P3
P2
P6
P5
NOT FOR DISTRIB UTION © SUPERDATASCIENCE [Link] [Link]
©SuperDataScience
Largest distance
2 clusters
P1
P3
P2
P6
P5
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIB UTION © SUPERDATASCIENCE [Link] [Link]
©SuperDataScience
Largest distance
3 clusters
P1
P3
P2
P4
P6
P5
P9
P8
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
People who bought also bought …
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
User ID Movies liked
46578 Movie1, Movie2, Movie3, Movie4
98989 Movie1, Movie2
71527 Movie1, Movie2, Movie4
78981 Movie1, Movie2
89192 Movie2, Movie4
61557 Movie1, Movie3
Movie1 Movie2
Movie1 Movie3
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Transaction ID Products purchased
46578 Burgers, French Fries, Vegetables
98989 Burgers, French Fries, Ketchup
71527 Vegetables, Fruits
78981 Pasta, Fruits, Butter, Vegetables
89192 Burgers, Pasta, French Fries
61557 Fruits, Orange Juice, Vegetables
87923 Burgers, French Fries, Ketchup, Mayo
Step 2: Take all the subsets in transactions having higher support than minimum support
Step 3: Take all the rules of these subsets having higher confidence than minimum confidence
Movie1 Movie2
Movie1 Movie3
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Transaction ID Products purchased
46578 Burgers, French Fries, Vegetables
98989 Burgers, French Fries, Ketchup
71527 Vegetables, Fruits
78981 Pasta, Fruits, Butter, Vegetables
89192 Burgers, Pasta, French Fries
61557 Fruits, Orange Juice, Vegetables
87923 Burgers, French Fries, Ketchup, Mayo
Burgers French
Fries
Potential
Rules:
Vegetables
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Market Basket Optimisation:
Movie Recommendation:
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Step 1:Set a minimum support
Step 2: Take all the subsets in transactions having higher support than minimum support
Return
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
We’ve generated our own bandit configuration
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
We’ve generated our own bandit configuration
New Round
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
We’ve generated our own bandit configuration
New Round
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
• Deterministic • Probabilistic
• Requires update at every round • Can accommodate delayed feedback
• Better empirical evidence
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Here’s what we will learn:
• Types of Natural Language Processing
• Classical vs Deep Learning Models
• End-to-end Deep Learning Models
• Bag-Of-Words
Seq2Seq
DNLP
Processing
Language
Natural
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Learning
Deep
Seq2Seq
DNLP
Processing
Language
Natural
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Some examples:
1. If / Else Rules (Chatbot)
2. Audio frequency components analysis (Speech
Recognition) NLP DL
3. Bag-of-words model (Classification)
4. CNN for text Recognition (Classification)
5. Seq2Seq (many applic ations)
Comment Pass/Fail
Great job! 1
Amazing work.
Well done.
1
Yes
1
I’m back EOS Seq2Seq
Very well written. 1
Poor effort. 0
Could have done better. 0
h0 h1 h2Try harder
h3 next time.
… h0
n g0 g1 g2
… …
Encoder Decoder
Models
DL
NLP
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... ,0]
if badminton table
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... ,0]
SOS Special
EOS Words
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Hello Kirill, Checking if you are back to Oz. Let me know if you are around …Cheers, V
Training Data:
Hey mate, have you read about Hinton’s capsule networks?
Did you like that recipe I sent you last week?
Hi Kirill, are you coming to dinner tonight?
Dear Kirill, would you like to service your car with us again?
Are you coming to Australia in December?
…
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Hello Kirill, Checking if you are back to Oz. Let me know if you are around …Cheers, V
Training Data:
[1,1,0, 0, 0, 1,0, 0, 1,1,0, 0, 0, 0, 0, 1,0, 1,0, 1,0, 0, 1,0, 0, ... ,2]
[1,1,0, 0, 0, 0, 0, 1,0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1,0, 0, 1,0, 0, ... ,0]
[1,1,0, 0, 0, 0, 0, 1,0, 0, 1,0, 0, 0, 0, 1,0, 0, 0, 1,0, 0, 0, 0, 1,... ,1]
[1,1,0, 0, 0, 0, 0, 1,0, 0, 1,0, 0, 0, 0, 1,1,0, 1,0, 0, 0, 0, 0, 0, ... ,1]
[1,1,0, 0, 0, 0, 0, 0, 1,0, 0, 0, 0, 0, 0, 1,0, 0, 1,1,0, 0, 0, 1,0, ... ,1]
…
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NLP DL
Hello Kirill, Checking if you are back to Oz. Let me know if you are around …Cheers, V
Training Data:
[1,1,0, 0, 0, 1,0, 0, 1,1,0, 0, 0, 0, 0, 1,0, 1,0, 1, 0, 0, 1,0, 0, ... ,2]
[1,1,0, 0, 0, 0, 0, 1,0, 0, 0, 0, 0, 0 ,0, 2, 0, 0, 0, 1,0, 0, 1,0, 0, ... ,0]
[1,1,0, 0, 0, 0, 0, 1,0, 0, 1,0, 0, 0, 0, 1,0, 0, 0, 1,0, 0, 0, 0, 1,... ,1]
[1,1,0, 0, 0, 0, 0, 1,0, 0, 1,0, 0, 0, 0, 1,1,0, 1,0, 0, 0, 0, 0, 0, ... ,1]
[1,1,0, 0, 0, 0, 0, 0, 1,0, 0, 0, 0, 0,0, 1,0, 0, 1,1,0, 0, 0, 1,0, ... ,1]
Imag…
e Source: [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
2017
25,600x
1980
2x
1956
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Source: [Link]
Log-scale
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Source: [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Source: Time Magazine
INPUT INPUT
INPUT INPUT
INPUT INPUT
INPUT
OUTPUT
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Geoffrey Hinton
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Image Source: [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Input value 1
Input value 2
Output value
Input value 3
Self-Organizing Maps
Unsupervised
Neuron
Dendrites
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Image Source: Wikipedia
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Node
neuron
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
neuron
Input signal m
Input signal 1
Input signal 2
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Output signal
neuron
Input signal m
Input signal 1
Input signal 2
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Input value 1 X1
Input value m Xm
Synapse
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Input value 1 X1
Input value m Xm
Synapse
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Input value 1 X1
Independent
variable 1
Input value 2
Independent
X2 neuron y Output value
variable 2
Input value m Xm
Independent
variable m
Standardize
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Additional Reading:
Efficient BackProp
Link:
[Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Input value 1 X1
Independent
variable 1
Input value 2
Independent
X2 neuron y Output value
variable 2
Can be:
• Continuous (price)
• Binary (will exit yes/no)
Input value m Xm • Categorical
Independent
variable m
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Input value 1 X1
Independent
variable 1 y1 Output value 1
Input value 2
Independent
X2 neuron y2 Output value 2
variable 2
y3 Output value p
Input value m Xm
Independent
variable m
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Input value 1 X1
Independent
variable 1
Input value 2
Independent
X2 neuron y Output value
variable 2
Input value m Xm
Independent
variable m
Same observation
Single Observation Single Observation
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Input value 1 X1
w1
w2
Input value 2 X2 neuron y Output value
wm
Input value m Xm
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Input value 1 X1
w1
Input value 2 X2 w2
?
neuron y Output value
wm
Input value m Xm
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Input value 1 X1
w1
1st step:
Input value 2 X2 w2 y Output value
wm
Input value m Xm
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Input value 1 X1
w1
2nd step:
Input value 2 X2 w2 y Output value
wm
Input value m Xm
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Input value 1 X1
w1
2nd step:
Input value 2 X2 w2 3rd step
y Output value
wm
Input value m Xm
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Input value 1 X1
w1
2nd step:
Input value 2 X2 w2 3rd step
y Output value
wm
Input value m Xm
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0
1
y
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Threshold Function
0
1
y
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Sigmoid
0
1
y
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Rectifier
0
1
y
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Hyperbolic Tangent (tanh)
-1
1
y
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Additional Reading:
Link:
[Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Input value 1 X1
w1
2nd step:
3rd step
Input value 2 X2 w2 y Output value
wm
Input value m Xm
If threshold activation function:
Output value
Input value 2 X2 y
Input value m Xm
w4
Age X4
Bedrooms X2
Age X4
Bedrooms X2
Age X4
Bedrooms X2
Age X4
Bedrooms X2
Age X4
Bedrooms X2
Age X4
Bedrooms X2
Age X4
Bedrooms X2
Age X4
Bedrooms X2
Age X4
Bedrooms X2
y Price
Age X4
Input value 2 X2 w2 y
ŷ Output value
wm
Input value m Xm
y Actual value
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
ŷ y C
Input value 1 X1
w1
C =½(ŷ- y)2
wm
Input value m Xm
y Actual value
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
ŷ y C
Input value 1 X1
w1
wm
Input value m Xm
y Actual value
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
ŷ y C
Input value 1 X1
w1
C =½(ŷ- y)2
wm
Input value m Xm
y Actual value
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
ŷ y C
Input value 1 X1
w1
C =½(ŷ- y)2
wm
Input value m Xm
y Actual value
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
ŷ y C
Input value 1 X1
w1
C =½(ŷ- y)2
wm
Input value m Xm
y Actual value
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
ŷ y C
Input value 1 X1
w1
C =½(ŷ- y)2
wm
Input value m Xm
y Actual value
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
ŷ y C
Input value 1 X1
w1
C =½(ŷ- y)2
wm
Input value m Xm
y Actual value
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
ŷ y C
Input value 1 X1
w1
C =½(ŷ- y)2
wm
Input value m Xm
y Actual value
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
X1 X1
w1 w1
X2 w2 ŷ X2 w2 ŷ
wm wm
Xm Xm
y y
X1 X1
w1 w1
C =∑ ½(ŷ- y)2
X2 w2 ŷ X2 w2 ŷ
wm wm
Xm Xm
y y
X1 X1
X2 w2 ŷ X2 w2 ŷ
wm wm
Xm
y
Xm
y
C
X1 X1
w1 w1
X2 w2 ŷ X2 w2 ŷ
Xm
wm
y
Xm
wm
y
ŷy ŷy ŷy ŷy ŷy ŷy ŷy ŷy
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Additional Reading:
CrossValidated (2015)
Link:
[Link]
functions-used-in-neural-networks-alongside-applications
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
X1 X1
w1 w1
X2 w2 ŷ X2 w2 ŷ
wm wm
Xm Xm
y y
X1 X1
w1 w1
C =∑ ½(ŷ- y)2
X2 w2 ŷ X2 w2 ŷ
wm wm
Xm Xm
y y
X1 X1
X2 w2 ŷ X2 w2 ŷ
wm wm
Xm
y
Xm
y
C
X1 X1
w1 w1
X2 w2 ŷ X2 w2 ŷ
Xm
wm
y
Xm
wm
y
ŷy ŷy ŷy ŷy ŷy ŷy ŷy ŷy
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
C =½(ŷ- y)2
Output value
Actual value
y
y
ŷ
w1
X1
Input value
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
C =½(ŷ- y)2
ŷ
Best!
C
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Area (feet2) X1
Bedrooms X2
y Price
Age X4
Bedrooms X2
y Price
25 weights
Age X4
93 PFLOPS
93 x 1015
ŷ
C
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
C =½(ŷ- y)2
ŷ
C
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
ŷ
Best!
C
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
X1 X1
w1 w1
X2 w2 ŷ X2 w2 ŷ
wm wm
Xm Xm
y y
X1 X1
w1 w1
C =∑ ½(ŷ- y)2
X2 w2 ŷ X2 w2 ŷ
wm wm
Xm Xm
y y
X1 X1
X2 w2 ŷ X2 w2 ŷ
wm wm
Xm
y
Xm
y
C
X1 X1
w1 w1
X2 w2 ŷ X2 w2 ŷ
Xm
wm
y
Xm
wm
y
ŷy ŷy ŷy ŷy ŷy ŷy ŷy ŷy
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
X1 X1
w1 w1
X2 w2 ŷ X2 w2 ŷ
wm wm
Xm Xm
y y
X1 X1
w1 w1
C =∑ ½(ŷ- y)2
X2 w2 ŷ X2 w2 ŷ
wm wm
Xm Xm
y y
X1 X1
X2 w2 ŷ X2 w2 ŷ
wm wm
Xm
y
Xm
y
C
X1 X1
w1 w1
X2 w2 ŷ X2 w2 ŷ
Xm
wm
y
Xm
wm
y
ŷy ŷy ŷy ŷy ŷy ŷy ŷy ŷy
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
w’s
w’s
w’s
w’s
w’s
w’s
w’s
w’s
Upd
Upd
Upd
Upd
Upd
Upd
Upd
Upd
Upd w’s
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Additional Reading:
Link:
[Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Additional Reading:
Link:
[Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
FoBrw
acakrp
drP
orpoapgaagta
iotn
ion
Link:
[Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
STEP 1: Randomly initialise the weights to small numbers close to 0 (but not 0).
STEP 2: Input the first observation of your dataset in the input layer, each feature in one input node.
STEP 3: Forward-Propagation: from left to right, the neurons are activated in a way that the impact of each
neuron’s activation is limited by the weights. Propagate the activations until getting the predicted result y.
STEP 4: Compare the predicted result to the actual result. Measure the generated error.
STEP 5: Back-Propagation: from right to left, the error is back-propagated. Update the weights according to
how much they are responsible for the error. The learning rate decides by how much we update the
weights.
STEP 6: Repeat Steps 1to 5 and update the weights after each observation (Reinforcement Learning). Or:
Repeat Steps 1to 5 but update the weights only after a batch of observations (Batch Learning).
STEP 7: Whe n the whole training set passed through the ANN, that makes an epoch. Redo more epochs.
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
What we will learn in this
section:
• What are Convolutional Neural Networks?
• Step 1- Convolution Operation
• Step 1(b) - ReLU Layer
• Step 2 - Pooling
• Step 3 - Flattening
• Step 4 - Full Connection
• Summary
class)
Label
CNN
Input Image
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Happy
Sad
CNN
CNN
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
B / W Image 2x2px
Pixel 1 Pixel 2
3d array Colored
Pixel 1 Pixel 2
Colored
Image
Image
Pixel 3 Pixel 4
Pixel 3 Pixel 4
Blue channel
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
STEP 1:Convolution
STEP 3: Flattening
Gradient-Based Learning
Applied to Document
Recognition
Link:
[Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Additional Reading:
Introduction to
Convolutional Neural
Networks
By Jianxin Wu (2017)
Link:
[Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0 0 0 0 0 0 0
0 1 0 0 0 1 0
0 0 1
0 0 0 0 0 0 0
0 0 0 1 0 0 0 1 0 0
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
Input Feature
Image Detector
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0
0 0 1
0 0 0 0 0 0 0
0 0 0 1 0 0 0 1 0 0
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1
0 0 1
0 0 0 0 0 0 0
0 0 0 1 0 0 0 1 0 0
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0
0 0 1
0 0 0 0 0 0 0
0 0 0 1 0 0 0 1 0 0
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0
0 0 1
0 0 0 0 0 0 0
0 0 0 1 0 0 0 1 0 0
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0
0 0 0 1 0 0 0 1 0 0
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1 0 0
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1
0 0 0 1 0 0 0 1 0 0
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1
0 0 0 1 0 0 0 1 0 0
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1
0 0 0 1 0 0 0 1 0 0
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0 1
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0 1 0
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0 1 0 1
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0 1 0 1 2
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0 1 0 1 2 1
0 1 0 0 0 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0 1 0 1 2 1
0 1 0 0 0 1 0 1
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0 1 0 1 2 1
0 1 0 0 0 1 0 1 4
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0 1 0 1 2 1
0 1 0 0 0 1 0 1 4 2
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0 1 0 1 2 1
0 1 0 0 0 1 0 1 4 2 1
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0 1 0 1 2 1
0 1 0 0 0 1 0 1 4 2 1 0
0 1 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0 1 0 1 2 1
0 1 0 0 0 1 0 1 4 2 1 0
0 1 1
0 0 1 1 1 0 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0 1 0 1 2 1
0 1 0 0 0 1 0 1 4 2 1 0
0 1 1
0 0 1 1 1 0 0 0 0
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0 1 0 1 2 1
0 1 0 0 0 1 0 1 4 2 1 0
0 1 1
0 0 1 1 1 0 0 0 0 1
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0 1 0 1 2 1
0 1 0 0 0 1 0 1 4 2 1 0
0 1 1
0 0 1 1 1 0 0 0 0 1 2
0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 0
0 0 1
0 0 0 0 0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1 0 0 1 0 1 2 1
0 1 0 0 0 1 0 1 4 2 1 0
0 1 1
0 0 1 1 1 0 0 0 0 1 2 1
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 1 0 0 0 1 0
0 0 1 1 1 0 0
0 0 0 0 0 0 0
Input Image
Convolutional
Layer
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Image Source: [Link]/en/[Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Image Source: [Link]/en/[Link]
Sharpen:
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Image Source: [Link]/en/[Link]
Blur:
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Edge Enhance:
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 1 0 0 0 1 0
0 0 1 1 1 0 0
0 0 0 0 0 0 0
Input Image
Convolutional
Layer
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Feature Maps
0 0 0 0 0 0 0
Rectifier
0 1 0 0 0 1 0 y
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 1 0 0 0 1 0
0 0 1 1 1 0 0
0 0 0 0 0 0 0 0
Input Image
Convolutional Layer
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Image Source: [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Image Source: [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Image Source: [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Additional Reading:
Understanding
Convolutional Neural
Networks with A
Mathematical Model
Link:
[Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Additional Reading:
Link:
[Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Image Source: Wikipedia
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Image Source: Wikipedia
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0
1
1
Feature Map
0
2
2
0
1
1
1
0
0
0
0
1
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0 1 0 0 0
0 1 1 1 0
Max Pooling
1 0 1 2 1
1 4 2 1 0
0 0 1 2 1
Pooled Feature
Feature Map Map
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0 1 0 0 0
0 1 1 1 0 1
Max Pooling
1 0 1 2 1
1 4 2 1 0
0 0 1 2 1
Pooled Feature
Feature Map Map
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0 1 0 0 0
0 1 1 1 0 1 1
Max Pooling
1 0 1 2 1
1 4 2 1 0
0 0 1 2 1
Pooled Feature
Feature Map Map
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0 1 0 0 0
0 1 1 1 0 1 1 0
Max Pooling
1 0 1 2 1
1 4 2 1 0
0 0 1 2 1
Pooled Feature
Feature Map Map
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0 1 0 0 0
0 1 1 1 0 1 1 0
Max Pooling
1 0 1 2 1 4
1 4 2 1 0
0 0 1 2 1
Pooled Feature
Feature Map Map
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0 1 0 0 0
0 1 1 1 0 1 1 0
Max Pooling
1 0 1 2 1 4 2
1 4 2 1 0
0 0 1 2 1
Pooled Feature
Feature Map Map
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0 1 0 0 0
0 1 1 1 0 1 1 0
Max Pooling
1 0 1 2 1 4 2 1
1 4 2 1 0
0 0 1 2 1
Pooled Feature
Feature Map Map
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0 1 0 0 0
0 1 1 1 0 1 1 0
Max Pooling
1 0 1 2 1 4 2 1
1 4 2 1 0 0
0 0 1 2 1
Pooled Feature
Feature Map Map
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0 1 0 0 0
0 1 1 1 0 1 1 0
Max Pooling
1 0 1 2 1 4 2 1
1 4 2 1 0 0 2
0 0 1 2 1
Pooled Feature
Feature Map Map
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0 1 0 0 0
0 1 1 1 0 1 1 0
Max Pooling
1 0 1 2 1 4 2 1
1 4 2 1 0 0 2 1
0 0 1 2 1
Pooled Feature
Feature Map Map
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Additional Reading:
Evaluation of Pooling
Operations in Convolutional
Architectures for Object
Recognition
Link:
[Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0 0 0 0 0 0 0
0 1 0 0 0 1 0
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 1 0 0 0 1 0 Convolution Pooling
0 0 1 1 1 0 0
0 0 0 0 0 0 0
Input Image
Convolutional Pooling Layer
Layer
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Image Source: [Link]/~aharley/vis/conv/[Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Pooled Feature
0
1
1
1
2
2
1
4
0
Map
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
1
1
0
4
2
1
0
2
1
Flattening
Pooled Feature
0
1
1
1
2
2
1
4
0
Map
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Input layer of a future ANN
Flattening
Pooling Layer
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0 0 0 0 0 0 0
0 1 0 0 0 1 0
0 0 0 0 0 0 0
0 0 0 1 0 0 0 Convolution Pooling Flattening
0 1 0 0 0 1 0
0 0 1 1 1 0 0
0 0 0 0 0 0 0
Input Image
Input
layer of
Convolutional Pooling Layer a future
Layer ANN
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
X1
Flattening
X2 Output
value
Xm
Cat
Flattening
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Dog
Cat
Flattening
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Dog
Cat
0.9
0.2
0.2
0.1
0.1
0.1
1
1
Flattening
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Dog
Cat
0.9
0.2
0.2
0.1
0.1
0.1
1
1
Flattening
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Dog
Cat
Flattening
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Dog
Cat
0.1
0.1
0.2
0.2
0.2
0.9
0.9
1
Flattening
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Dog
Cat
0.1
0.1
0.2
0.2
0.2
0.9
0.9
1
Flattening
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Dog
Cat
Flattening
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0.05
0.95
Dog
Cat
0.1
0.8
0.8
0.4
0.2
0.1
1
Flattening
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0.79
0.21
Dog
Cat
0.1
0.8
0.4
0.2
0.1
0.9
1
1
Flattening
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Image Source: a talk by Geoffrey Hinton
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Additional Reading:
Link:
[Link]
[Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
©SuperDataScience
Machine Learning A-Z
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0.05
0.95
Dog
Cat
Flattening
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0.05
0.95
z2
z1
Dog
Cat
Flattenin
g
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
1
0
Dog 0.9
0.1
Cat
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
0.4
0.6
0.9
0.7
0.3
0.1
0.4
0.1
0.1
0.9
0.9
0.6
1
1
0
Dog
Dog
Dog
Cat
Cat
Cat
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Row Dog Cat^ Dog Cat Row Dog Cat^ Dog Cat
^ ^
#1 0.9 0.1 1 0 #1 0.6 0.4 1 0
#2 0.1 0.9 0 1 #2 0.3 0.7 0 1
sification E rror
Cl
as
#3 0.1 1/0
3.9
=0.33
1 0
#3 0.4 1 0 Mean Squared Error
1/0
3.6
=0.33
0.25 0.71
Cross-Entropy
0.38 1.06
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Additional Reading:
A Friendly Introduction to
Cross-Entropy Loss
Link:
[Link]
NOT FOR DISTRIBUTION © SUPERDATASCIENCE [Link]
Additional Reading:
Link:
[Link]
_intermezzo02/