Exemple #1
0
class MaxAbsScaler(FeatureTransformAlgorithm):
    r"""Implementation of feature scaling by its maximum absolute value.
    
    Date:
        2020

    Author:
        Luka Pečnik

    License:
        MIT
    
    Documentation:
        https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MaxAbsScaler.html#sklearn.preprocessing.MaxAbsScaler

    See Also:
        * :class:`niaaml.preprocessing.feature_transform.FeatureTransformAlgorithm`
    """
    Name = 'Maximum Absolute Scaler'

    def __init__(self, **kwargs):
        r"""Initialize MaxAbsScaler.
        """
        super(MaxAbsScaler, self).__init__()
        self.__max_abs_scaler = MAS()

    def fit(self, x, **kwargs):
        r"""Fit implemented transformation algorithm.

        Arguments:
            x (pandas.core.frame.DataFrame): n samples to fit transformation algorithm.
        """
        self.__max_abs_scaler.fit(x)

    def transform(self, x, **kwargs):
        r"""Transforms the given x data.

        Arguments:
            x (pandas.core.frame.DataFrame): Data to transform.

        Returns:
            pandas.core.frame.DataFrame: Transformed data.
        """

        return self.__max_abs_scaler.transform(x)

    def to_string(self):
        r"""User friendly representation of the object.

        Returns:
            str: User friendly representation of the object.
        """
        return FeatureTransformAlgorithm.to_string(self).format(
            name=self.Name,
            args=self._parameters_to_string(
                self.__max_abs_scaler.get_params()))
Exemple #2
0
# Importing data
cwd = Path(os.getcwd())
p = cwd / 'DATA'
data = pd.read_csv(p / "yacht_hydro.csv")

# boxplots
#for col in data.columns:
#    plt.figure()
#    plt.boxplot(data[col])
#    plt.title(col)

# scaling the data
data_scaled = data.copy()
scaler = MaxAbsScaler()
data_scaled.loc[:, :] = scaler.fit_transform(data)
scaler_params = scaler.get_params()

# We will eventually need the physical (unscaled) data to display the results
extract_scaling_function = np.ones((1, data_scaled.shape[1]))
extract_scaling_function = scaler.inverse_transform(extract_scaling_function)

pd.set_option('display.max_columns', 7)
#print(data_scaled.iloc[:3,:])

## Shuffling data
#data = data.sample(frac=1,random_state=0).reset_index(drop=True)
#
#
## Separating inputs from outputs
#X_data = np.array(data.iloc[:,:6])
#y_data = np.array(data.iloc[:,-1])