This article is part of our series on “AI education”
Machine learning and deep learning are moving at such a fast pace that it is sometimes hard keeping up with just the names of new algorithms and architectures, let alone learn them. Take transformers, for instance. Four years ago, they were still an emerging field of research. Today, they are the primary type of neural network used in large language models and have replaced RNNs and even CNNs in many applications.
Generative models such as GANs and VAEs have undergone a similar trend. And in the past year, diffusion and CLIP neural networks have shown much promise.
With so much happening and changing in the field, writing an introductory book on machine learning and deep learning has become a real challenge. Yet Sebastian Raschka, Yuxi Liu, and Vahid Mirjalili have managed to pull a very difficult feat in their latest book, Machine Learning with PyTorch and Scikit-Learn.
The book, which is the PyTorch edition of the acclaimed Python Machine Learning, provides a balanced mix of theory, math, coding, and references to give you a broad overview of the ML and DL landscape and help you trace a roadmap for your future career in artificial intelligence.
A great intro to machine learning with Python
Writing a self-study book on machine learning with Python poses a dual challenge. On the one hand, machine learning—and especially deep learning—involves complex mathematical and computational concepts that can be daunting without the help of an instructor. Therefore, filling out pages with complex formulas like college textbooks will make it difficult and boring for many readers who are trying to learn machine learning on their own.
On the other hand, there are many Python libraries that make it easy to create and train machine learning code with a shallow understanding of the underlying mathematics and computation. But without understanding the math and logic behind the algorithms, your machine learning coding skills will have limited use when it comes to writing real applications and making important decisions.
Fortunately, the authors of Machine Learning with PyTorch and Scikit-Learn have managed to strike the right balance of theory and practice. The authors teach many important machine learning concepts by providing an overview of the logic, gradually introducing the formulas and explaining them step by step, and showing how to implement them in Python.
Throughout the chapters, you build your knowledge of different machine learning algorithms, activation functions, loss functions, optimizers, hyperparameter optimization, ensembles, etc., and use this knowledge base to later learn more complicated concepts. At the same time, the authors take you through the basics of creating a machine learning pipeline by gathering and preparing data and regularly reviewing your models for decay and drift.
In some cases, such as artificial neurons, you get to implement ML models from scratch before later getting familiar with Python libraries that give full and optimized functionality.
The book provides very good coverage of Scikit-Learn, Python’s main machine learning library, as well as Numpy and Pandas. (I strongly recommend reading Python for Data Analysis by Wes Mckinney for a more comprehensive guide on Numpy and Pandas. They are two of the central libraries in data science, machine learning, and deep learning, so learning them from the creator of Pandas will be an indispensable skill.)
However, you should have a solid knowledge of Python basics and object-oriented programming before picking up this book. It won’t hold your hand on list comprehensions, function pointers, lambda functions, class inheritance, and other topics that make Python coding more efficient. You’ll also need to brush up on some of the environment configuration skills such as setting up Python environments and running Jupyter Notebook servers (alternatively, you can opt to use an ML-as-a-Service platform such as Google Colab or Microsoft Azure Machine Learning).
As a bonus, the book’s sidebars provide references to many academic papers that delve deeper into the science and math of machine learning concepts. I found this to be a very great feature of the book for several reasons.
First, literally thousands of machine learning and deep learning papers are published every year, and it can be very difficult to navigate the landscape. Second, the book references some of the milestone papers that sometimes date back to the late 1990s or early 2000s and have been lost in time with all the exciting research that has happened in recent years. And third, the book gradually introduces you to papers that are on par with the skills and knowledge that you’ve learned up to that point in the book—reading academic papers can be discouraging if you don’t have the background knowledge.
Of course, there’s a lot more to classic machine learning than can be fitted in the first 350 pages of the book. While deep learning makes more sensational news stories, many classic machine learning algorithms introduced in this book, such as decision trees and support vector machines (SVM), are still more useful in real-world applications because of their compute and data efficiency, explainability, and other factors. (For more in-depth coverage of some of these algorithms, I recommend Machine Learning Algorithms by Giuseppe Bonaccorso. Read my review of the book here.)
A tour de force of deep learning
Half of Machine Learning with PyTorch and Scikit-Learn is allocated to deep learning. Here too, the authors have done a marvelous job of gradually introducing concepts, math, coding, and tying it all together by implementing from scratch and then showing how to do it with standard Python libraries.
Like other introductory books on deep learning, Machine Learning with PyTorch takes you through the basics of neural networks and the manual implementation of a multilayer perceptron.
The rest of the deep learning chapters use PyTorch instead of TensorFlow, which I think is one of the advantages of the book. While TensorFlow is a very powerful library, I think its learning curve is steeper than PyTorch. The authors delve deep into many important features of PyTorch, including using the object-oriented features of the library to create your own custom layers, networks, data loaders, and loss functions.
The book has very good chapters on convolutional neural networks (CNN) and recurrent neural networks (RNN). But where it really shines is its introduction of more advanced deep learning architectures, including transformer networks, generative models, and graph neural networks (GNN). The authors have done a really great job of simplifying very complicated concepts and showing how they work in practice.
While each of these topics is worthy of a separate book, the authors have managed to explain them in simple terms and prepare you to pick up more advanced books or read academic papers. In particular, the chapters on attention mechanisms and transformers are among the best I’ve read on the topic (and I’ve read many).
There are a few things that were not entirely satisfactory. The chapter on reinforcement learning was a bit shallow. Understandably, RL is a very complicated topic that requires its own 800-page book. But I felt that the chapter tried to cover too much (including deep reinforcement learning) and ended up not having the depth that the other sections of the book have.
I would have also liked to see the book cover more real-world examples that span across several chapters and gradually build a real application. In this regard, a great book is Aurélien Géron’s Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow (read my review here).
Finally—and this is something that most introductory ML books are missing—I think the book’s readers could have benefitted from an introduction to MLOps and cloud ML platforms. Understandably, not everyone will want to create scalable ML models, but the MLaaS landscape has evolved so much in recent years that I think all students and self-learners can benefit from them.
But all in all, this is an excellent book. Whether it’s your first experience learning Python machine learning or if you already have a bit of experience, you’re sure to enjoy Machine Learning with PyTorch and Scikit-Learn and learn much from it.