Sklears Python Bindings
Python bindings for the sklears machine learning library, providing a high-performance, scikit-learn compatible interface through PyO3.
Latest release:
0.1.0-alpha.1(October 13, 2025). See the workspace release notes for highlights and upgrade guidance.
Features
- Drop-in replacement for scikit-learn's most common algorithms
- 3-100x performance improvements over scikit-learn
- Full NumPy array compatibility with zero-copy operations where possible
- Comprehensive error handling with Python exceptions
- Memory-safe operations with automatic reference counting
- Scikit-learn compatible API for easy migration
Supported Algorithms
Linear Models
LinearRegression- Ordinary least squares linear regressionRidge- Ridge regression with L2 regularizationLasso- Lasso regression with L1 regularizationLogisticRegression- Logistic regression for classification
Clustering
KMeans- K-Means clustering algorithmDBSCAN- Density-based spatial clustering
Preprocessing
StandardScaler- Standardize features by removing mean and scaling to unit varianceMinMaxScaler- Scale features to a given rangeLabelEncoder- Encode target labels with value between 0 and n_classes-1
Model Selection
train_test_split- Split arrays into random train and test subsetsKFold- K-Fold cross-validatorStratifiedKFold- Stratified K-Fold cross-validatorcross_val_score- Evaluate metric(s) by cross-validationcross_val_predict- Generate cross-validated estimates
Metrics
accuracy_score- Classification accuracymean_squared_error- Mean squared error for regressionmean_absolute_error- Mean absolute error for regressionr2_score- R² (coefficient of determination) scoreprecision_score- Precision for classificationrecall_score- Recall for classificationf1_score- F1 score for classificationconfusion_matrix- Confusion matrix for classificationclassification_report- Text report of classification metrics
Installation
Prerequisites
- Python 3.8 or later
- NumPy
- Rust 1.70 or later
- PyO3 and Maturin for building
Building from Source
-
Clone the repository:
-
Install Maturin:
-
Build and install the package:
-
Or build a wheel:
Quick Start
# Generate sample data
=
=
# Train a linear regression model
=
=
# Calculate R² score
=
Performance Comparison
Here's a typical performance comparison with scikit-learn:
# Generate data
, =
, , , =
# Sklears
=
=
=
= -
# Scikit-learn
=
=
=
= -
API Compatibility
The sklears Python bindings are designed to be API-compatible with scikit-learn. Most existing scikit-learn code should work with minimal changes:
Before (scikit-learn):
After (sklears):
# All functions and classes are available in the main module
=
=
, , , =
=
Memory Management
The bindings are designed to be memory-efficient:
- Zero-copy operations where possible using NumPy's C API
- Automatic memory management through PyO3's reference counting
- Efficient data structures using ndarray and sprs for sparse matrices
- Streaming support for large datasets that don't fit in memory
Error Handling
All Rust errors are properly converted to Python exceptions:
# This will raise a ValueError if arrays have incompatible shapes
=
# Shape mismatch
System Information
Get information about your sklears installation:
# Version information
# Build information
=
# Hardware capabilities
=
# Performance benchmarks
=
Configuration
Set global configuration options:
# Set number of threads for parallel operations
# Get current configuration
=
Examples
See the examples/ directory for comprehensive usage examples:
python_demo.py- Complete demonstration of all features- Performance comparison scripts
- Real-world use cases
Contributing
Contributions are welcome! Please see the main sklears repository for contribution guidelines.
License
This project is licensed under the MIT OR Apache-2.0 license.
Acknowledgments
- Built with PyO3 for Rust-Python interoperability
- Compatible with NumPy arrays
- API inspired by scikit-learn