Barbarian Meets Coding
barbarianmeetscoding

WebDev, UX & a Pinch of Fantasy

7 minutes readbook-notesdraft

AI and Machine Learning for Coders

AI and Machine Learning for Coders is a book by Laurence Moroney about how to get started doing practical AI and Machine learning from creating and training machine learning models to deploying them and using them in real world applications. What follows are my notes as I learn about ML from the book and other sources, synthesize the most important ideas and mental models, and practice with exercises.

What is Machine Learning?

Machine Learning is a field within Artificial Intelligence that focuses on understanding and building methods that learn and can use that learning to perform tasks (like been able to label images, recommend your favorite songs, write an article, draw a piece of art or compose some music). By learn we mean that a machine learning program can process lots of data and build a model of understanding from that data so that we can then use that knowledge to perform useful tasks. This concept is easier to grasp with an example and in contrast to traditional programming.

In traditional programming (or ruled based programming) we write a program that encodes a set of rules to perform a task, for instance, we might write a program for an activity tracker that based on your speed records whether you’re walking or jogging:

function labelActivity(speed:number) {
  if (speed < 5) return 'walking'
  if (speed < 10) return 'jogging'
  if (speed < 20) return 'running'
  // etc...
}

In this context provided some input (speed) and some business logic (written by ourselves as programming rules) we get some desired output (whether the person is walking, running or cycling).

In traditional programming, given an input and rules we get a result:

                  ------------
input ------>     |   rules  |   ------> output ???
                  ------------

In machine learning, instead of us providing the rules, we provide the machine learning algorithm with lots of data that it can use to derive the rules of the system itself. Once it learns these rules, in the form of a Machine Learning model, it can make predictions about new data. In the case of a motion tracker one could provide the machine learning algorithm with a training set of sensor data labelled as belonging to different activities (what we call supervised learning).

In machine learning, given lots of inputs and outputs (a training set) we
derive the rules of the system (as an ML model) which we can then apply to
novel inputs.


Phase 1) Training: learn the rules of the system
                               ---------------
training set input ------>     |   rules???  |   ------> training set output
                               ---------------


Phase 2) Inference: apply the learned rules to make decisions

                        --------------------
novel input ------>     |   learned rules  |   ------> output ???
                        --------------------

Given the above, Machine learning is specially useful at solving problems that are too complex to reduce to a set of rules that could be programmed by a human.

Supervised learning?

In the example above we discussed an approach to Machine Learning called supervised learning (where the data provided to the machine learning algorithm contains a set of desired outputs for a given set of inputs). There are more types of machine learning approaches which are useful in different scenarios.

Getting Started

A great way to get started with ML is using Google Colab notebooks which allow you to create and train ML models without having to install anything and from the comfort of a web browser. When you go to colab.research.google.com you’ll be welcomed by a introduction to Colab in the form of a notebook that explains what Colab is and how to use it. If you have 3 minutes this is a great intro:

Here are links with colab notebooks that describe exercises within the book, highlight the most important concepts and are heavily commented:

Concepts

This is a collection on concepts that will help you build a mental model and foundation to learning Machine learning.

  • Machine Learning: Field of machine learning that focuses on making programs that can learn by themselves from looking at data and use that knowledge to perform useful tasks (like labeling images, making recommendations, writing articles, composing music or art).
  • Supervised learning: Approach to machine learning where we provide the machine learning algorithm with a training set that provides a series of example inputs and their desired outputs. The goal of this learning approach is to derive a general rule that maps inputs to outputs.
  • Unsupervised learning: Approach to machine learning where we provide the machine learning algorithm with unlabelled data. The learning algorithm must find its own structure in the data provided (like grouping or clustering).
  • Reinforced learning: Approach to machine learning where a program interacts with a dynamic environment to perform a given goal. As the program navigates through this dynamic problem space it is provided feedback in the form of rewards that guide its training.
  • Training a model: In machine learning the first step in creating a program to solve a given problem consists in training a model. Training a model consists in exposing a machine learning algorithm to lots of data so that it can learn from that data and derive a view of the world it can use to solve that problem.
  • Inference: In machine learning, the second step in creating a program to solve a given problem is to use a trained ML model to infer or make predictions when provided with novel data to produce actionable results.
  • Overfitting: In the context of training a ML model, overfitting occurs when the trained model models the trained data too closely and as a result it can provide very accurate results for the trained data but not for novel data.

Resources


Jaime González García

Written by Jaime González García , dad, husband, software engineer, ux designer, amateur pixel artist, tinkerer and master of the arcane arts. You can also find him on Twitter jabbering about random stuff.Jaime González García