Crate sklears_python

Crate sklears_python 

Source
Expand description

Python bindings for the sklears machine learning library

This crate provides PyO3-based Python bindings for sklears, enabling seamless integration with the Python ecosystem while maintaining Rust’s performance advantages.

§Features

  • Drop-in replacement for scikit-learn’s most common algorithms
  • 14-20x performance improvements over scikit-learn (validated)
  • Full NumPy array compatibility
  • Comprehensive error handling with Python exceptions
  • Memory-safe operations with automatic reference counting

§Example

import sklears_python as skl
import numpy as np

# Create 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)

Macros§

wrap_pyfunction
Wraps a Rust function annotated with #[pyfunction].

Structs§

Borrowed
A borrowed equivalent to Bound.
Bound
A GIL-attached equivalent to Py<T>.
PerformanceStats
Performance monitoring structure
Py
A GIL-independent reference to an object allocated on the Python heap.
PyARDRegression
Bayesian ARD regression.
PyAny
Represents any Python object.
PyBayesianRidge
Bayesian ridge regression.
PyClassInitializer
Initializer for our #[pyclass] system.
PyElasticNet
Linear regression with combined L1 and L2 priors as regularizer.
PyErr
Represents a Python exception.
PyLabelEncoder
Encode target labels with value between 0 and n_classes-1.
PyLasso
Python wrapper for Lasso regression
PyLinearRegression
Ordinary least squares Linear Regression.
PyLogisticRegression
Logistic Regression (aka logit, MaxEnt) classifier.
PyMinMaxScaler
Transform features by scaling each feature to a given range.
PyModule
Represents a Python module object.
PyRef
A wrapper type for an immutably borrowed value from a Bound<'py, T>.
PyRefMut
A wrapper type for a mutably borrowed value from a Bound<'py, T>.
PyRidge
Python wrapper for Ridge regression
PyStandardScaler
Standardize features by removing the mean and scaling to unit variance.
PyValueError
Represents Python’s ValueError exception.
Python
A marker token that represents holding the GIL.

Enums§

SklearsPythonError
Enhanced error handling for sklears-python

Traits§

FromPyObject
Extract a type from a Python object.
IntoPyObject
Defines a conversion from a Rust type to a Python object, which may fail.
PyAnyMethods
This trait represents the Python APIs which are usable on all Python objects.
PyBoolMethods
Implementation of functionality for PyBool.
PyByteArrayMethods
Implementation of functionality for PyByteArray.
PyBytesMethods
Implementation of functionality for PyBytes.
PyCapsuleMethods
Implementation of functionality for PyCapsule.
PyComplexMethods
Implementation of functionality for PyComplex.
PyDictMethods
Implementation of functionality for PyDict.
PyFloatMethods
Implementation of functionality for PyFloat.
PyFrozenSetMethods
Implementation of functionality for PyFrozenSet.
PyListMethods
Implementation of functionality for PyList.
PyMappingMethods
Implementation of functionality for PyMapping.
PyMappingProxyMethods
Implementation of functionality for PyMappingProxy.
PyModuleMethods
Implementation of functionality for PyModule.
PySequenceMethods
Implementation of functionality for PySequence.
PySetMethods
Implementation of functionality for PySet.
PySliceMethods
Implementation of functionality for PySlice.
PyStringMethods
Implementation of functionality for PyString.
PyTracebackMethods
Implementation of functionality for PyTraceback.
PyTupleMethods
Implementation of functionality for PyTuple.
PyTypeMethods
Implementation of functionality for PyType.
PyWeakrefMethods
Implementation of functionality for PyWeakref.

Functions§

benchmark_basic_operations
Performance testing utility
calculate_r2_score
Calculate R² score with optimized array operations
check_memory_usage
Check memory usage and warn if arrays are very large
core_array1_to_py
Convert an ndarray Array1 into a Python-owned NumPy array object
core_array2_to_py
Convert an ndarray Array2 into a Python-owned NumPy array object
get_available_memory_mb
Get system memory information for better memory management
get_build_info
Get build information about sklears
get_config
Get current configuration
get_hardware_info
Get hardware acceleration capabilities
get_memory_info
Get memory usage information
get_version
Get the version of sklears
has_feature
Check if specific features are enabled
ndarray1_to_numpy
Convert ndarray Array1<f64> to NumPy array
ndarray_to_numpy
Convert ndarray Array2<f64> to NumPy array
numpy_to_ndarray1
Convert NumPy array to ndarray Array1<f64>
numpy_to_ndarray2
Convert NumPy array to ndarray Array2<f64>
pyarray_to_core_array1
Convert a read-only NumPy array view into an owned SciRS2 ndarray Array1
pyarray_to_core_array2
Convert a read-only NumPy array view into an owned SciRS2 ndarray Array2
set_config
Set global configuration options
show_versions
Print system information
validate_finite_values
Validate that array contains only finite values
validate_finite_values_1d
Validate that 1D array contains only finite values
validate_fit_arrays
Validate input arrays for model fitting
validate_fit_arrays_enhanced
Enhanced validation functions with better error handling
validate_predict_array
Validate input arrays for prediction

Type Aliases§

Array1
one-dimensional array
Array2
two-dimensional array
LinearModelResult
Common error type for linear model operations
PyArray1
One-dimensional array.
PyArray2
Two-dimensional array.
PyObject
A commonly-used alias for Py<PyAny>.
PyReadonlyArray1
Read-only borrow of a one-dimensional array.
PyReadonlyArray2
Read-only borrow of a two-dimensional array.
PyResult
Represents the result of a Python call.

Attribute Macros§

pyclass
pyfunction
A proc macro used to expose Rust functions to Python.
pymethods
A proc macro used to expose methods to Python.
pymodule
A proc macro used to implement Python modules.

Derive Macros§

FromPyObject
IntoPyObject
IntoPyObjectRef