watex.utils.scaley#

watex.utils.scaley(y, x=None, deg=None, func=None)[source]#

Scaling value using a fitting curve.

Create polyfit function from a specifc data points x to correct y values.

Parameters:
  • y – array-like of y-axis. Is the array of value to be scaled.

  • x – array-like of x-axis. If x is given, it should be the same length as y, otherwise and error will occurs. Default is None.

  • func – callable - The model function, f(x, ...). It must take the independent variable as the first argument and the parameters to fit as separate remaining arguments. func can be a linear function i.e for f(x)= ax +b where a is slope and b is the intercept value. It is recommended according to the y value distribution to set up a custom function for better fitting. If func is given, the deg is not needed.

  • deg – polynomial degree. If value is None, it should be computed using the length of extrema (local and/or global) values.

Returns:

  • y: array scaled - projected sample values got from f.

  • x: new x-axis - new axis x_new generated from the samples.

  • linear of polynomial function f

References:

Wikipedia, Curve fitting, https://en.wikipedia.org/wiki/Curve_fitting Wikipedia, Polynomial interpolation, https://en.wikipedia.org/wiki/Polynomial_interpolation

Example:
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from watex.exmath import scale_values
>>> rdn = np.random.RandomState(42)
>>> x0 =10 * rdn.rand(50)
>>> y = 2 * x0  +  rnd.randn(50) -1
>>> plt.scatter(x0, y)
>>> yc, x , f = scale_values(y)
>>> plt.plot(x, y, x, yc)