Practical Machine Learning in Ruby

Feature thumb webapps banner 1920x1080

This guide contains the talking points and code for my talk for the RubyDevSummit titled, Machine Learning on Rails.

What is Machine Learning?

TechTarget Definition

“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.”

Dead simple definition:

The data determines the output.

Right tool for the right job

Shallow vs deep learning Shallow: naive bayes, decision trees - straightforward implementation in a Rails app Deep: Neural networks - Tensorflow traditional framework

Practical Applications of Machine Learning

Recommendation engine Custom route actions Version control Markdown syntax Sport specific scouting. Marketing analysis. Analyzing when a vehicle may need to be removed from a fleet based on historical trends. Checking to see if an email is spam. Verifying bank transactions. Verifying medical diagnosis. Google search engine Etc, etc, etc

Why Ruby Isn’t Typically Used for Machine Learning

Misconceived notions about speed Lack of libraries Ease of passing responsibilities to other services Assumption that all machine learning is deep learning

Popular Algorithms

Decision Tree Naive Bayes K Means Clustering Algorithm Support Vector Machine Algorithm Apriori Algorithm Linear Regression Logistic Regression Artificial Neural Networks Random Forests Nearest Neighbours

Supervised vs Unsupervised Learning

Supervised – Teaching a child that an electrical outlet is dangerous, and the child learns not to touch other electrical hazards. Unsupervised – A child learns what’s dangerous by trial and error, eventually learning not to touch electrical hazards.

Ruby Machine Learning Examples

Continuous vs Discrete

Continuous – Items that can be measured, e.g. height, weight, product reviews. Discrete – Items that have a set number of options: gender, or dice roll.

Decision Tree Example

Naive Bayes Example

Rails + Machine Learning

Machine learning process for Recommendation Engine

Content crawler / cleaning - Ruby excels at both tasks Tokenization + Graph Rank Probability analysis Save learning object to yml for persistence Run Naive Bayes through knowledge base

Implementation Tools for Recommendation Engine

Rails Microservice API App Sidekiq + Redis + ActiveJob Naive Bayes Graph rank

Notable Element of Recommendation Engine API

Service object <> Background jobs Stop Words for Graph Rank

Instructions for Testing Locally