High-performance machine learning library powered by Rust
Project description
Ferrolearn - High-performance machine learning library
Ferrolearn brings Rust's performance to Python's machine learning ecosystem. By implementing compute-intensive algorithms in Rust, we achieve significant speedups while maintaining the familiar scikit-learn API.
Key Features
- ๐ 2-10x faster than pure Python implementations
- ๐ง Scikit-learn compatible API - drop-in replacement
- ๐ฆ Rust-powered - memory safe and blazingly fast
- ๐ Zero-copy operations - efficient NumPy integration
- โก Automatic parallelization - scales with your CPU cores
Installation
Prerequisites
- Python 3.8+
- Rust 1.70+
- pip
Quick Start
from ferrolearn import KMeans
import numpy as np
# Generate sample data
X = np.random.rand(10000, 50)
# Create and fit model - same API as scikit-learn
kmeans = KMeans(n_clusters=5, random_state=42)
kmeans.fit(X)
# Get predictions
labels = kmeans.predict(X)
print(f"Cluster centers shape: {kmeans.cluster_centers_.shape}")
print(f"Iterations: {kmeans.n_iter_}")
API Reference
KMeans
class KMeans(n_clusters=8, max_iters=300, tol=1e-4, random_state=None)
Parameters:
n_clusters: Number of clusters (default: 8)max_iters: Maximum iterations (default: 300)tol: Convergence tolerance (default: 1e-4)random_state: Random seed for reproducibility
Methods:
fit(X): Fit the modelpredict(X): Predict cluster labelsfit_predict(X): Fit and predict in one call
Attributes:
cluster_centers_: Cluster centroidsn_iter_: Number of iterations runinertia_: Sum of squared distances to nearest cluster
Architecture
ferrolearn leverages Rust's strengths where they matter most:
Python (API Layer) Rust (Compute Layer)
โ โ
โโ KMeans.fit() โโโโโโโโโโโโโโบ โ Parallel distance computation
โ โ SIMD-ready operations
โโ NumPy arrays โโโโโโโโโโโโโโบ โ Zero-copy array views
โ โ Cache-efficient algorithms
โโ Results โโโโโโโโโโโโโโโโโโโโโ
Development
Setup Development Environment
# Clone and setup
git clone https://github.com/Rafa-Gu98/ferrolearn.git
cd ferrolearn
# Create virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install in development mode
make dev-install
Running Tests
# All tests
make test
# Only Rust tests
cargo test
# Only Python tests
pytest tests/
Project Structure
ferrolearn/
โโโ src/ # Rust source code
โ โโโ lib.rs # PyO3 bindings
โ โโโ kmeans.rs # K-Means implementation
โโโ python/ # Python package
โโโ tests/ # Test suite
โโโ Cargo.toml # Rust dependencies
โโโ pyproject.toml # Python packaging
Roadmap
Current (v0.1.0)
- โ K-Means clustering
- โ Scikit-learn compatible API
- โ Comprehensive benchmarks
Upcoming
- DBSCAN clustering
- Mini-batch K-Means
- Random Forest
- Gradient Boosting
Future
- GPU acceleration
- Distributed computing
- More algorithms based on user feedback
Contributing
We welcome contributions! ferrolearn is most impactful for:
- Algorithms with many iterations
- Embarrassingly parallel computations
- Memory-intensive operations
Performance Notes
When ferrolearn shines:
- Medium to large datasets (>10k samples)
- Moderate dimensionality (20-100 features)
- Multiple iterations or clusters
Current limitations:
- Small datasets may not see significant speedup due to overhead
- Not all algorithms benefit equally from Rust implementation
License
MIT License - see LICENSE file for details.
Author
Rafa_PyRs.dev
- Email: rafagr98.dev@gmail.com
- GitHub: @rafagr98
Acknowledgments
- Built with PyO3 - Rust bindings for Python
- Inspired by scikit-learn - API design
- Powered by ndarray and rayon
ferrolearn: Where Python meets Rust for machine learning performance
Made with ๐ and ๐ฆ
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ferrolearn-0.1.0.tar.gz.
File metadata
- Download URL: ferrolearn-0.1.0.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e47cce249b81272b9d42a7c8fa24d09ddc56cbe865772dc1a82e223fa80bb5d
|
|
| MD5 |
33c0e3c00cb937bc969468e0d6adcd74
|
|
| BLAKE2b-256 |
2325a9daa7d8413fabc40070c2b9f6b8e010494babe636997cb2bbb9d7678d06
|
File details
Details for the file ferrolearn-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: ferrolearn-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 276.8 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4457ee0e1240738757da8ec8659e971f24158b6e6c1525637260eb40256cedc9
|
|
| MD5 |
e2e7fefa19f75ab7d0eb393e1e5dcdf5
|
|
| BLAKE2b-256 |
1d00bc266f068556ac3866cc6764f1dd817b491312b5516834148552c632c3ce
|