"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
-
Upload
tech-in-asia-id -
Category
Technology
-
view
57 -
download
1
Transcript of "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
![Page 1: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/1.jpg)
Practical Machine Learning with Ruby
Tech in Asia ConferenceJakarta, 2016/11/16
![Page 2: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/2.jpg)
About Me• Iqbal Farabi• Cofounder of: • Virkea Empresa Sistema• Starqle Indonesia
• Member of ID Ruby community• Contact: [email protected]
![Page 3: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/3.jpg)
What to Expect
Basic concepts of Machine Learning
Introduction to Classification with Neural Network
Neural Network Implementation with Ruby
![Page 4: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/4.jpg)
Let’s learn together!
![Page 5: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/5.jpg)
Overview
Machine Learning
Mathematical Models• Simple Regression• Handwritten Recognition
Ruby Implementation• Simple Regression• Handwritten Recognition
![Page 6: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/6.jpg)
Machine Learning
![Page 7: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/7.jpg)
Machine LearningMotivations
![Page 8: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/8.jpg)
Data Science Full Stack
![Page 9: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/9.jpg)
Data Science Full Stack
Machine Learning
![Page 10: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/10.jpg)
SciRuby ManifestoRuby has for some time lacked libraries implementing the basic tools needed for scientific computing and data visualization.
We believe that the time for a Ruby science and visualization package has come. Sometimes when a solution of sugar and water becomes super-saturated, from it precipitates a pure, delicious, and diabetes-causing crystal of sweetness, induced by no more than the tap of a finger. So it is, we believe, with the need for numeric and visualization libraries in Ruby.
![Page 11: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/11.jpg)
Machine LearningBasic Concepts
![Page 12: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/12.jpg)
DefinitionMachine 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.
![Page 13: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/13.jpg)
Types of Learning• Supervised Learning• Unsupervised Learning• Reinforcement Learning
![Page 14: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/14.jpg)
Supervised LearningInput data is called training data and has a known label or result such as spam/not-spam or a stock price at a time.
A model is prepared through a training process where it is required to make predictions and is corrected when those predictions are wrong. The training process continues until the model achieves a desired level of accuracy on the training data.
![Page 15: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/15.jpg)
Supervised Learningx y1 22 43 64 ?
![Page 16: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/16.jpg)
Supervised LearningSize (ft) # of Bedrooms # of Floors Age of home Price ($1000)
1 2104 5 1 45 460
1 1416 3 2 40 232
1 1534 3 2 30 315
1 852 2 1 36 178
![Page 17: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/17.jpg)
Mathematical ModelsSimple Regression
![Page 18: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/18.jpg)
Regression (1)x y1 22 43 64 ?
![Page 19: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/19.jpg)
Regression (2)
![Page 20: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/20.jpg)
Regression (3)
![Page 21: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/21.jpg)
Regression (4)
![Page 22: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/22.jpg)
Regression (5)
![Page 23: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/23.jpg)
Regression (6)
![Page 24: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/24.jpg)
Regression (7)
![Page 25: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/25.jpg)
Regression (8)
![Page 26: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/26.jpg)
Regression (10)
![Page 27: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/27.jpg)
Ruby ImplementationSimple Regression
![Page 28: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/28.jpg)
Some Gems You’ll Need• iRuby - https://github.com/SciRuby/iruby• NMatrix - https://github.com/SciRuby/nmatrix• Nyaplot - https://github.com/domitry/nyaplot• Ruby GSL - https://github.com/SciRuby/rb-gsl
![Page 29: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/29.jpg)
How do We Translate this to Ruby?
![Page 30: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/30.jpg)
![Page 31: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/31.jpg)
Matrix Representation
![Page 32: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/32.jpg)
Math Matrix
![Page 33: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/33.jpg)
Math Ruby
![Page 34: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/34.jpg)
Gradient Descent
![Page 35: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/35.jpg)
Demo!source: my github repo
![Page 36: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/36.jpg)
Mathematical ModelsNeural Network
![Page 37: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/37.jpg)
Perceptron (1)
x1
x2
x3
output
![Page 38: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/38.jpg)
Perceptron (2)• x1, x2, x3 single binary inputs• add “weight” for each input: w1, w2, w3
ouput0 if ≤ threshold
1 if > threshold
![Page 39: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/39.jpg)
Perceptron Example (1)Should I go to TIA Conference?• x1 = can I take a leave in November 16th and 17th?• x2 = are my friends going to the conference?• x3 = is there any talk that interests me?
Add “weight” for each input, for instance: • w1 = 6 (means this is the most important factor in my decision) • w2 = 1 (means this is the least important factor in my decision)• w3 = 3 (means this is less important factor in my decision)
![Page 40: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/40.jpg)
Perceptron Example (2)Decide threshold• Lower threshold means that I am more likely to go to TIA Conference• Higher threshold means that I am less likely to go to TIA Conference• Example: threshold = 3
Calculate perceptron, example:• output = (0 * 6) + (1 * 1) + (1 * 3) = 4• output > threshold I go to TIA Conference!
![Page 41: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/41.jpg)
Perceptron Modified (1)
(vectorized)
![Page 42: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/42.jpg)
Perceptron Modified (2)
ouput0 if ≤ threshold
1 if > thresholdouput
0 if w . x + b ≤ 0
1 if w . x + b > 0
b = bias = -threshold
![Page 43: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/43.jpg)
Perceptron as Logic Function (1)Example: NAND Perceptron
x1 x2 Calculation Result
0 0 0*(-2) + 0*(-2) + 3 = 3 True
1 0 1*(-2) + 0*(-2) + 3 = 1 True
0 1 0*(-2) + 1*(-2) + 3 = 1 Tue
1 1 1*(-2) + 1*(-2) + 3 = -1 False
3
x1
x2
-2
-2
![Page 44: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/44.jpg)
Perceptron as Logic Function (2)Example: Bitwise Copy
-2
-2-2
-2
-2
-2
-2-2
-4
3
3
3
3
3
source: Neural Networks and Deep Learning
![Page 45: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/45.jpg)
Neural Network’s Goal• To devise learning algorithms which can automatically tune the
weights and biases of a network of artificial neurons. • This tuning happens in response to external stimuli, without direct
intervention by a programmer. • Enable the use of artificial neurons in a way which is radically different
to conventional logic gates• Learn to solve problems, sometimes where it would be extremely
difficult to directly design a conventional circuit
![Page 46: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/46.jpg)
Ruby ImplementationHandwritten Recognition
![Page 47: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/47.jpg)
Handwritten Recognition
![Page 48: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/48.jpg)
Convert Each Image to 28x28 Pixels
![Page 49: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/49.jpg)
Neural Network
![Page 50: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/50.jpg)
Ruby ImplementantionInput Layer• x1 = greyscale value of pixel at (0, 0)• …• x784 = greyscale value of pixel at (27, 27)
Output Layer: • y1 = 0, y2 = 1, y3 = 2, y4 = 3, y5 = 4, y6 = 5, y7 = 6, y8 = 7, y9 = 8, y10 = 9
Neural Network’s goal: based on training data,• Find weight• Find bias
![Page 51: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/51.jpg)
Cost Function• w = weight• b = bias• x = network input• y(x) = label for each input• a = network output
![Page 52: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/52.jpg)
Gradient Descent• Given the cost function, try to minimize cost function
![Page 53: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/53.jpg)
Gems You’ll Need• Chunky PNG (https://github.com/wvanbergen/chunky_png)• Nmatrix (https://github.com/tangledpath/ruby-fann)• Ruby FANN (https://github.com/tangledpath/ruby-fann)• Sinatra (https://github.com/sinatra/sinatra)
![Page 54: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/54.jpg)
Training Neural Network (1)
![Page 55: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/55.jpg)
Training Neural Network (3)
![Page 56: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/56.jpg)
Training Neural Network (2)
![Page 57: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/57.jpg)
Predict
![Page 58: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/58.jpg)
Demo!source: Geoff Buesing
![Page 59: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/59.jpg)
What’s Next?
![Page 60: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/60.jpg)
What’s Next?• Explore more SciRuby Libraries• Implement more learning algorithms in Ruby• Learn more Math XD• Join ID Ruby community! (http://tinyurl.com/id-ruby-slack)
![Page 61: "Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)](https://reader031.fdocuments.net/reader031/viewer/2022030306/586fd9301a28ab18428b58e5/html5/thumbnails/61.jpg)
Thank You!