Coding academy coding academy Python 3
Machine learning: quick tips and tricks Mihalis Tsoukalos reveals his tried-and-tested approach for processing reams of data using machine-learning techniques and Python 3. hese days, machine learning (ML) is not only important as a research area of computer science, but it’s also started playing a key role in our everyday lives. As if this wasn’t enough, an exponential growth in the usage of ML is expected in the next few years. The biggest advantage of ML is that it offers new and unique ways of thinking about the problems we want to study and solve. ML is all about extracting knowledge from your data using a computer – in this case, all the examples of this tutorial are going to be written in Python 3. However, the topic is huge and can’t be covered in a single article, so the main purpose of this tutorial is to get you started with the various Python 3 libraries and their functions, learn what each library supports, and give you a good reason to explore some or all of them. So, without further ado, let’s get started with the next section, which is a quick introduction to ML.
our expert Mihalis Tsoukalos is a UNIX administrator, a programmer, a DBA and a mathematician. You can reach him at www. mtsoukalos.eu.
Machine learning in a nutshell
If you’re keen to know more about ML, read The Elements of Statistical Learning, Python Machine Learning and An Introduction to Statistical Learning with Applications in R.
88 LXF236 May 2018
ML can help you discover hidden patterns and information that would be difficult to recognise otherwise. Statistics are more or less the foundation of ML in many ways, so it would be helpful if you’re familiar with some basic statistical definitions such as mean value, median, standard deviation, percentile and outlier. The three main areas of ML are Supervised Learning, Unsupervised Learning and Reinforcement Learning. Supervised Learning is about identifying the relationships between some labelled variables. These are variables that we already know what they represent, and a target variable, and includes areas such as Classification and Regression. The techniques of Unsupervised Learning attempt to find hidden patterns in the data without knowing anything about it – including their types. Clustering is the most popular category of Unsupervised Learning. Reinforcement Learning enables you to learn the behaviour of a system based on the feedback you obtain, using techniques such as Markov decision processes and Monte Carlo methods. Now it’s time for some definitions. An Artificial Neural Network models the relationships of the input signal set
This shows the Python 3 code of classify.py that illustrates the use of the scikit-learn module and the iris data set for classification.
and the output signal set in a way that’s inspired by a brain. Put simply, an Artificial Neural Network uses interconnecting nodes to solve problems such as signal processing or pattern recognition using ML. Deep Learning is the subfield of ML that deals with very large Artificial Neural Networks. A Generalised Linear Model is a statistical method that, in simplified terms, uses linear regression models for predicting the behaviour of the data. A clustering technique attempts to group the data in sets, in such a way that objects of the same group are similar in some sense. This mainly depends on the type of data you have to process. Finally, a Classification technique – which is an example of pattern recognition – uses training data to establish some categories and then puts new observations into these categories.
Curved examples The first example of this tutorial will be relatively simple: we’ll attempt to find a mathematical function that best fits the data points of the input. This is called curve fitting and is one of the simplest kinds of ML. It’s closely related to mathematics. The Python 3 code of simple.py is the following: #!/usr/bin/env python3 import numpy as np
You can subscribe to this magazine @ www.myfavouritemagazines.co.uk