Join thousands of students in our LangChain and Vector DBs in Production course, with over 50+ lessons and practical projects for FREE!.


Rustic Learning: Machine Learning in Rust  Part 2: Regression and Classification
Latest   Machine Learning

Rustic Learning: Machine Learning in Rust Part 2: Regression and Classification

Last Updated on April 6, 2023 by Editorial Team

Author(s): Ulrik Thyge Pedersen

Originally published on Towards AI.

Rustic Learning: Machine Learning in Rust — Part 2: Regression and Classification

An Introduction to Rust’s Machine Learning crates

Photo by Malik Skydsgaard on Unsplash

Rustic Learning is a series of articles that explores the use of Rust programming language for machine learning tasks. The articles cover a range of topics, from the basics of Rust to more advanced machine learning concepts, and provide practical examples to help readers get started with implementing ML algorithms in Rust. You can find the other parts of the Rustic Learning series here:

Part 1: Introduction to Rust

Part 2: Regression and Classification

Part 3: Deep Learning Bindings

Part 4: Neural Networks

Part 5: Model Deployment

Machine Learning in Rust

While Rust is not yet as widely used for machine learning as some other languages like Python or R, it has a growing community of developers working on machine learning projects. Rust’s performance and safety features make it a good choice for some types of machine learning applications, particularly those that involve large amounts of data or require low-level optimization.

Rust has several libraries and frameworks for machine learning, lets talk about a few of them!


SmartCore is a machine learning library written in Rust that provides a variety of algorithms for regression, classification, clustering, and more. It includes both traditional machine learning algorithms like linear regression and k-means clustering, as well as more advanced techniques like neural networks and gradient boosting.

One of the unique features of SmartCore is its emphasis on interpretability. Many of the algorithms included in SmartCore provide detailed information about the models they build, including feature importance, decision paths, and more. This makes it easier for developers to understand and debug their machine learning models.

Here’s a short code example that demonstrates how to use SmartCore for binary classification:

In this example, we load the iris dataset using SmartCore’s built-in dataset loader. We then extract the features and target variable from the dataset, create a logistic regression model, fit it to the data, and use it to predict the target variable for new data. Finally, we calculate the accuracy of the model and print it to the console.

Overall, SmartCore is a powerful and flexible machine learning library that provides a variety of algorithms and tools for building interpretable machine learning models in Rust.

Photo by David Schultz on Unsplash


Linfa is a Rust-based machine-learning library that offers a wide range of algorithms for regression, classification, clustering, and other tasks. The library encompasses both conventional and advanced machine learning techniques, including linear regression, k-means clustering, random forests, and support vector machines.

One of Linfa’s most notable features is its emphasis on interoperability, achieved through a standardized API for machine learning algorithms. This enables developers to easily switch algorithms and compare their performance while also facilitating integration with other Rust libraries for data manipulation and visualization, such as ndarray and gnuplot.

Here’s a short code example that demonstrates how to use Linfa for binary classification using a support vector machine:

To illustrate the library’s capabilities, we can use Linfa’s Svm implementation to build a support vector machine model, fit it to synthetic data generated with ndarray and ndarray_rand, and use it to predict the target variable for new data. We can then evaluate the accuracy of the model with Linfa’s accuracy_score function and output the results to the console.

In conclusion, Linfa is a versatile and robust machine-learning library that provides numerous algorithms and tools for creating machine-learning models in Rust. Its interoperability and integration with other Rust libraries make it an excellent choice for developers seeking a modular and extendable approach to building machine learning applications.

Photo by Tudor Baciu on Unsplash


In conclusion, this article has introduced us to two of the most popular machine-learning libraries available in Rust, namely Linfa and SmartCore. We have learned about the key features and capabilities of each library, including support for common machine-learning algorithms, data manipulation, and model evaluation.

Linfa provides a high-level API that allows developers to focus on building and training models without worrying about low-level details such as memory management. On the other hand, SmartCore is a low-level library that provides efficient implementations of linear algebra operations and other common machine learning algorithms.

Despite being relatively new compared to other languages like Python and R, Rust’s machine-learning ecosystem is growing rapidly, and libraries like Linfa and SmartCore are contributing to its popularity.

As more developers explore Rust for machine learning applications, we can expect to see more libraries and tools being developed that leverage Rust’s unique strengths, such as memory safety and performance.

Overall, the availability of efficient and reliable machine learning libraries in Rust makes it a promising language for building high-performance and secure machine learning applications!

Thank you for reading my story!

Subscribe for free to get notified when I published a new story!

Find me on LinkedIn and Kaggle!

…and I would love your feedback!

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI

Feedback ↓