Class MinMaxScaler
- java.lang.Object
-
- ai.djl.training.util.MinMaxScaler
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class MinMaxScaler extends java.lang.Object implements java.lang.AutoCloseable
Transform arrays by scaling each value to a given range. The desired range of transformed data can be set usingoptRange
. the range defaults to 0...1.After fitting the scaler the fitted values are attached to the same NDManager as the input array.
-
-
Constructor Summary
Constructors Constructor Description MinMaxScaler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
MinMaxScaler
detach()
Detaches this MinMaxScaler fitted value from current NDManager's lifecycle.MinMaxScaler
fit(NDArray data)
Computes the minimum and maximum to be used for later scaling.MinMaxScaler
fit(NDArray data, int[] axises)
Computes the minimum and maximum to be used for later scaling.NDArray
getMax()
Returns the value of fittedMax.NDArray
getMin()
Returns the value of fittedMin.NDArray
inverseTransform(NDArray data)
Undoes the transformation of X according to feature_range.NDArray
inverseTransformi(NDArray data)
Undoes the transformation of X according to feature_range as an in-place operation.MinMaxScaler
optRange(float minRange, float maxRange)
Sets desired range of transformed data.NDArray
transform(NDArray data)
Transforms the data using the previous calculated minimum and maximum.NDArray
transformi(NDArray data)
Transforms the data in-place using the previous calculated minimum and maximum.
-
-
-
Method Detail
-
fit
public MinMaxScaler fit(NDArray data, int[] axises)
Computes the minimum and maximum to be used for later scaling.After fitting the scaler the fitted values are attached to the same NDManager as the input array. reusing the minMaxScaler in the context of other NDManager's is possible by
detach()
the scaler from the NDManager.- Parameters:
data
- used to compute the minimum and maximum used for later scalingaxises
- minimum maximum computation along this axises- Returns:
- the fitted MinMaxScaler
-
fit
public MinMaxScaler fit(NDArray data)
Computes the minimum and maximum to be used for later scaling.After fitting the scaler the fitted values are attached to the same NDManager as the input array. reusing the minMaxScaler in the context of other NDManager's is possible by
detach()
the scaler from the NDManager.- Parameters:
data
- used to compute the minimum and maximum used for later scaling- Returns:
- the fitted MinMaxScaler
-
transform
public NDArray transform(NDArray data)
Transforms the data using the previous calculated minimum and maximum.if
fit()
is not executed yet, then the minimum/maximum is computer based on the input data array and used for later computations. X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0)) X_scaled = X_std * (max - min) + min- Parameters:
data
- to get transformed- Returns:
- the transformed data, the input array is not changed
-
transformi
public NDArray transformi(NDArray data)
Transforms the data in-place using the previous calculated minimum and maximum.if
fit()
is not called before then the minimum/maximum is computer based on the input data array and used for later computations. X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0)) X_scaled = X_std * (max - min) + min- Parameters:
data
- to get transformed- Returns:
- the transformed data (reference to the input data) the input array is changed in-place by this operation
-
inverseTransform
public NDArray inverseTransform(NDArray data)
Undoes the transformation of X according to feature_range.- Parameters:
data
- to get transformed- Returns:
- the transformed array
-
inverseTransformi
public NDArray inverseTransformi(NDArray data)
Undoes the transformation of X according to feature_range as an in-place operation.- Parameters:
data
- to get transformed, the data get changed in-place- Returns:
- the transformed array
-
detach
public MinMaxScaler detach()
Detaches this MinMaxScaler fitted value from current NDManager's lifecycle.this becomes un-managed and it is the user's responsibility to close this. Failure to close the resource might cause your machine to run out of native memory.
After fitting the scaler the fitted values are attached to the same NDManager as the input array.
Re-fitting the scaler after detaching doesn't re-attach the scaler to any NDManager.
- Returns:
- the detached MinMaxScaler (itself) - to use as a fluent API
-
optRange
public MinMaxScaler optRange(float minRange, float maxRange)
Sets desired range of transformed data.- Parameters:
minRange
- min value for desired rangemaxRange
- max value for desired range- Returns:
- the configured MinMaxScaler
-
getMin
public NDArray getMin()
Returns the value of fittedMin.- Returns:
- the fittedMin value
-
getMax
public NDArray getMax()
Returns the value of fittedMax.- Returns:
- the fittedMax value
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
-
-