Practical Machine Learning 
David Jones
“Field of study that gives computers the ability to 
learn without being explicitly programmed” 
Arthur Samuel, 1959
“Write a program to make this helicopter hover”
Pitch 
Yaw 
Roll
helicopter.rb 
while helicopter.flying 
if helicopter.pitch < 0 
helicopter.pitchBy(0.1) 
else 
helicopter.pitchBy(-0.1) 
end 
end
helicopter.rb 
while helicopter.flying 
if helicopter.pitch < 0 
helicopter.pitchBy(0.1) 
else 
helicopter.pitchBy(-0.1) 
end 
if helicopter.yaw < 0 
helicopter.yawBy(0.1) 
else 
helicopter.yawBy(-0.1) 
end 
end
helicopter.rb 
while helicopter.flying 
if helicopter.pitch < 0 
helicopter.pitchBy(0.1) 
else 
helicopter.pitchBy(-0.1) 
end 
if helicopter.yaw < 0 
helicopter.yawBy(0.1) 
else 
helicopter.yawBy(-0.1) 
end 
if helicopter.roll < 0 
helicopter.rollBy(0.1) 
else 
helicopter.rollBy(-0.1) 
end 
end
OK, but what if… 
• it’s about to hit a tree? 
• one of the main rotor blades is broken? 
• power is running low? 
• there is wind?
What if the helicopter was upside down?
helicopter.rb 
while helicopter.flying 
if helicopter.pitch < 0 
helicopter.pitchBy(0.1) 
else 
helicopter.pitchBy(-0.1) 
end 
if helicopter.yaw < 0 
helicopter.yawBy(0.1) 
else 
helicopter.yawBy(-0.1) 
end 
if helicopter.roll < 0 
helicopter.rollBy(0.1) 
else 
helicopter.rollBy(-0.1) 
end 
end 
Fail
Observe new 
exception case 
Write code to handle 
exception
Helicopter Flying Codebase 
Helicopter Flying Codebase
You will soon realise you can’t 
explicitly handle every 
exception.
“Field of study that gives computers the ability to 
learn without being explicitly programmed” 
Arthur Samuel, 1959
Autonomous RC Helicopter 
Flown using machine learning algorithms
That was 8 years ago… 
How good is machine learning today?
Germany wins
All 15 match outcomes predicted correctly 
No “luck” here.
Google Search 
Netflix 
Sentiment Analysis 
Autonomous Cars 
Spam Detection 
Face Detection 
Siri 
Priority Inbox 
Medical Diagnosis Advertising 
Fraud Detection 
Product Recommendations 
OCR 
Dictation 
Video Games 
Finance
So, how does it work?
Collect Data 
Train Model 
Make Predictions
Two distinct algorithm types 
• Supervised algorithms 
• Unsupervised algorithms
Supervised
Supervised Learning 
Training Data
estimate_sales_price.rb 
def estimate_house_sales_price(num_of_bedrooms, sqft, neighborhood) 
price = 0 
# In my area, the average house costs $200 per sqft 
price_per_sqft = 200 
if neighborhood == "hipsterton": 
# but some areas cost a bit more 
price_per_sqft = 400 
elsif neighborhood == "skid row": 
# and some areas cost less 
price_per_sqft = 100 
end 
# start with a base price estimate based on how big the place is 
price = price_per_sqft * sqft 
# now adjust our estimate based on the number of bedrooms 
if num_of_bedrooms == 0 
# Studio apartments are cheap 
price = price - 20000 
else 
# places with more bedrooms are usually 
# more valuable 
price = price + (num_of_bedrooms * 1000) 
end 
price 
end
estimate_sales_price_ml.rb 
def estimate_house_sales_price(num_of_bedrooms, sqft, neighborhood) 
do_some_maths(num_of_bedrooms, sqft, neighborhood) 
end
estimate_sales_price_ml.rb 
def estimate_house_sales_price(num_of_bedrooms, sqft, neighborhood) 
price = 0 
# a little pinch of this 
price += num_of_bedrooms * .841231951398213 
# and a big pinch of that 
price += sqft * 1231.1231231 
# maybe a handful of this 
price += neighborhood * 2.3242341421 
# and finally, just a little extra salt for good measure 
price += 201.23432095 
end
estimate_sales_price_ml.rb 
def estimate_house_sales_price(num_of_bedrooms, sqft, neighborhood) 
price = 0 
# a little pinch of this 
price += num_of_bedrooms * 1.0 
# and a big pinch of that 
price += sqft * 1.0 
# maybe a handful of this 
price += neighborhood * 1.0 
# and finally, just a little extra salt for good measure 
price += 1.0 
end
…500
Square Feet 
Number of Bedrooms
estimate_sales_price_ml.rb 
def estimate_house_sales_price(num_of_bedrooms, sqft, neighborhood) 
price = 0 
# a little pinch of this 
price += num_of_bedrooms * .841231951398213 
# and a big pinch of that 
price += sqft * 1231.1231231 
# maybe a handful of this 
price += neighborhood * 2.3242341421 
# and finally, just a little extra salt for good measure 
price += 201.23432095 
end
$300,000
Unsupervised
“Computer, tell me what’s interesting about this 
data” 
Training Data
Machine Learning 
> 
Explicit Programming
x = sqr feet 
y = price
Selecting Features
Force applied, weight, colour, wind, 
material, who threw it, day of week
Force applied, weight, colour, wind, 
material, who threw it, day of week
Practical Machine Learning 
How do I use this as a developer?
Algorithm Selection 
How do I know what algorithm to use?
Algorithm Implementation 
How do I implement an algorithm? Don’t.
Algorithm Performance 
Large amounts of training data changing in 
realtime
Hosting 
How am I going to run special software 
required to successfully use ML?
No Data? 
Start logging today.
ML for Developers 
So you don’t need to get a PHD in maths
Prediction.IO 
• Open Source 
• Deploy on your own servers or instantly on 
Amazon’s Cloud 
• Cheap to run 
• Developer friendly API 
• Easy to use admin UI
Prediction.IO 
• Ignore the maths 
• Helps you find the best algorithm for your problem 
• Easily hosted and performant 
• Uses scalable services such as MapReduce 
and Hadoop. 
• You don’t need to know how to work this stuff 
though.
Prediction.IO 
• Specialises in two use cases 
• recommendations 
• similarity 
• more being added…
Product rating 
Product views 
Purchases
Selecting Features
Selecting Features
Selecting Features
Ruby SDK 
Selecting Features
A/B Test Results 
• 45% longer average session 
• 22% increase in conversion rate 
• 37% increase in average order value 
• 71% increase in revenue
Machine Learning 
• Extremely powerful at solving complex 
problems 
• Increasingly important for developers to 
know about it 
• Don’t need to know the maths to get the 
benefit
More Information 
Stanford Machine Learning 
https://www.coursera.org/course/ml 
Bootstrapping Machine Learning 
http://www.louisdorard.com/machine-learning-book/ 
Machine Learning is Fun 
https://medium.com/@ageitgey/machine-learning-is-fun- 
80ea3ec3c471 
Building The Smart Shop 
http://info.resolvedigital.com/building-the-smart-spree-shop
David Jones 
@d_jones 
Questions?

Practical Machine Learning