11

(Marcin) #1

Thinking Pi


TUTORIAL


Transform your Raspberry Pi into a silicon brain using scikit-learn


Thinking Pi


here’s a lot of talk flying around
about super-powerful artificial
intelligence (AI) running on GPU
clusters in the cloud. This makes
AI sound like it’s just for people with
their own supercomputers and PhDs.
However, you can easily build your own learning
machines on practically any hardware you want.
In fact, one of the top machine learning libraries is
a simple Python library that can be running on your
Raspberry Pi in minutes!
AI can be a bit of a troublesome phrase, not least
because no one seems to agree on what intelligence
actually is. We’re going to focus on one aspect of
intelligence: learning. This is the ability to do actions
based on what you’ve observed in the past – or in this
case, your Raspberry Pi performing actions based on
what input it’s previously received.
Building and running machine learning on devices
like Raspberry Pis allows you to build clever machines
using whatever data you want (public or private), and
apply that to applications completely untethered from
the internet. A common example is a thermostat that
not only lets you control it with a quirky interface, but
also learns what temperature to set, based on time
of day, humidity, who is in the room, and learnt solely
from how you have set the temperature in the past.
Getting into machine learning can seem like a
huge undertaking if you have never touched it before.
Fortunately, one of the most popular machine learning
libraries is founded on the principle of being as simple
as possible to use. Scikit-learn is an open-source
comprehensive library that has implementations of the
most common machine learning algorithms, packaged

in a user-friendly API. Let’s install it in onto our
Raspberry Pi using pip, (a package installer for Python)!

pip install -U scikit-learn

Before we jump into the library, here is a little
machine learning intuition.
In the type of machine learning we are going to do
(supervised learning), our code is going to learn the
pattern that maps a set of inputs to a set of outputs.
What does this mean? If you were a botanist (plant
expert) who sees a bunch of different flowers that
you don’t know the name of, and another expert
points to a couple of unique flowers and tells you
their name, in your head you are learning a mapping
between the unique features of the flowers (e.g.
colour, shape, smell) and the name of the flower.
So, when you see another flower, you can use that
‘mapping’ to predict the name of the flower, based on
its features, without the other expert’s help. So the
flowers’ features (e.g. colour, shape, smell) are the
inputs, and the names of the flowers are the outputs.
Our machine learning algorithm will be tasked with
learning the mapping between them, so that with
just inputs (flower features), it can predict the outputs
(flower name).

SIGNAL AND NOISE
The most important skill in machine learning is in
developing a good intuition around ‘how much’ and
‘what kind’ of data you need to learn a mapping/
pattern. Imagine you have no idea about the rules of
Quidditch (maybe you don’t have to imagine), and
your task is to figure out the rules just by watching it
being played. How many matches would it take you?
How many matches go to penalty shoot-outs? If you
don’t see it, you won’t know that it’s part of the rules,
so you’ll have to see enough to see how every rule
applies to every scenario. What happens if, in some of
the matches, the referee is making wrong calls? You
will learn the wrong rules, unless you watch enough
matches where the referee is making the correct calls
to compensate.

T


Right
Scikit-learn is a
hugely powerful
library that we’ll only
just be scratching the
surface of. There are
many more features
if you dig beneath
the surface

Zack Akil


Zack is a data scientist
focusing on the big
problems, such as the
proper filming of
rugby matches.


ZackAkil

YOU’LL NEED
Raspberry Pi
Free download pdf