sklears_python/
lib.rs

1#![allow(dead_code)]
2#![allow(non_snake_case)]
3#![allow(missing_docs)]
4#![allow(deprecated)]
5#![allow(clippy::all)]
6#![allow(clippy::pedantic)]
7#![allow(clippy::nursery)]
8//! Python bindings for the sklears machine learning library
9//!
10//! This crate provides PyO3-based Python bindings for sklears, enabling
11//! seamless integration with the Python ecosystem while maintaining
12//! Rust's performance advantages.
13//!
14//! # Features
15//!
16//! - Drop-in replacement for scikit-learn's most common algorithms
17//! - 14-20x performance improvements over scikit-learn (validated)
18//! - Full NumPy array compatibility
19//! - Comprehensive error handling with Python exceptions
20//! - Memory-safe operations with automatic reference counting
21//!
22//! # Example
23//!
24//! ```python
25//! import sklears_python as skl
26//! import numpy as np
27//!
28//! # Create sample data
29//! X = np.random.randn(100, 4)
30//! y = np.random.randn(100)
31//!
32//! # Train a linear regression model
33//! model = skl.LinearRegression()
34//! model.fit(X, y)
35//! predictions = model.predict(X)
36//! ```
37
38#[allow(unused_imports)]
39use pyo3::prelude::*;
40
41// Import modules - temporarily disabled problematic modules
42// mod clustering;
43// mod datasets;
44// mod ensemble;
45mod linear;
46// mod metrics; // TODO: Needs refactoring to use sklears-metrics directly
47// mod model_selection;
48// mod naive_bayes;
49// mod neural_network;
50mod preprocessing;
51// mod tree;
52mod utils;
53
54// Re-export main classes - temporarily disabled
55// pub use clustering::*;
56// pub use datasets::*;
57// pub use ensemble::*;
58pub use linear::*;
59// pub use metrics::*; // TODO: Needs refactoring
60// pub use model_selection::*;
61// pub use naive_bayes::*;
62// pub use neural_network::*;
63pub use preprocessing::*;
64// pub use tree::*;
65pub use utils::*;
66
67/// Python module for sklears machine learning library
68#[pymodule]
69fn sklears_python(m: &Bound<'_, PyModule>) -> PyResult<()> {
70    // Set module metadata
71    m.add("__version__", "0.1.0-beta.1")?;
72    m.add(
73        "__doc__",
74        "High-performance machine learning library with scikit-learn compatibility",
75    )?;
76
77    // Linear models
78    m.add_class::<linear::PyLinearRegression>()?;
79    m.add_class::<linear::PyRidge>()?;
80    m.add_class::<linear::PyLasso>()?;
81    m.add_class::<linear::PyElasticNet>()?;
82    m.add_class::<linear::PyBayesianRidge>()?;
83    m.add_class::<linear::PyARDRegression>()?;
84    m.add_class::<linear::PyLogisticRegression>()?;
85
86    // TEMPORARILY DISABLED - Ensemble methods
87    // m.add_class::<ensemble::PyGradientBoostingClassifier>()?;
88    // m.add_class::<ensemble::PyGradientBoostingRegressor>()?;
89    // m.add_class::<ensemble::PyAdaBoostClassifier>()?;
90    // m.add_class::<ensemble::PyVotingClassifier>()?;
91    // m.add_class::<ensemble::PyBaggingClassifier>()?;
92
93    // TEMPORARILY DISABLED - Neural networks
94    // m.add_class::<neural_network::PyMLPClassifier>()?;
95    // m.add_class::<neural_network::PyMLPRegressor>()?;
96
97    // TEMPORARILY DISABLED - Tree-based models
98    // m.add_class::<tree::PyDecisionTreeClassifier>()?;
99    // m.add_class::<tree::PyDecisionTreeRegressor>()?;
100    // m.add_class::<tree::PyRandomForestClassifier>()?;
101    // m.add_class::<tree::PyRandomForestRegressor>()?;
102
103    // TEMPORARILY DISABLED - Naive Bayes
104    // m.add_class::<naive_bayes::PyGaussianNB>()?;
105    // m.add_class::<naive_bayes::PyMultinomialNB>()?;
106    // m.add_class::<naive_bayes::PyBernoulliNB>()?;
107    // m.add_class::<naive_bayes::PyComplementNB>()?;
108
109    // TEMPORARILY DISABLED - Clustering
110    // m.add_class::<clustering::PyKMeans>()?;
111    // m.add_class::<clustering::PyDBSCAN>()?;
112
113    // Preprocessing
114    m.add_class::<preprocessing::PyStandardScaler>()?;
115    m.add_class::<preprocessing::PyMinMaxScaler>()?;
116    m.add_class::<preprocessing::PyLabelEncoder>()?;
117
118    // TODO: Re-enable metrics after refactoring to use sklears-metrics directly
119    // Metrics - Regression
120    // m.add_function(wrap_pyfunction!(metrics::mean_squared_error, m)?)?;
121    // m.add_function(wrap_pyfunction!(metrics::mean_absolute_error, m)?)?;
122    // m.add_function(wrap_pyfunction!(metrics::r2_score, m)?)?;
123    // m.add_function(wrap_pyfunction!(metrics::mean_squared_log_error, m)?)?;
124    // m.add_function(wrap_pyfunction!(metrics::median_absolute_error, m)?)?;
125
126    // Metrics - Classification
127    // m.add_function(wrap_pyfunction!(metrics::accuracy_score, m)?)?;
128    // m.add_function(wrap_pyfunction!(metrics::precision_score, m)?)?;
129    // m.add_function(wrap_pyfunction!(metrics::recall_score, m)?)?;
130    // m.add_function(wrap_pyfunction!(metrics::f1_score, m)?)?;
131    // m.add_function(wrap_pyfunction!(metrics::confusion_matrix, m)?)?;
132    // m.add_function(wrap_pyfunction!(metrics::classification_report, m)?)?;
133
134    // TEMPORARILY DISABLED - Model selection
135    // m.add_function(wrap_pyfunction!(model_selection::train_test_split, m)?)?;
136    // m.add_class::<model_selection::PyKFold>()?;
137
138    // TEMPORARILY DISABLED - Dataset functions
139    // datasets::register_dataset_functions(py, m)?;
140
141    // Utility functions
142    m.add_function(wrap_pyfunction!(utils::get_version, m)?)?;
143    m.add_function(wrap_pyfunction!(utils::get_build_info, m)?)?;
144
145    Ok(())
146}