Practical Machine Learning

63
Practical Machine Learning David Jones

description

A rough outline to whet your appetite: - Get a non-mathematical beginners introduction to machine learning - See examples of where ML is being used today - Find out how to identify where ML might be useful in your app - Find out about selecting “features” for a ML problem - Prediction.io: why it’s a good solution for developers and how to use it with Ruby - See results of a recent A/B test using prediction.io on a production application.

Transcript of Practical Machine Learning

Page 1: Practical Machine Learning

Practical Machine LearningDavid Jones

Page 2: Practical Machine Learning

“Field of study that gives computers the ability to learn without being explicitly programmed”

Arthur Samuel, 1959

Page 3: Practical Machine Learning

“Write a program to make this helicopter hover”

Page 4: Practical Machine Learning

Pitch

Yaw

Roll

Page 5: Practical Machine Learning

helicopter.rb

while helicopter.flying

if helicopter.pitch < 0 helicopter.pitchBy(0.1) else helicopter.pitchBy(-0.1) end

end

Page 6: Practical Machine Learning

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

Page 7: Practical Machine Learning

helicopter.rbwhile 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

Page 8: Practical Machine Learning

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?

Page 9: Practical Machine Learning

What if the helicopter was upside down?

Page 10: Practical Machine Learning

helicopter.rbwhile 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

Page 11: Practical Machine Learning

Observe new exception case

Write code to handle exception

Page 12: Practical Machine Learning

Helicopter Flying CodebaseHelicopter Flying Codebase

Page 13: Practical Machine Learning

You will soon realise you can’t explicitly handle every

exception.

Page 14: Practical Machine Learning

“Field of study that gives computers the ability to learn without being explicitly programmed”

Arthur Samuel, 1959

Page 15: Practical Machine Learning

Autonomous RC HelicopterFlown using machine learning algorithms

Page 16: Practical Machine Learning

That was 8 years ago…How good is machine learning today?

Page 17: Practical Machine Learning
Page 18: Practical Machine Learning

Germany wins

Page 19: Practical Machine Learning

All 15 match outcomes predicted correctlyNo “luck” here.

Page 20: Practical Machine Learning

Google SearchNetflix

Face DetectionSpam Detection

Medical Diagnosis AdvertisingFraud Detection

Product Recommendations

Siri

OCR

Priority Inbox

Dictation

Autonomous Cars

Video Games

Finance

Sentiment Analysis

Page 21: Practical Machine Learning

So, how does it work?

Page 22: Practical Machine Learning

Collect Data

Train Model

Make Predictions

Page 23: Practical Machine Learning
Page 24: Practical Machine Learning

Two distinct algorithm types• Supervised algorithms

• Unsupervised algorithms

Page 25: Practical Machine Learning

Supervised

Page 26: Practical Machine Learning

Supervised Learning

Trai

ning

Dat

a

Page 27: Practical Machine Learning

estimate_sales_price.rbdef 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

priceend

Page 28: Practical Machine Learning

estimate_sales_price_ml.rbdef estimate_house_sales_price(num_of_bedrooms, sqft, neighborhood) do_some_maths(num_of_bedrooms, sqft, neighborhood)end

Page 29: Practical Machine Learning

estimate_sales_price_ml.rbdef 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.23432095end

Page 30: Practical Machine Learning

estimate_sales_price_ml.rbdef 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.0end

Page 31: Practical Machine Learning

…500

Page 32: Practical Machine Learning

Square Feet

Number of Bedrooms

Page 33: Practical Machine Learning

estimate_sales_price_ml.rbdef 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.23432095end

Page 34: Practical Machine Learning

$300,000

Page 35: Practical Machine Learning

Unsupervised

Page 36: Practical Machine Learning

“Computer, tell me what’s interesting about this data”

Trai

ning

Dat

a

Page 37: Practical Machine Learning

Machine Learning>

Explicit Programming

Page 38: Practical Machine Learning

x = sqr feety = price

Page 39: Practical Machine Learning

Selecting Features

Page 40: Practical Machine Learning

Force applied, weight, colour, wind, material, who threw it, day of week

Page 41: Practical Machine Learning

Force applied, weight, colour, wind, material, who threw it, day of week

Page 42: Practical Machine Learning

Practical Machine LearningHow do I use this as a developer?

Page 43: Practical Machine Learning

Algorithm SelectionHow do I know what algorithm to use?

Page 44: Practical Machine Learning

Algorithm ImplementationHow do I implement an algorithm? Don’t.

Page 45: Practical Machine Learning

Algorithm PerformanceLarge amounts of training data changing in

realtime

Page 46: Practical Machine Learning

HostingHow am I going to run special software

required to successfully use ML?

Page 47: Practical Machine Learning

No Data?Start logging today.

Page 48: Practical Machine Learning
Page 49: Practical Machine Learning

ML for DevelopersSo you don’t need to get a PHD in maths

Page 50: Practical Machine Learning

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

Page 51: Practical Machine Learning

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.

Page 52: Practical Machine Learning

Prediction.IO• Specialises in two use cases

• recommendations

• similarity

• more being added…

Page 53: Practical Machine Learning

Product ratingProduct viewsPurchases

Page 54: Practical Machine Learning
Page 55: Practical Machine Learning

Selecting Features

Page 56: Practical Machine Learning

Selecting Features

Page 57: Practical Machine Learning

Selecting Features

Page 58: Practical Machine Learning

Selecting Features

Ruby SDK

Page 59: Practical Machine Learning
Page 60: Practical Machine Learning

A/B Test Results• 45% longer average session

• 22% increase in conversion rate

• 37% increase in average order value

• 71% increase in revenue

Page 61: Practical Machine Learning

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

Page 62: Practical Machine Learning

More InformationStanford 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 Shophttp://info.resolvedigital.com/building-the-smart-spree-shop

Page 63: Practical Machine Learning

David Jones@d_jones

Questions?