watex.utils.smoothing#
- watex.utils.smoothing(ar, /, drop_outliers=True, ma=True, absolute=False, interpolate=False, axis=0, view=False, fig_size=(7, 7), xlabel=None, ylabel=None, cmap='binary')[source]#
Smooth data along axis.
- Parameters:
ar (ArrayLike 1d or 2d) – One dimensional or two dimensional array.
drop_outliers (bool, default=True) – Remove the outliers in the data before smoothing along the given axis
ma (bool, default=True,) – Use the moving average for smoothing array value along axis. This seems more realistic rather than using only the scaling method.
absolute (bool, default=False,) – keep positive the extrapolated scaled values. Indeed, when scaling data, negative value can be appear due to the polyfit function. to absolute this value, set
absolute=True. Note that converting to values to positive must be considered as the last option when values in the array must be positive.axis (int, default=0) – Axis along with the data must be smoothed. The default is the along the row.
view (bool, default =False) – Visualize the two dimensional raw and smoothing grid.
xlabel (str, optional) – Label of x
ylabel (str, optional) – label of y
fig_size (tuple , default=(7, 5)) – Matplotlib figure size
cmap (str, default='binary') – Matplotlib.colormap to manage the view color
- Returns:
arr0 – Smoothed array value.
- Return type:
ArrayLike
Examples
>>> import numpy as np >>> from watex.utils.exmath import smoothing >>> # add Guassian Noises >>> np.random.seed (42) >>> ar = np.random.randn (20, 7 ) * 20 + np.random.normal ( 20, 7 ) >>> ar [:3, :3 ] array([[ 31.5265026 , 18.82693352, 34.5459903 ], [ 36.94091413, 12.20273182, 32.44342041], [-12.90613711, 10.34646896, 1.33559714]]) >>> arc = smoothing (ar, view =True , ma =False ) >>> arc [:3, :3 ] array([[32.20356863, 17.18624398, 41.22258603], [33.46353806, 15.56839464, 19.20963317], [23.22466498, 13.8985316 , 5.04748584]]) >>> arcma = smoothing (ar, view =True )# ma=True by default >>> arcma [:3, :3 ] array([[23.96547827, 8.48064226, 31.81490918], [26.21374675, 13.33233065, 12.29345026], [22.60143346, 16.77242118, 2.07931194]]) >>> arcma_1 = smoothing (ar, view =True, axis =1 ) >>> arcma_1 [:3, :3 ] array([[18.74017857, 26.91532187, 32.02914421], [18.4056216 , 21.81293014, 21.98535213], [-1.44359989, 3.49228057, 7.51734762]])