View Source Scholar.Preprocessing.MinMaxScaler (Scholar v0.3.1)
Scales a tensor by dividing each sample in batch by maximum absolute value in the batch
Centering and scaling happen independently on each feature by computing the relevant statistics on the samples in the training set. Maximum absolute value then is stored to be used on new samples.
Summary
Functions
Compute the maximum absolute value of samples to be used for later scaling.
Standardizes the tensor by removing the mean and scaling to unit variance.
Performs the standardization of the tensor using a fitted scaler.
Functions
Compute the maximum absolute value of samples to be used for later scaling.
Options
:axes
- Axes to calculate the max absolute value over. By default the absolute values are calculated between the whole tensors.:min_bound
- The lower boundary of the desired range of transformed data. The default value is0
.:max_bound
- The upper boundary of the desired range of transformed data. The default value is1
.
Return values
Returns a struct with the following parameters:
min_data
: the calculated minimum value of samples.max_data
: the calculated maximum value of samples.min_bound
: The lower boundary of the desired range of transformed data.max_bound
: The upper boundary of the desired range of transformed data.
Examples
iex> t = Nx.tensor([[1, -1, 2], [2, 0, 0], [0, 1, -1]])
iex> Scholar.Preprocessing.MinMaxScaler.fit(t)
%Scholar.Preprocessing.MinMaxScaler{
min_data: Nx.tensor(
[
[-1]
]
),
max_data: Nx.tensor(
[
[2]
]
),
min_bound: Nx.tensor(
0
),
max_bound: Nx.tensor(
1
)
}
Standardizes the tensor by removing the mean and scaling to unit variance.
Examples
iex> t = Nx.tensor([[1, -1, 2], [2, 0, 0], [0, 1, -1]])
iex> Scholar.Preprocessing.MinMaxScaler.fit_transform(t)
#Nx.Tensor<
f32[3][3]
[
[0.6666666865348816, 0.0, 1.0],
[1.0, 0.3333333432674408, 0.3333333432674408],
[0.3333333432674408, 0.6666666865348816, 0.0]
]
>
Performs the standardization of the tensor using a fitted scaler.
Examples
iex> t = Nx.tensor([[1, -1, 2], [2, 0, 0], [0, 1, -1]])
iex> scaler = Scholar.Preprocessing.MinMaxScaler.fit(t)
iex> Scholar.Preprocessing.MinMaxScaler.transform(scaler, t)
#Nx.Tensor<
f32[3][3]
[
[0.6666666865348816, 0.0, 1.0],
[1.0, 0.3333333432674408, 0.3333333432674408],
[0.3333333432674408, 0.6666666865348816, 0.0]
]
>
iex> t = Nx.tensor([[1, -1, 2], [2, 0, 0], [0, 1, -1]])
iex> scaler = Scholar.Preprocessing.MinMaxScaler.fit(t)
iex> new_tensor = Nx.tensor([[0.5, 1, -1], [0.3, 0.8, -1.6]])
iex> Scholar.Preprocessing.MinMaxScaler.transform(scaler, new_tensor)
#Nx.Tensor<
f32[2][3]
[
[0.5, 0.6666666865348816, 0.0],
[0.43333330750465393, 0.5999999642372131, -0.20000000298023224]
]
>