Preface
Introduction
What is Data Science?
Data science is an interdisciplinary field that uses scientific methods, processes, algorithms, and systems to extract knowledge and insights from structured and unstructured data. It combines aspects of statistics, computer science, and domain knowledge to analyze and interpret complex data.
Why Use Rust for Data Science?
Rust is a systems programming language known for its performance, safety, and concurrency capabilities. These features make Rust an excellent choice for data science tasks, which often involve processing large datasets and performing computationally intensive operations. Rust's strong type system and memory safety guarantees can help reduce bugs and improve the reliability of data science applications.
Overview of the Book
This book aims to provide a comprehensive guide to using Rust for data science. It will cover everything from setting up the Rust environment and basic syntax to advanced topics like machine learning, deep learning, and data engineering. Each chapter will include practical examples and projects to help you apply the concepts learned.
Chapter_01
Rust Environment Setup
Rust Environment Setup
Rust is a modern and powerful systems programming language. To get started with Rust, you'll need to install it on your system.
This setup.md
file provides instructions for setting up Rust on Windows, macOS, and Linux, as well as installing Rust for use with Jupyter Notebook using the evcxr tool. You can customize and expand this document as needed.
Here are instructions for various platforms:
Installing Rust on Windows
- Visit the official Rust website for Windows: https://www.rust-lang.org/learn/get-started.
- Download the
rustup-init.exe
installer. - Run the installer and follow the on-screen instructions.
- Open a new command prompt or terminal window and type
rustc --version
to verify that Rust is installed.
Installing Rust on macOS
- Open a terminal.
- Install Homebrew if you don't already have it. Follow the instructions at https://brew.sh.
- Install Rust using Homebrew:
- To verify the installation, run
rustc --version
in the terminal.
Installing Rust on Linux
- Open a terminal.
- Visit the official Rust website for Linux: https://www.rust-lang.org/learn/get-started.
- Follow the instructions for your Linux distribution. They typically involve running a command to install Rust using
rustup
. - To verify the installation, run
rustc --version
in the terminal.
Checking the Installation
After the installation has been completed successfully, you will have on your command line tool four new commands, you can check their versions as follows:
-
rustup
: Rust installation tool managerrustup --version
-
rustc
: Rust Compilerrustc --version
-
rustdoc
: Rust documentation toolrustdoc --version
-
cargo
: Rust compilation and package managercargo --version
Setup Rust Kernel
Installing Jupyter Lab
You can skip this section if you already have jupyter lab (or notebook) installed on your machine. If not, you can choose one method to get things done. In the following subsection, I will focus on jupyter lab, the newer version of classic jupyter notebook.
-
Using anaconda distribution:
-
Using Command Line Tools: There is a chance that you don't want anaconda to be installed on you machine, in fact it takes a lot of space from the hard disk, especially the full version. If this is your case, then what you need is python to be installed, and then install jupyter lab. I assume you already have python, if not please do so.
Then it suffices only to run the following command to install jupyter lab:
pip install -U jupyterlab
- Installing Jupyterlab Desktop Application
-
Unix-based Systems
-
Mac OS: Using
brew
utility as follows:brew install jupyterlab
-
Linux (Ubuntu): You need to install
snapd
firstsudo apt update sudo apt install snapd
Then you can simply use the following command:
sudo snap install jupyterlab-desktop --classic
-
Fedora Linux:
-
Install
snapd
sudo dnf install snapd
-
Create symbolic link
sudo ln -s /var/lib/snapd/snap /snap
-
Install the application
sudo snap install jupyterlab-desktop --classic
-
-
-
Windows
winget install jupyterlab
Please check the jupyterlab official link if you have any problem with installation of you have a different operating system.
Installing Rust Kernel for Jupyter Notebook
If you want to use Rust in Jupyter Notebook, you can use the evcxr
tool, which provides Rust support for Jupyter:
- Install
evcxr
usingcargo
, the Rust package manager
cargo install evcxr_jupyter
- Once
evcxr
is installed, you can configure Jupyter Notebook to use it
evcxr_jupyter --install
-
Start Jupyter Notebook
-
Create a new Jupyter notebook and choose the "Rust" kernel to start writing Rust code.
Now you're all set to explore the power of Rust on Jupyter Notebook.
Updating Rust
Updating Rust on different platforms is streamlined by the use of rustup
command, the Rust’s
official toolchain installer and manager.
The Rustup provides a uniform way to manage Rust versions across various environments. To update Rust using Rustup, open your terminal or command prompt and run:
rustup update
This command checks for the latest stable version of Rust, downloads it, and updates your system to use it. It's applicable to Windows, Linux, and macOS.
After Updating
After updating, you can verify the installation and check the current version by running:
rustc --version
This command will display the version of Rust currently installed, ensuring that your update was successful.
Uninstall Rust
Rust can be removed or uninstalled from the machine using the rustup
manager.
On Mac os Machines
rustup self uninstall
Or you can uninstall rust
using brew
utility by typing the following command on a terminal application:
brew uninstall rust
Uninstalling Jupyter Rust Kernel
evcxr_jupyter --uninstall
cargo uninstall evcxr_jupyter