MinMaxScaler
Module: strata.preprocessing • Kind: struct • Traits: Copyable, Movable, Serializable, Transformer
Source: strata/preprocessing/scaler.mojo
struct MinMaxScaler[compute_dtype: DType = DType.float64](Copyable, Movable, Serializable, Transformer)from strata.preprocessing import MinMaxScalerTransform features by scaling each feature to a specified range.
Scales and translates each feature individually such that it is in the given range on the training set, e.g. between zero and one:
Parameters (Compile-Time)
Section titled “Parameters (Compile-Time)”| Parameter | Description |
|---|---|
compute_dtype |
Computational precision data type. Default DType.float64. |
Constructors
Section titled “Constructors”def __init__( out self, feature_range_min: Scalar[Self.compute_dtype] = 0.0, feature_range_max: Scalar[Self.compute_dtype] = 1.0, clip: Bool = False,)Initialize the MinMaxScaler.
| Argument | Type | Description |
|---|---|---|
feature_range_min |
Scalar[Self.compute_dtype] |
Lower bound of the transformed range. Default 0.0. |
feature_range_max |
Scalar[Self.compute_dtype] |
Upper bound of the transformed range. Default 1.0. |
clip |
Bool |
Whether to clip transformed values to the feature range. Default False. |
Attributes
Section titled “Attributes”| Attribute | Description |
|---|---|
data_min_ |
Per-feature minimum seen in the training data. |
data_max_ |
Per-feature maximum seen in the training data. |
data_range_ |
Per-feature range () seen in the data. |
scale_ |
Per-feature relative scaling factor. |
min_ |
Per-feature minimum adjustment. |
is_fitted |
Boolean flag indicating if estimator has been fitted. |
Methods Overview
Section titled “Methods Overview”| Method | Description |
|---|---|
MinMaxScaler.fit() |
Compute fitted parameters from input matrix X. |
MinMaxScaler.transform() |
Transform input features using the fitted parameters. |
MinMaxScaler.fit_transform() |
Fit the estimator to X and return the transformed output. |
MinMaxScaler.inverse_transform() |
Undoes the scaling of X according to the fitted feature range. |
MinMaxScaler.serialize() |
Serializes MinMaxScaler parameters and fitted state into BufferWriter. |
MinMaxScaler.deserialize() |
Deserializes MinMaxScaler from BufferReader. |
Method Details
Section titled “Method Details”MinMaxScaler.fit()
Section titled “MinMaxScaler.fit()”def fit[in_dtype: DType](mut self, X: Matrix[in_dtype])
def fit[feat_dtype: DType, target_dtype: DType]( mut self, dataset: Dataset[feat_dtype, target_dtype],)Overload Note: This method accepts either a standard
X: Matrixor a unifieddataset: Datasetcontainer.
Compute fitted parameters from input matrix X.
| Parameter | Type | Description |
|---|---|---|
X |
Matrix[in_dtype] |
Feature matrix. |
dataset |
Dataset[feat_dtype, target_dtype] |
Dataset container holding feature matrix. (Can be provided alternatively in place of X) |
MinMaxScaler.transform()
Section titled “MinMaxScaler.transform()”def transform[in_dtype: DType]( self, X: Matrix[in_dtype],) -> Matrix[in_dtype]
def transform[feat_dtype: DType, target_dtype: DType]( self, dataset: Dataset[feat_dtype, target_dtype],) -> Dataset[ feat_dtype, target_dtype ]Overload Note: This method accepts either a standard
X: Matrixor a unifieddataset: Datasetcontainer.
Transform input features using the fitted parameters.
| Parameter | Type | Description |
|---|---|---|
X |
Matrix[in_dtype] |
Feature matrix. |
dataset |
Dataset[feat_dtype, target_dtype] |
Dataset container holding feature matrix. (Can be provided alternatively in place of X) |
Returns: Matrix[in_dtype]
MinMaxScaler.fit_transform()
Section titled “MinMaxScaler.fit_transform()”def fit_transform[in_dtype: DType]( mut self, X: Matrix[in_dtype],) -> Matrix[in_dtype]
def fit_transform[feat_dtype: DType, target_dtype: DType]( mut self, dataset: Dataset[feat_dtype, target_dtype],) -> Dataset[ feat_dtype, target_dtype ]Overload Note: This method accepts either a standard
X: Matrixor a unifieddataset: Datasetcontainer.
Fit the estimator to X and return the transformed output.
| Parameter | Type | Description |
|---|---|---|
X |
Matrix[in_dtype] |
Feature matrix. |
dataset |
Dataset[feat_dtype, target_dtype] |
Dataset container holding feature matrix. (Can be provided alternatively in place of X) |
Returns: Matrix[in_dtype]
MinMaxScaler.inverse_transform()
Section titled “MinMaxScaler.inverse_transform()”def inverse_transform[in_dtype: DType]( self, X: Matrix[in_dtype],) -> Matrix[in_dtype]Undoes the scaling of X according to the fitted feature range.
| Parameter | Type | Description |
|---|---|---|
X |
Matrix[in_dtype] |
Feature matrix. |
Returns: Matrix[in_dtype]
MinMaxScaler.serialize()
Section titled “MinMaxScaler.serialize()”def serialize(self, mut writer: BufferWriter)Serializes MinMaxScaler parameters and fitted state into BufferWriter.
MinMaxScaler.deserialize()
Section titled “MinMaxScaler.deserialize()”def deserialize(mut reader: BufferReader) -> SelfDeserializes MinMaxScaler from BufferReader.
Returns: Self
Section titled “Returns: Self”Example
Section titled “Example”from strata.preprocessing import MinMaxScalerfrom strata.core import Matrix
var scaler = MinMaxScaler[DType.float64](feature_range_min=0.0, feature_range_max=1.0)scaler.fit(X_train)var X_scaled = scaler.transform(X_train)