watex.utils.naive_scaler#
- watex.utils.naive_scaler(X, y=None, *, kind=<class 'sklearn.preprocessing._data.StandardScaler'>, copy=True, with_mean=True, with_std=True, feature_range=(0, 1), clip=False, norm='l2', **fit_params)[source]#
Quick data scaling using both strategies implemented in scikit-learn with StandardScaler and MinMaxScaler.
Function returns scaled frame if dataframe is passed or ndarray. For other scaling, call scikit-learn instead.
- Parameters
X ({array-like, sparse matrix} of shape (n_samples, n_features)) – The data used to compute the mean and standard deviation used for later scaling along the features axis.
y (None) – Ignored.
kind (str, default='StandardScaler') – Kind of data scaling. Can also be [‘MinMaxScaler’, ‘Normalizer’]. The default is ‘StandardScaler’
copy (bool, default=True) – If False, try to avoid a copy and do inplace scaling instead. This is not guaranteed to always work inplace; e.g. if the data is not a NumPy array or scipy.sparse CSR matrix, a copy may still be returned.
with_mean (bool, default=True) – If True, center the data before scaling. This does not work (and will raise an exception) when attempted on sparse matrices, because centering them entails building a dense matrix which in common use cases is likely to be too large to fit in memory.
with_std (bool, default=True) – If True, scale the data to unit variance (or equivalently, unit standard deviation).
feature_range (tuple (min, max), default=(0, 1)) – Desired range of transformed data.
norm ({'l1', 'l2', 'max'}, default='l2') – The norm to use to normalize each non zero sample. If norm=’max’ is used, values will be rescaled by the maximum of the absolute values.
clip (bool, default=False) – Set to True to clip transformed values of held-out data to provided feature range.
fit_params (dict,) – keywords arguments passed to the scikit-learn fitting parameters More details on https://scikit-learn.org/stable/
- Returns
X_sc – Transformed array.
- Return type
{ndarray, sparse matrix} or dataframe of shape (n_samples, n_features)
Examples
>>> import numpy as np >>> import pandas as pd >>> from watex.utils.mlutils import naive_scaler >>> X= np.random.randn (7 , 3 ) >>> X_std = naive_scaler (X ) ... array([[ 0.17439644, 1.55683005, 0.24115109], [-0.59738672, 1.3166854 , 1.23748004], [-1.6815365 , -1.19775838, 0.71381357], [-0.1518278 , -0.32063059, -0.47483155], [-0.41335886, 0.13880519, 0.69258621], [ 1.45221902, -1.03852015, -0.40157981], [ 1.21749443, -0.45541153, -2.00861955]]) >>> # use dataframe >>> Xdf = pd.DataFrame (X, columns =['a', 'c', 'c']) >>> naive_scaler (Xdf , kind='Normalizer') # return data frame ... a c c 0 0.252789 0.967481 -0.008858 1 -0.265161 0.908862 0.321961 2 -0.899863 -0.416231 0.130380 3 0.178203 0.039443 -0.983203 4 -0.418487 0.800306 0.429394 5 0.933933 -0.309016 -0.179661 6 0.795234 -0.051054 -0.604150