THE
PYTHON BIBLE
VOLUME FOUR
Machine Learning
By
Florian Dedov
Copyright 2019
Copyright 2019 Florian Dedov
Florian Dedov, Vienna
1st Edition
ASIN E-Book: B07VZW6KC6
ISBN-10 Paperback: 1086956761
ISBN-13 Paperback: 978-1086956764
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
TABLE OF CONTENT
Introduction
With this book, we get into some really advanced territory and things get more and more complicated. In the last book, we were learning about data science and data analysis. We now know how to analyze and visualize big data sets. But except for some statistical values we didnt really extract any knowledge out of the data and we were certainly not able to predict future data.
This is where the topic of this book comes into play machine learning . Its a much hyped term and nowadays it can be found almost everywhere. In robots, video games, the stock market, home appliances or even in cars. And its constantly growing. The development of artificial intelligences cant be stopped and it bears almost unlimited potential (for both good and evil). The people who dont educate themselves on this matter will be overrun by the development instead of benefiting from it.
Python is definitely the language that dominates the AI market. Of course, artificial intelligences are developed in all sorts of languages but Python has become the lingua franca of machine learning in the past few years. Therefore, if you want to be part of this future, you will need to be fluent in Python and get a good understanding of machine learning.
This Book
In this volume of The Python Bible series, we will dig deep into the machine learning realm and the Python language. We will train and apply complex machine learning models and at the end you will be able to develop and optimize your own AI suited for your specific tasks.
What you will need for this book is the knowledge from the previous three volumes. You will need to be fluent in the basic and intermediate concepts of the Python language. Also, you will need some basic understanding of data science and the libraries NumPy, Pandas and Matplotlib . If you have already read volume one to three, you are good to go. A decent understanding of mathematics (high school level) is definitely beneficial.
We will start by discussing what machine learning actually is and what types there are. Then, we will install the necessary modules and start with the programming part. First, we will look at linear regression, which is a pretty basic statistical machine learning model. After that, we will cover classification, clustering and support vector machines. Then, we will discuss neural networks and build a model that predicts handwritten digits. At the end, we will take a look at the optimization of models.
This book is again full of new and more complex information. There is a lot to learn here so stay tuned and code along while reading. This will help you to understand the material better and to practice implementing it. I wish you a lot of fun and success with your journey and this book!
Just one little thing before we start. This book was written for you, so that you can get as much value as possible and learn to code effectively. If you find this book valuable or you think you have learned something new, please write a quick review on Amazon. It is completely free and takes about one minute. But it helps me produce more high quality books, which you can benefit from.
Thank you!
If you are interested in free educational content about programming and machine learning, check out: https://www.neuralnine.com/
1 What is Machine Learning?
As always, before we start to learn how something works, we first want to precisely define what it is, that we are learning about. So what is this hyped concept of machine learning ? I will not try to give you some sophisticated and complex scientific definition here. We will try to explain it as simply as possible.
What machine learning is fundamentally is just the science, in which we focus on teaching machines or computers to perform certain tasks without being given specific instructions. We want our machines to learn how to do something themselves without explaining it to them.
In order to do this, we oftentimes look at how the human brain works and try to design virtual brains that work in a similar manner.
Notice that machine learning and artificial intelligence are not the same. Artificial intelligence is a broad field and every system that can learn and solve problems might be considered an AI. Machine learning is one specific approach to this broad field. In machine learning the AI doesnt receive any instructions. It isnt static and it doesnt follow clear and strict steps to solve problems. Its dynamic and restructures itself.
Supervised Learning
In machine learning we have different approaches or types. The two main approaches are supervised learning and unsupervised learning . So lets first talk about supervised learning.
Here, we give our model a set of inputs and also the corresponding outputs, which are the desired results. In this way, the model learns to match certain inputs to certain outputs and it adjusts its structure. It learns to make connections between what was put in and what the desired output is. It understands the correlation. When trained well enough, we can use the model to make predictions for inputs that we dont know the results for.
Classic supervised learning algorithms are regressions, classifications and support vector machines.
Unsupervised Learning
With unsupervised learning on the other hand, we dont give our model the desired results while training. Not because we dont want to but because we dont know them. This approach is more like a kind of pattern recognition. We give our model a set of input data and it then has to look for patterns in it. Once the model is trained, we can put in new data and our model will need to make decisions.
Since the model doesnt get any information about classes or results, it has to work with similarities and patterns in the data and categorize or cluster it by itself.
Classic unsupervised learning algorithms are clustering, anomaly detection and some applications of neural networks.
Reinforcement Learning
Then there is a third type of machine learning called reinforcement learning . Here we create some model with a random structure. Then we just observe what it does and reinforce or encourage it, when we like what it does. Otherwise, we can also give some negative feedback. The more our model does what we want it to do, the more we reinforce it and the more rewards it gets. This might happen in form of a number or a grade, which represents the so-called fitness of the model.
In this way, our model learns what is right and what is wrong. You can imagine it a little bit like natural selection and survival of the fittest. We can create 100 random models and kill the 50 models that perform worst. Then the remaining 50 reproduce and the same process repeats. These kinds of algorithms are called genetic algorithms.
Classic reinforcement learning algorithms are genetic or evolutional algorithms.
Deep Learning