# 1.5. The Prelude and Imports
## 1.5.1. Three ways to bring names into scope
### Glob the whole prelude
```rust
use rustyml::prelude::*;
```
This pulls everything into the current scope. It suits getting code written quickly, without having to look up where each item lives.
### Glob a single prelude category
The prelude is split into four submodules, so you can import just what you need:
```rust
use rustyml::prelude::machine_learning::*; // classical estimators, traits, and shared enums
use rustyml::prelude::neural_network::*; // Sequential, History, Tensor, layers, losses, optimizers
use rustyml::prelude::metrics::*; // the evaluation-metric functions and types
use rustyml::prelude::utils::*; // standardize, normalize, scalers, encoders, split
```
Use this when the file you are writing clearly belongs to a single domain.
### Import by exact path
```rust,ignore
use rustyml::machine_learning::LinearRegression;
use rustyml::traits::{Fit, Predict};
use rustyml::metrics::r2_score;
```
Library code that has to be maintained long-term should prefer this style.
## 1.5.2. What the prelude re-exports
The `prelude` is a hand-picked list: it re-exports only the items you reach for often. The tables below show exactly what each prelude submodule re-exports.
### Machine learning
| Estimator traits | `Fit`, `Predict`, `Transform`, `FitTransform` |
| Shared enums | `DistanceCalculationMetric`, `RegularizationType`, `KernelType` |
| Regression | `LinearRegression`, `LeastSquaresSolver` |
| Linear classification | `LogisticRegression`, `generate_polynomial_features` |
| Neighbors | `KNN`, `WeightingStrategy` |
| Trees | `DecisionTree`, `DecisionTreeParams`, `Algorithm` |
| SVM | `SVC`, `LinearSVC` |
| Discriminant analysis | `LDA`, `DiscriminantSolver`, `Shrinkage` |
| Clustering | `KMeans`, `DBSCAN`, `MeanShift`, `estimate_bandwidth` |
| Decomposition | `PCA`, `KernelPCA`, `EigenSolver`, `SVDSolver` |
| Manifold | `TSNE`, `TSNEMethod`, `Init` |
| Anomaly detection | `IsolationForest`, `Contamination` |
### Neural network
| Tensor | `Tensor` (alias for `ArrayD<f32>`) |
| Model | `Sequential` |
| Training history | `History` (one loss per epoch, what `fit` returns) |
| Core layers | `Dense`, `Flatten`, `Activation` |
| Activation layers | `Linear`, `ReLU`, `Sigmoid`, `Softmax`, `Tanh` |
| Convolution | `Conv1D`, `Conv2D`, `Conv3D`, `DepthwiseConv2D`, `SeparableConv2D`, `PaddingType` |
| Pooling | `MaxPooling1D/2D/3D`, `AveragePooling1D/2D/3D`, `GlobalMaxPooling1D/2D/3D`, `GlobalAveragePooling1D/2D/3D` |
| Recurrent | `SimpleRNN`, `LSTM`, `GRU` |
| Regularization | `Dropout`, `SpatialDropout1D/2D/3D`, `GaussianDropout`, `GaussianNoise` |
| Normalization | `BatchNormalization`, `LayerNormalization`, `LayerNormalizationAxis`, `GroupNormalization`, `InstanceNormalization` |
| Losses | `MeanSquaredError`, `MeanAbsoluteError`, `BinaryCrossEntropy`, `CategoricalCrossEntropy`, `SparseCategoricalCrossEntropy` |
| Optimizers | `SGD`, `Adam`, `AdamW`, `RMSprop`, `AdaGrad` |
Note the exact casing on `RMSprop` (lowercase `p`). Activations come in two forms: one is the standalone layers `ReLU`/`Softmax`/`Linear`/`Sigmoid`/`Tanh`. The other is, in any layer that accepts an `Activation` enum, either picking a variant (`Activation::ReLU`, `Activation::Softmax`, `Activation::Linear`, `Activation::Sigmoid`, `Activation::Tanh`) or passing one of those standalone activation layers instead (they `impl Layer` and convert `Into<Activation>`).
For example, one of `Dense::new`'s parameters is `activation: impl Into<Activation>`, so you can pass either an `Activation` enum variant or a standalone activation layer: `Dense::new(3, 8, Activation::ReLU)` and `Dense::new(3, 8, ReLU::new())` are equivalent.
### Metrics
| Types | `ConfusionMatrix`, `MulticlassConfusionMatrix`, `Average` |
| Regression | `mean_squared_error`, `root_mean_squared_error`, `mean_absolute_error`, `median_absolute_error`, `mean_absolute_percentage_error`, `r2_score`, `explained_variance_score` |
| Classification | `accuracy`, `roc_auc`, `roc_curve`, `precision_recall_curve`, `average_precision`, `log_loss`, `cohen_kappa`, `top_k_accuracy` |
| Clustering | `adjusted_rand_index`, `adjusted_mutual_info`, `normalized_mutual_info`, `homogeneity_score`, `completeness_score`, `v_measure_score`, `fowlkes_mallows_score`, `silhouette_score`, `davies_bouldin_score`, `calinski_harabasz_score` |
Unlike the error-propagation design in the rest of the crate, the metric functions panic outright on an error, which keeps the module lightweight; see [5. Model Evaluation](../Chapter-05/5.0._Model_Evaluation.md). Their argument order is `(y_true, y_pred)`, matching scikit-learn.
### Utilities
| Scaling | `standardize`, `StandardizationAxis`, `normalize`, `NormalizationAxis`, `NormalizationOrder`, `StandardScaler`, `MinMaxScaler`, `MaxAbsScaler`, `RobustScaler`, `Normalizer` |
| Label encoding | `to_categorical`, `to_categorical_with_mapping`, `to_sparse_categorical` |
| Splitting | `train_test_split`, `train_test_split_stratified` |
| Traits | `Fit`, `Predict`, `Transform`, `FitTransform` |
## 1.5.3. Feature gates decide what the prelude contains
The `rustyml::prelude` module is always compiled, but each submodule only appears once the matching module feature is enabled. So `use rustyml::prelude::*` does not mean everything RustyML can do — it means everything the features you enabled can do. For what each feature contains, see [1.2 Installation and Feature Flags](./1.2._Installation_and_Feature_Flags.md).
| `machine_learning` | the classical estimators, traits, and shared enums |
| `neural_network` | `Sequential`, `History`, `Tensor`, layers, losses, optimizers |
| `metrics` | the metric functions and the confusion-matrix types |
| `utils` | `standardize`, `normalize`, the whole scaler family, encoders, split functions, the estimator traits |
| `default` (all five modules) | every module |
| `full` | every module |
## 1.5.4. Using fully-qualified paths
To find where an item lives, [docs.rs/rustyml](https://docs.rs/rustyml) is the place to look. Here is a lookup table for the main types:
| `LinearRegression`, `LogisticRegression` | `rustyml::machine_learning::` |
| `KNN`, `DecisionTree`, `SVC`, `LinearSVC`, `LDA` | `rustyml::machine_learning::` |
| `KMeans`, `DBSCAN`, `MeanShift` | `rustyml::machine_learning::` |
| `PCA`, `KernelPCA`, `TSNE`, `IsolationForest`, `Contamination` | `rustyml::machine_learning::` |
| `Fit`, `Predict`, `Transform`, `FitTransform` | `rustyml::traits::` (also re-exported under `rustyml::machine_learning::` and `rustyml::utils::`) |
| `DistanceCalculationMetric` | `rustyml::machine_learning::` or `rustyml::math::` |
| `Sequential`, `History` | `rustyml::neural_network::sequential::` |
| `Tensor` | `rustyml::neural_network::` |
| `Dense`, `Flatten`, `Activation` | `rustyml::neural_network::layers::` |
| `Adam`, `SGD`, `AdamW`, `RMSprop`, `AdaGrad` | `rustyml::neural_network::optimizers::` |
| `MeanSquaredError`, `CategoricalCrossEntropy`, and the rest | `rustyml::neural_network::losses::` |
| `accuracy`, `mean_squared_error`, `r2_score`, and the rest | `rustyml::metrics::` |
| `ConfusionMatrix`, `MulticlassConfusionMatrix`, `Average` | `rustyml::metrics::` |
| `standardize`, `StandardizationAxis` | `rustyml::utils::standardize::` |
| `StandardScaler`, `MinMaxScaler`, `MaxAbsScaler`, `RobustScaler`, `Normalizer` | `rustyml::utils::` (defined in `rustyml::utils::scaler::`) |
| `normalize`, `NormalizationAxis`, `NormalizationOrder` | `rustyml::utils::normalize::` |
| `train_test_split`, `train_test_split_stratified` | `rustyml::utils::train_test_split::` |
| `to_categorical`, `to_sparse_categorical`, and the rest | `rustyml::utils::label_encoding::` |
| `Error`, `RustymlResult` | `rustyml::error::` |
| `set_global_seed`, `clear_global_seed` | `rustyml::` (or `rustyml::random::`) |