Skip to main content

scry_learn/
lib.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2//! # scry-learn
3//!
4//! Machine learning toolkit in pure Rust.
5//!
6//! ## Quick Start
7//!
8//! ```ignore
9//! use scry_learn::prelude::*;
10//!
11//! let data = Dataset::from_csv("iris.csv", "species")?;
12//! let (train, test) = train_test_split(&data, 0.2, 42);
13//!
14//! let mut model = RandomForestClassifier::new()
15//!     .n_estimators(100)
16//!     .max_depth(10);
17//! model.fit(&train)?;
18//!
19//! let preds = model.predict(&test)?;
20//! let report = classification_report(&test.target, &preds);
21//! println!("{report}");
22//! ```
23
24#![warn(missing_docs)]
25#![deny(unsafe_code)]
26#![allow(clippy::doc_markdown)]
27#![allow(clippy::missing_fields_in_debug)]
28#![allow(clippy::uninlined_format_args)]
29#![allow(clippy::redundant_pub_crate)]
30#![allow(clippy::use_self)]
31#![allow(clippy::suspicious_operation_groupings)]
32#![allow(clippy::used_underscore_binding)]
33#![allow(clippy::cast_possible_wrap)]
34#![allow(clippy::items_after_statements)]
35#![allow(clippy::too_many_arguments)]
36#![allow(clippy::option_if_let_else)]
37#![allow(clippy::type_complexity)]
38#![allow(clippy::map_unwrap_or)]
39#![allow(clippy::needless_range_loop)]
40#![allow(clippy::explicit_counter_loop)]
41#![allow(clippy::unnecessary_wraps)]
42#![allow(clippy::default_trait_access)]
43#![allow(clippy::redundant_clone)]
44#![allow(clippy::significant_drop_tightening)]
45#![allow(clippy::or_fun_call)]
46#![allow(clippy::redundant_closure_for_method_calls)]
47
48pub(crate) mod accel;
49pub mod anomaly;
50pub mod calibration;
51pub mod cluster;
52pub(crate) mod constants;
53pub mod dataset;
54pub mod distance;
55pub mod ensemble;
56pub mod error;
57pub mod explain;
58pub mod feature_selection;
59pub mod linear;
60pub(crate) mod matrix;
61pub mod metrics;
62pub mod naive_bayes;
63pub mod neighbors;
64pub mod neural;
65pub mod partial_fit;
66pub mod pipeline;
67pub mod preprocess;
68pub(crate) mod rng;
69pub mod search;
70pub mod sparse;
71pub mod split;
72pub mod svm;
73pub mod text;
74pub mod tree;
75pub(crate) mod version;
76pub mod weights;
77
78#[cfg(feature = "mmap")]
79pub mod mmap;
80#[cfg(feature = "experimental")]
81pub mod onnx;
82#[cfg(feature = "polars")]
83pub mod polars_interop;
84
85/// Convenience re-exports for common usage.
86pub mod prelude {
87    pub use crate::anomaly::IsolationForest;
88    pub use crate::calibration::{
89        CalibratedClassifierCV, CalibrationMethod, IsotonicRegression, PlattScaling,
90    };
91    pub use crate::cluster::{
92        silhouette_score, AgglomerativeClustering, Dbscan, Hdbscan, KMeans, Linkage,
93        MiniBatchKMeans,
94    };
95    pub use crate::dataset::{ColumnStats, Dataset};
96    pub use crate::ensemble::{StackingClassifier, Voting, VotingClassifier};
97    pub use crate::error::ScryLearnError;
98    pub use crate::explain::{ensemble_tree_shap, permutation_importance, tree_shap};
99    pub use crate::feature_selection::{f_classif, ScoreFn, SelectKBest, VarianceThreshold};
100    pub use crate::linear::{
101        ElasticNet, LassoRegression, LinearRegression, LogisticRegression, Penalty, Ridge, Solver,
102    };
103    pub use crate::matrix::DenseMatrix;
104    pub use crate::metrics::{
105        accuracy, adjusted_rand_index, balanced_accuracy, calinski_harabasz_score,
106        classification_report, cohen_kappa_score, confusion_matrix, davies_bouldin_score,
107        explained_variance_score, f1_score, log_loss, mean_absolute_percentage_error,
108        mean_squared_error, pr_curve, precision, r2_score, recall, roc_auc_score, roc_curve,
109        ClassMetrics, ClassificationReport, ConfusionMatrix, PrCurve, RocCurve,
110    };
111    #[cfg(feature = "mmap")]
112    pub use crate::mmap::{save_scry, MmapDataset};
113    pub use crate::naive_bayes::{BernoulliNB, GaussianNb, MultinomialNB};
114    pub use crate::neighbors::{
115        Algorithm, DistanceMetric, KdTree, KnnClassifier, KnnRegressor, WeightFunction,
116    };
117    pub use crate::neural::{
118        Activation, BackwardOutput, CallbackAction, Layer, MLPClassifier, MLPRegressor,
119        OptimizerKind, TrainingCallback,
120    };
121    #[cfg(feature = "experimental")]
122    pub use crate::neural::{Conv2D, Flatten, MaxPool2D};
123    pub use crate::partial_fit::PartialFit;
124    pub use crate::pipeline::Pipeline;
125    pub use crate::preprocess::{
126        ColumnTransformer, DropStrategy, LabelEncoder, MinMaxScaler, Norm, Normalizer,
127        OneHotEncoder, Pca, PolynomialFeatures, RobustScaler, SimpleImputer, StandardScaler,
128        Strategy, Transformer, UnknownStrategy,
129    };
130    pub use crate::search::{
131        BayesSearchCV, CvResult, GridSearchCV, ParamDistribution, ParamGrid, ParamSpace,
132        ParamValue, RandomizedSearchCV, Tunable,
133    };
134    pub use crate::sparse::{CscMatrix, CsrMatrix};
135    pub use crate::split::{
136        cross_val_predict, cross_val_score, cross_val_score_stratified, group_k_fold,
137        repeated_cross_val_score, stratified_split, time_series_split, train_test_split,
138        RepeatedKFold, ScoringFn,
139    };
140    #[cfg(feature = "experimental")]
141    pub use crate::svm::{Gamma, Kernel, KernelSVC, KernelSVR};
142    pub use crate::svm::{LinearSVC, LinearSVR};
143    pub use crate::text::sparse_to_dataset;
144    pub use crate::tree::{
145        DecisionTreeClassifier, DecisionTreeRegressor, GradientBoostingClassifier,
146        GradientBoostingRegressor, HistGradientBoostingClassifier, HistGradientBoostingRegressor,
147        RandomForestClassifier, RandomForestRegressor, RegressionLoss, SplitCriterion,
148    };
149    pub use crate::weights::ClassWeight;
150}