Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Ridge regression 1D

Here, we implement one-dimensional Ridge Regression*in several styles, using increasing levels of abstraction. It's designed as a learning path for beginners, and focuses on writing idiomatic, clear, and type-safe Rust code. We focus on minimizing this loss function:

where: is an input covariate, is the associated output, is the Ridge coefficient, is the regularization strength.

What you'll learn

This module is perfect if you're just starting with Rust and want to:

  • Write beginner-friendly numerical code
  • Understand how to manipulate vectors (Vec<f64>) and slices (&[f64])
  • Write clean and safe code using the standard library only
  • Structure your functions with clear responsibilities
  • Learn good Rust patterns: immutability, iterators, ownership
  • How to make a simple crate out of it
  • How to expose a public API

If you want to implement and run this example while you read but are not familiar with Cargo yet, have a look at Cargo 101 for how to set up your project.