Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Sklears Python Bindings

Crates.io Documentation License Minimum Rust Version

Python bindings for the sklears machine learning library, providing a high-performance, scikit-learn compatible interface through PyO3.

Latest release: 0.1.0-rc.1 (February 2026). See the workspace release notes for highlights and upgrade guidance.

Features

  • Drop-in replacement for scikit-learn's most common algorithms
  • Pure Rust implementation with ongoing performance optimization
  • 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 regression
  • Ridge - Ridge regression with L2 regularization
  • Lasso - Lasso regression with L1 regularization
  • ElasticNet - Elastic-net regularization
  • BayesianRidge - Bayesian ridge regression
  • ARDRegression - Automatic Relevance Determination regression
  • LogisticRegression - Logistic regression for classification

Ensemble Methods

  • GradientBoostingClassifier - Gradient boosting for classification
  • GradientBoostingRegressor - Gradient boosting for regression
  • AdaBoostClassifier - Adaptive boosting classifier
  • VotingClassifier - Voting ensemble classifier
  • BaggingClassifier - Bagging ensemble classifier

Neural Networks

  • MLPClassifier - Multi-layer perceptron classifier
  • MLPRegressor - Multi-layer perceptron regressor

Naive Bayes

  • GaussianNB - Gaussian Naive Bayes
  • MultinomialNB - Multinomial Naive Bayes
  • BernoulliNB - Bernoulli Naive Bayes
  • ComplementNB - Complement Naive Bayes

Clustering

  • KMeans - K-Means clustering algorithm
  • DBSCAN - Density-based spatial clustering

Preprocessing (coming soon)

  • StandardScaler - Standardize features by removing mean and scaling to unit variance
  • MinMaxScaler - Scale features to a given range
  • LabelEncoder - Encode target labels with value between 0 and n_classes-1

Tree Models (coming soon)

  • RandomForestClassifier - Random forest for classification
  • DecisionTreeClassifier - Decision tree for classification

Model Selection

  • train_test_split - Split arrays into random train and test subsets
  • KFold - K-Fold cross-validator
  • StratifiedKFold (coming soon) - Stratified K-Fold cross-validator
  • cross_val_score (coming soon) - Evaluate metric(s) by cross-validation

Metrics (coming soon)

  • accuracy_score - Classification accuracy
  • mean_squared_error - Mean squared error for regression
  • mean_absolute_error - Mean absolute error for regression
  • r2_score - R² (coefficient of determination) score
  • precision_score - Precision for classification
  • recall_score - Recall for classification
  • f1_score - F1 score for classification
  • confusion_matrix - Confusion matrix for classification
  • classification_report - Text report of classification metrics

Installation

Prerequisites

  • Python 3.9 or later
  • NumPy
  • Rust 1.70 or later
  • PyO3 and Maturin for building

Building from Source

  1. Clone the repository:

    git clone https://github.com/cool-japan/sklears.git
    cd sklears/crates/sklears-python
    
  2. Install Maturin:

    pip install maturin
    
  3. Build and install the package:

    maturin develop --release
    
  4. Or build a wheel:

    maturin build --release
    pip install target/wheels/sklears-*.whl
    

Quick Start

import numpy as np
import sklears as skl

# Generate sample data
X = np.random.randn(100, 4)
y = np.random.randn(100)

# Train a linear regression model
model = skl.LinearRegression()
model.fit(X, y)
predictions = model.predict(X)

# Calculate R² score
score = model.score(X, y)
print(f"R² score: {score:.3f}")

Performance Comparison

Here's a typical performance comparison with scikit-learn:

import time
import numpy as np
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
import sklears as skl
from sklearn.linear_model import LinearRegression as SklearnLR

# Generate data
X, y = make_regression(n_samples=10000, n_features=100, noise=0.1)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

# Sklears
start = time.time()
model = skl.LinearRegression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
sklears_time = time.time() - start

# Scikit-learn
start = time.time()
sklearn_model = SklearnLR()
sklearn_model.fit(X_train, y_train)
sklearn_predictions = sklearn_model.predict(X_test)
sklearn_time = time.time() - start

print(f"Sklears time: {sklears_time:.4f}s")
print(f"Sklearn time: {sklearn_time:.4f}s")
print(f"Speedup: {sklearn_time / sklears_time:.2f}x")

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):

from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error

After (sklears):

import sklears as skl

# Available classes and functions
model = skl.LinearRegression()
X_train, X_test, y_train, y_test = skl.train_test_split(X, y)

# Note: StandardScaler, MinMaxScaler, LabelEncoder - coming soon
# Note: mean_squared_error, r2_score, accuracy_score, etc. - coming soon

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:

import sklears as skl
import numpy as np

try:
    # This will raise a ValueError if arrays have incompatible shapes
    model = skl.LinearRegression()
    model.fit(np.array([[1, 2], [3, 4]]), np.array([1, 2, 3]))  # Shape mismatch
except ValueError as e:
    print(f"Error: {e}")

System Information

Get information about your sklears installation:

import sklears as skl

# Version information
print(f"Version: {skl.get_version()}")

# Build information
build_info = skl.get_build_info()
for key, value in build_info.items():
    print(f"{key}: {value}")

# Note: get_hardware_info() and benchmark_basic_operations() - coming soon

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 Apache-2.0 license.

Acknowledgments

  • Built with PyO3 for Rust-Python interoperability
  • Compatible with NumPy arrays
  • API inspired by scikit-learn

Metadata

Release files for sklears 0.1.0rc1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sklears 0.1.0rc1
File Size Uploaded Provenance Actions
sklears-0.1.0rc1.tar.gz 3.9 MB Without provenance Details for sklears-0.1.0rc1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for sklears 0.1.0rc1
File Interpreter ABI Platform Actions
sklears-0.1.0rc1-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details for sklears-0.1.0rc1-cp314-cp314-macosx_11_0_arm64.whl
sklears-0.1.0rc1-cp310-cp310-manylinux_2_34_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.34+ x86-64 Details for sklears-0.1.0rc1-cp310-cp310-manylinux_2_34_x86_64.whl

Total release size: 5.6 MB

Release files / sklears-0.1.0rc1.tar.gz

Download URL sklears-0.1.0rc1.tar.gz
Size 3.9 MB
Tags Source
SHA-256 checksum
How to use checksums
4fd928886403d05ba1273cc518b65752c07cf5101a114753c8501a4b06cd9e3e
BLAKE2b-256 checksum
How to use checksums
ec9fb2ff50eb669722ea522110977f767fa069855201ba96aca6390df1d03baf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.7

Release files / sklears-0.1.0rc1-cp314-cp314-macosx_11_0_arm64.whl

Download URL sklears-0.1.0rc1-cp314-cp314-macosx_11_0_arm64.whl
Size 780.6 kB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
222365ad31598355a0960e6206a6598fe8b9f37f7660f79cee3ce6c1d2fdabb3
BLAKE2b-256 checksum
How to use checksums
515aa970a9cdb62c37bfb8f55ee4615f396f04d2cbfad45e26d5f79c8ab08858
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.7

Release files / sklears-0.1.0rc1-cp310-cp310-manylinux_2_34_x86_64.whl

Download URL sklears-0.1.0rc1-cp310-cp310-manylinux_2_34_x86_64.whl
Size 897.6 kB
Tags CPython 3.10 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
1d07a70df843fadc5c1b16d8078ad7c0075077d9bccd2f85cd20e3f1acc4f263
BLAKE2b-256 checksum
How to use checksums
71f2c231aafadc380f51aac8d045e9587b247a199847f9906fb0131b0b16b936
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.3

Security for sklears 0.1.0rc1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page