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
  • 3-100x performance improvements over scikit-learn
  • 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.
PyAny
Represents any Python object.
PyClassInitializer
Initializer for our #[pyclass] system.
PyErr
Represents a Python exception.
PyLasso
Python wrapper for Lasso regression
PyLinearRegression
Ordinary least squares Linear Regression.
PyLogisticRegression
Logistic Regression (aka logit, MaxEnt) classifier.
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
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
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 to NumPy array
ndarray_to_numpy
Convert ndarray Array2 to NumPy array
numpy_to_ndarray1
Convert NumPy array to ndarray Array1 - simplified implementation
numpy_to_ndarray2
Convert NumPy array to ndarray Array2 - simplified implementation
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.
PyObjectDeprecated
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