pub fn min_max_scale(
features: &Array2<f64>,
) -> Result<(Array2<f64>, Scaler), DatasetError>Expand description
Rescale each feature column into the [0, 1] range.
This is min-max scaling, (value - min) / (max - min), applied per column.
Prefer it over standardize when a bounded range matters more than a
comparable spread. Use it for pixel-like features (digits), or as input to a
model that expects [0, 1].
As with standardize, the minimum and maximum come from the finite
values of each column. Non-finite entries stay untouched. A constant column
maps to all zeros rather than dividing by 0.
§Parameters
features- The numeric feature matrix, shape(n_samples, n_features).
§Returns
(Array2<f64>, Scaler)- The rescaled matrix, and the fitted per-column statistics to replay on later data withapply_scaler.
§Errors
DatasetError::ValidationError- Returns this whenfeatureshas no rows or no columns.
§Example
use dataset_ml::preprocessing::min_max_scale;
use ndarray::array;
let features = array![[1.0, -5.0], [3.0, 5.0]];
let (scaled, _scaler) = min_max_scale(&features).unwrap();
assert_eq!(scaled, array![[0.0, 0.0], [1.0, 1.0]]);