Practical Machine Learning with Rust
304 pages
English
PDF
4.5

Practical Machine Learning with Rust

Practical Machine Learning with Rust

Author:

Year:

Summary:

Introduction

The book «Practical Machine Learning with Rust» (author: Joydeep Bhattacharjee, 2020, 304 pages) is a rare and valuable guide that unites two powerful worlds: the high-performance systems language Rust and modern machine learning. While Python dominates the ML ecosystem, Rust offers safe memory management, speed close to C/C++, and excellent capabilities for parallel computing. This book is not just a translation of Python approaches into Rust, but a deep dive into the specifics of creating ML models, taking into account the language's features.

What the book is about

The author consistently guides the reader from the basics of Rust (if you are a beginner) to building full-fledged neural networks and data processing pipelines. The book is divided into logical blocks:

  • Rust Basics for ML: a brief but concise introduction to syntax, ownership, borrowing, and traits necessary for further work.
  • Working with Data: loading, cleaning, and transforming data using the ndarray, csv, and serde crates.
  • Linear Algebra and Statistics: implementing matrix operations, calculating metrics (mean, variance, correlation) without third-party libraries.
  • Machine Learning Algorithms: linear regression, logistic regression, k-nearest neighbors, decision trees — from scratch and using the rustlearn crate.
  • Neural Networks: building a multi-layer perceptron, backpropagation, working with the tch-rs crate (binding to PyTorch).
  • Optimization and Parallelism: using Rayon for parallel data processing, speeding up training.
  • Model Deployment: creating a REST API using actix-web and integrating the model into a web service.

Who this book is for

The book is intended for developers already familiar with Rust (at least at a basic level) who want to apply it to machine learning tasks. It will also be useful for ML engineers who want to go beyond Python and gain control over performance. Beginners in Rust should first master at least The Rust Programming Language, as the author does not dwell on elementary constructs.

What the reader will learn

  • How to efficiently load and process large volumes of data in Rust.
  • How to implement classic ML algorithms without external dependencies.
  • How to use the ndarray, rustlearn, tch-rs crates to build models.
  • How to optimize training using multithreading (Rayon).
  • How to serialize models and deploy them to production via a web server.
  • How to avoid common mistakes related to ownership and borrowing when working with matrices.

Strengths

1. Practical focus. Each chapter contains ready-to-run code. The examples are real: from predicting housing prices to image classification.

2. Balance between theory and implementation. The author explains the mathematics of algorithms just enough for the reader to understand what is happening, without getting bogged down in formulas.

3. Focus on performance. It shows how Rust allows you to process data faster than Python, especially on large datasets.

4. Modern stack. Up-to-date versions of crates (as of 2020) are used, making the book applicable today with minor adjustments.

5. Deployment. A rare topic for ML books — packaging a model into a web service — is covered in detail and with high quality.

Who it is recommended for

The book will be useful for:

  • Rust developers looking to expand the scope of the language.
  • Data Scientists who want to move beyond Python and gain control over performance.

Recommendations