skg.util

Shared utility functions used by the fitting routines.

Functions

preprocess(x[, copy, float, axis]) Ensure that x is a properly formatted numpy array.
preprocess_npair(x, y[, axis, xcopy, ycopy]) Ensure that x and y are floating point arrays of compatible size.
preprocess_pair(x, y[, sorted, xcopy, ycopy]) Ensure that x and y are floating point arrays of the same size, ranked in increasing order by x.
skg.util.preprocess(x, copy=False, float=False, axis=None)[source]

Ensure that x is a properly formatted numpy array.

Proper formatting means at least one dimension, and may include optional copying, reshaping and coersion into a floating point datatype.

Parameters:
  • x (array-like) – The array to process. If not already a numpy array, it will be converted to one.
  • copy (bool, optional) – If True, a copy is made regardless of whether x is already a numpy array or not. The default is False.
  • float (bool, optional) – If True, and x is not an inexact array already (numpy.float16, numpy.float32, numpy.float64, numpy.float96, numpy.float128, etc), coerce to be of type numpy.float_. Defaults to False.
  • axis (int, optional) – If specified, the specified axis is moved to the end of the shape. Default is to return x without reshaping.
Returns:

x – Processed version of the input.

Return type:

ndarray

skg.util.preprocess_npair(x, y, axis=-1, xcopy=False, ycopy=False)[source]

Ensure that x and y are floating point arrays of compatible size.

x is an array containing vectors along dimension axis. y contains scalar elements. The shape of y must match that of x exactly except for axis.

Parameters:
  • x (array-like) – The vector x-values of the data points. The array will be converted to floating point, and raveled along all dimensions but axis, which will be the last dimension.
  • y (array-like) – The y-values of the data points corresponding to x. Must have one fewer dimension than x, and its shape must match all elements of x’s shape except axis. Will be converted to floating point and raveled.
  • xcopy (bool, optional) – Ensure that x gets copied even if it is already an array. The default is to leave arrays untouched as much as possible.
  • ycopy (bool) – Ensure that y gets copied even if it is already an array. The default is to leave arrays untouched as much as possible.
Returns:

x, y – Processed versions of the inputs.

Return type:

ndarray

See also

preprocess_pair
For cases when x and y both contain scalars, and are the exact same size.
skg.util.preprocess_pair(x, y, sorted=True, xcopy=False, ycopy=False)[source]

Ensure that x and y are floating point arrays of the same size, ranked in increasing order by x.

Parameters:
  • x (array-like) – The x-values of the data points. The array will be converted to floating point, raveled and sorted, only as necessary.
  • y (array-like) – The y-values of the data points corresponding to x. Must be the same size as x. Will be converted to floating point and raveled only as necessary. Will be sorted if x gets sorted.
  • sorted (bool) – Set to True if x is already monotonically increasing or decreasing. If False, x will be sorted into increasing order, and y will be sorted along with it.
  • xcopy (bool, optional) – Ensure that x gets copied even if it is already an array. The default is to leave arrays untouched as much as possible.
  • ycopy (bool) – Ensure that y gets copied even if it is already an array. The default is to leave arrays untouched as much as possible.
Returns:

x, y – Processed versions of the inputs.

Return type:

ndarray

See also

preprocess_npair
Similar function but for x containing vectors and y scalars.