Class 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 using optRange. the range defaults to 0...1.

    After fitting the scaler the fitted values are attached to the same NDManager as the input array.

    • Constructor Detail

      • MinMaxScaler

        public MinMaxScaler()
    • 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 scaling
        axises - 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 range
        maxRange - 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 interface java.lang.AutoCloseable