SlideShare a Scribd company logo
Machine Learning
Boris Nadion
boris@astrails.com
@borisnadion
@borisnadion
boris@astrails.com
astrails
http://astrails.com
awesome web and mobile apps
since 2005
Machine Learning: Make Your Ruby Code Smarter
Machine Learning: Make Your Ruby Code Smarter
Machine Learning: Make Your Ruby Code Smarter
Machine Learning: Make Your Ruby Code Smarter
Machine Learning: Make Your Ruby Code Smarter
Machine Learning: Make Your Ruby Code Smarter
terms
AI (artificial intelligence)
- the theory and development of computer systems
able to perform tasks that normally require human
intelligence, such as visual perception, speech
recognition, decision-making, and translation
between languages
ML (machine learning)
- is a type of artificial intelligence (AI) that provides
computers with the ability to learn without being
explicitly programmed. Machine learning focuses
on the development of computer programs that
can teach themselves to grow and change when
exposed to new data.
without being explicitly programmed
FF NN cost function
FF NN Cost Function
I’m kidding
cost function with regularization
2 types of ML
supervised learning
unsupervised learning
supervised
the training data is labeled,
eg. we know the correct answer
unsupervised
the training data is not labeled,
eg. we would figure out hidden correlations by ourselves
linear regression
supervised learning
(x(1)
, y(1)
), (x(2)
, y(2)
)…(x(m)
, y(m)
)
m training examples of (x(i)
, y(i)
)
x(i)
- feature
y(i)
- label
x(i)
y(i)
training set
learning algorithm
hθ(x)x(new data)
y(prediction)
training set
learning algorithm
hθ(x)x(new data)
y(prediction)
hθ(x) = hypothesis
(x, y)
y = hθ(x) = θ0 + θ1x
find θ0 and θ1
hθ(x) = θ0 + θ1x1 + θ2x2 + …+ θnxn
many features, n - number of features
size, sq.m
x1
# rooms
x2
age
x3
price
y
80 3 22 2.9M
90 4 24 3.1M
75 3 28 2.5M
110 5 20 3.3M
1 USD = 3.85 NIS
hθ(x) = θ0 + θ1x1
summate the prediction error on training set
Linear Regression Cost Function
minimize J(θ)
funding a minimum of cost function = “learning”
gradient descent
batch, stochastic, etc, or advanced optimization algorithms
to find a global (sometimes local) minimum of cost function J
𝞪 - learning rate, a parameter of gradient descent
(x(1)
, y(1)
), (x(2)
, y(2)
)…(x(m)
, y(m)
)
gradient descent
θ0, θ1, θ2, …, θn
magic
inside
hθ(x) = θ0 + θ1x1 + θ2x2 + …+ θnxn
we’re ready to predict
features scaling
0 ≤ x ≤ 1
size, sq.m
size, sq.m / 110
x1
80 0.72
90 0.81
75 0.68
110 1
mean normalization
average value of the feature is ~0
-0.5 ≤ x ≤ 0.5
size, sq.m
(size, sq.m / 110) - 0.8025
x1
80 -0.0825
90 0.075
75 -0.1226
110 0.1975
matrix manipulations
X = n x 1 vector, ϴ = n x 1 vector
hθ(x) = θ0 + θ1x1 + θ2x2 + …+ θnxn
hθ(x) = ϴT
X
GPU
Machine Learning: Make Your Ruby Code Smarter
logistic regression
supervised learning
classifier
y = 1, true
y = 0, false
hθ(x) = g(ϴT
X)
hθ(X) - estimated probability that y = 1 on input X
g(z) - logistic non-linear function
logistic function g(z)
there is a few: sigmoid, tahn, ReLUs, etc
image source: Wikipedia
(x(1)
, y(1)
), (x(2)
, y(2)
)…(x(m)
, y(m)
)
minimize the cost
function
vector θ
y = {0, 1}
training set
learning algorithm
hθ(x)x(new data)
y(prediction)
hθ(x) = g(ϴT
X) y ≥ 0.5 - true
y < 0.5 - false
one-vs-all
supervised learning
Machine Learning: Make Your Ruby Code Smarter
y = 1, true
y = 0, false
y = 0, false
don’t implement it at home
use libsvm, liblinear, and others
neural networks
supervised learning
neuron
a0
a1
a2
computation hθ(a)
feed forward neural network
input layer
hidden layer
output layer
estimates
size, sq.m
# rooms
age
e0
e1
e2
e3
estimates
final
estimate
multiclass classifiers
logistic unit
x0
x1
x2
θ1
θ2
θ3 hθ = g(x0θ0 + x1θ1 + x2θ2)
θ - weights
g - activation function
logistic function g(z)
there is a few: sigmoid, tahn, ReLUs, etc
image source: Wikipedia
output: probabilities
0.4765 that y = 2
0.7123 that y = 1
net with no hidden layers
no hidden layers = one-vs-all logistic regression
cost function
sometimes called loss function of NN,
a representation of an error between
a real and a predicted value
training set
learning algorithm
θx(new data)
y(prediction)
backprop
backward propagation of errors
gradient descent + backprop
“deep learning” - is training a neural net
“deep” - because we have many layers
convolutional neural nets
widely used for image processing and object recognition
recurrent neural nets
widely used for natural language processing
CPU/GPU expensive
image source: https://xkcd.com/303/
image source: http://www.falsepositives.com/index.php/2008/01/31/the-real-reason-for-no-increased-productivity-behind-scripting-languages-reveled/
2008
2016
destination suggestion
tangledpath/ruby-fann
Ruby library for interfacing with FANN
(Fast Artificial Neural Network)
require './neural_network'
LOCATIONS = [:home, :work, :tennis, :parents]
LOCATIONS_INDEXED = LOCATIONS.map.with_index { |x, i| [x, i] }.to_h
XX = [
# week 1
# 1st day of week, 8am
[:work, 1, 8], [:tennis, 1, 17], [:home, 1, 20],
[:work, 2, 8], [:home, 2, 18],
[:work, 3, 8], [:tennis, 3, 17], [:home, 3, 20],
[:work, 4, 8], [:home, 4, 18],
[:work, 5, 8], [:home, 5, 18],
[:parents, 7, 13], [:home, 7, 18],
# week 2
[:work, 1, 8], [:home, 1, 18],
[:work, 2, 8], [:home, 2, 18],
[:work, 3, 8], [:tennis, 3, 17], [:home, 3, 20],
[:work, 4, 8], [:home, 4, 18],
[:work, 5, 8], [:home, 5, 18],
XX.each do |destination, day, time|
yy << LOCATIONS_INDEXED[destination]
xx << [day.to_f/7, time.to_f/24]
end
features scaling
2 ➞ 25 ➞ 4
one hidden layer with 25 units
100% accuracy
on training set
[
[1, 16.5], [1, 17], [1, 17.5], [1, 17.8],
[2, 17], [2, 18.1],
[4, 18],
[6, 23],
[7, 13],
].each do |day, time|
res = nn.predict_with_probabilities([
[day.to_f/7, time.to_f/24]
]).first.
select {|v| v[0] > 0} # filter zero probabilities
puts "#{day} #{time} t #{res.map {|v| [LOCATIONS[v[1]], v[0]]}.inspect}"
end
1 16.5 [[:tennis , 0.97]]
1 17 [[:tennis , 0.86], [:home , 0.06]]
1 17.5 [[:home , 0.52], [:tennis, 0.49]]
1 17.8 [[:home , 0.82], [:tennis, 0.22]]
2 17 [[:tennis , 0.85], [:home , 0.06]]
2 18.1 [[:home , 0.95], [:tennis, 0.07]]
4 18 [[:home , 0.96], [:tennis, 0.08]]
6 23 [[:home , 1.00]]
[:work, 1, 8], [:tennis, 1, 17], [:home, 1, 20],
[:work, 2, 8], [:home, 2, 18],
[:work, 3, 8], [:tennis, 3, 17], [:home, 3, 20],
[:work, 4, 8], [:home, 4, 18],
[:work, 5, 8], [:home, 5, 18],
[:parents, 7, 13], [:home, 7, 18],
# week 2
[:work, 1, 8], [:home, 1, 18],
[:work, 2, 8], [:home, 2, 18],
[:work, 3, 8], [:tennis, 3, 17], [:home, 3, 20],
[:work, 4, 8], [:home, 4, 18],
[:work, 5, 8], [:home, 5, 18],
borisnadion/suggested-destination-demo
ruby code of the demo
tensorflow
but you will need to learn Python
clustering
unsupervised learning
{X(i)
}
no labels
Machine Learning: Make Your Ruby Code Smarter
anomaly detection
unsupervised learning
Machine Learning: Make Your Ruby Code Smarter
collaborative filtering
unsupervised learning
Jane Arthur John
Star Wars VII 5 5 1
Dr. Strange 5 5 ?
Arrival 5 ? 1
automatic features
and their weights detection
based on the user votes
similarity between users
and between items
what to google
http://astrails.com
thanks!
Boris Nadion
http://astrails.com

More Related Content

PDF
PPTX
Explanation on Tensorflow example -Deep mnist for expert
DOC
Simple Matlab tutorial using matlab inbuilt commands
PDF
Graph convolutional networks in apache spark
PDF
Gentlest Introduction to Tensorflow - Part 3
PDF
Gentlest Introduction to Tensorflow
PPS
A Tutorial On Ip 1
PDF
Image Restoration (Digital Image Processing)
Explanation on Tensorflow example -Deep mnist for expert
Simple Matlab tutorial using matlab inbuilt commands
Graph convolutional networks in apache spark
Gentlest Introduction to Tensorflow - Part 3
Gentlest Introduction to Tensorflow
A Tutorial On Ip 1
Image Restoration (Digital Image Processing)

What's hot (17)

PPTX
Variational Autoencoder Tutorial
PDF
Generative modeling with Convolutional Neural Networks
PDF
PPT
Dip Morphological
PDF
Neural networks - BigSkyDevCon
PDF
Learning Deep Learning
PDF
Eight Regression Algorithms
PDF
Ensembles of Many Diverse Weak Defenses can be Strong: Defending Deep Neural ...
PDF
present_merged
PDF
MUMS Opening Workshop - An Overview of Reduced-Order Models and Emulators (ED...
PPTX
Deep Residual Hashing Neural Network for Image Retrieval
PDF
Blur Filter - Hanpo
PDF
Sparse autoencoder
PDF
Conditional neural processes
PPTX
Gaussian Image Blurring in CUDA C++
PDF
Output Units and Cost Function in FNN
PPTX
Sliced Wasserstein距離と生成モデル
Variational Autoencoder Tutorial
Generative modeling with Convolutional Neural Networks
Dip Morphological
Neural networks - BigSkyDevCon
Learning Deep Learning
Eight Regression Algorithms
Ensembles of Many Diverse Weak Defenses can be Strong: Defending Deep Neural ...
present_merged
MUMS Opening Workshop - An Overview of Reduced-Order Models and Emulators (ED...
Deep Residual Hashing Neural Network for Image Retrieval
Blur Filter - Hanpo
Sparse autoencoder
Conditional neural processes
Gaussian Image Blurring in CUDA C++
Output Units and Cost Function in FNN
Sliced Wasserstein距離と生成モデル
Ad

Viewers also liked (17)

PPT
algorithm
PPTX
Algorithm - Introduction
PPT
N5 Computing Science - Machine Code
PPT
Introduction To Algorithm [2]
PPTX
visual basic 6.0
PPT
Machine language
PPTX
Visual basic 6.0
PPTX
Visual basic 6
PDF
Algorithm and Programming (Introduction of Algorithms)
PPTX
Assembly and Machine Code
PPT
Visual Basic 6.0
PDF
Visual Basic 6.0
PPTX
Presentation on visual basic 6 (vb6)
PPT
Introduction to visual basic programming
PPTX
Computer Languages.
PPT
Visual basic ppt for tutorials computer
algorithm
Algorithm - Introduction
N5 Computing Science - Machine Code
Introduction To Algorithm [2]
visual basic 6.0
Machine language
Visual basic 6.0
Visual basic 6
Algorithm and Programming (Introduction of Algorithms)
Assembly and Machine Code
Visual Basic 6.0
Visual Basic 6.0
Presentation on visual basic 6 (vb6)
Introduction to visual basic programming
Computer Languages.
Visual basic ppt for tutorials computer
Ad

Similar to Machine Learning: Make Your Ruby Code Smarter (20)

PPTX
Introduction to Neural Netwoks
PDF
EssentialsOfMachineLearning.pdf
PDF
Capstone paper
PPTX
Neural Networks - How do they work?
PDF
Neural Nets Deconstructed
PDF
AIML2 DNN 3.5hr (111-1).pdf
PDF
Integrating Artificial Intelligence with IoT
PPTX
Nimrita deep learning
PPTX
Deep Learning
PDF
4. NN.pdf……………………………………………………………………………….
PDF
Artificial Neural Network for machine learning
PDF
super-cheatsheet-artificial-intelligence.pdf
PPTX
Machine learning ppt unit one syllabuspptx
PDF
Deep learning
PDF
Survey on Artificial Neural Network Learning Technique Algorithms
PPTX
Deep learning from scratch
PPTX
lecture15-neural-nets (2).pptx
PPT
tutorial.ppt
PDF
Lesson_8_DeepLearning.pdf
PPTX
Introduction to Machine Learning basics.pptx
Introduction to Neural Netwoks
EssentialsOfMachineLearning.pdf
Capstone paper
Neural Networks - How do they work?
Neural Nets Deconstructed
AIML2 DNN 3.5hr (111-1).pdf
Integrating Artificial Intelligence with IoT
Nimrita deep learning
Deep Learning
4. NN.pdf……………………………………………………………………………….
Artificial Neural Network for machine learning
super-cheatsheet-artificial-intelligence.pdf
Machine learning ppt unit one syllabuspptx
Deep learning
Survey on Artificial Neural Network Learning Technique Algorithms
Deep learning from scratch
lecture15-neural-nets (2).pptx
tutorial.ppt
Lesson_8_DeepLearning.pdf
Introduction to Machine Learning basics.pptx

More from Astrails (12)

PDF
Building and deploying React applications
PDF
Accounting For Hackers
PDF
Migrating from Flux to Redux. Why and how.
PDF
Engineering esthetics
PDF
Lean Software Development
PDF
RubyMotion: Put your Dreams in Motion with Ruby
PDF
WTF is NoSQL
PDF
Cassandra intro
PDF
Ruby is an Acceptable Lisp
PDF
Ruby is Awesome
PDF
Rails missing features
PDF
Performance - When, What and How
Building and deploying React applications
Accounting For Hackers
Migrating from Flux to Redux. Why and how.
Engineering esthetics
Lean Software Development
RubyMotion: Put your Dreams in Motion with Ruby
WTF is NoSQL
Cassandra intro
Ruby is an Acceptable Lisp
Ruby is Awesome
Rails missing features
Performance - When, What and How

Recently uploaded (20)

PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation theory and applications.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
sap open course for s4hana steps from ECC to s4
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Dropbox Q2 2025 Financial Results & Investor Presentation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Electronic commerce courselecture one. Pdf
Encapsulation theory and applications.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
sap open course for s4hana steps from ECC to s4
NewMind AI Weekly Chronicles - August'25 Week I
Encapsulation_ Review paper, used for researhc scholars
Programs and apps: productivity, graphics, security and other tools
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Advanced methodologies resolving dimensionality complications for autism neur...
MYSQL Presentation for SQL database connectivity
Per capita expenditure prediction using model stacking based on satellite ima...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
cuic standard and advanced reporting.pdf
MIND Revenue Release Quarter 2 2025 Press Release

Machine Learning: Make Your Ruby Code Smarter