Statistics: keras_proba.stats¶
Percentiles and quantiles, ported from TensorFlow Probability.
percentile ¶
Computes the q-th percentile(s) of x.
Given a vector x, the q-th percentile is the value q / 100 of the way
from the minimum to the maximum in a sorted copy of x. The two nearest
neighbors and interpolation determine the result when the normalized rank
does not match a sample exactly. Compare to numpy.percentile.
Example:
x = [1.0, 2.0, 3.0, 4.0]
percentile(x, q=30.0) # 2.0
percentile(x, q=30.0, interpolation="linear") # 1.9
percentile(x, q=[30.0, 70.0], interpolation="lower") # [1.0, 3.0]
percentile([[1.0, 2.0], [3.0, 4.0]], q=100.0, axis=[0]) # [3.0, 4.0]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric tensor with at least one dimension. |
required | |
q
|
Scalar or 1-D percentile(s) in |
required | |
axis
|
Int or list of ints: the axes indexing samples. If |
None
|
|
interpolation
|
One of |
None
|
|
keepdims
|
Whether to keep the reduced axes with size 1. |
False
|
Returns:
| Type | Description |
|---|---|
|
Tensor whose leading |
|
|
followed by the dimensions of |
quantiles ¶
Multi-backend percentiles and quantiles in Keras 3.
Ported from TensorFlow Probability's tensorflow_probability/python/stats/quantiles.py
(percentile and quantiles). The requested percentiles q must be concrete
(Python or NumPy values), since the gathered indices are computed statically.
__cached__
module-attribute
¶
__cached__ = '/home/runner/work/keras-proba/keras-proba/keras_proba/stats/__pycache__/quantiles.cpython-312.pyc'
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
__doc__
module-attribute
¶
__doc__ = "Multi-backend percentiles and quantiles in Keras 3.\n\nPorted from TensorFlow Probability's `tensorflow_probability/python/stats/quantiles.py`\n(`percentile` and `quantiles`). The requested percentiles `q` must be concrete\n(Python or NumPy values), since the gathered indices are computed statically.\n"
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
__file__
module-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
__name__
module-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
__package__
module-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
percentile ¶
Computes the q-th percentile(s) of x.
Given a vector x, the q-th percentile is the value q / 100 of the way
from the minimum to the maximum in a sorted copy of x. The two nearest
neighbors and interpolation determine the result when the normalized rank
does not match a sample exactly. Compare to numpy.percentile.
Example:
x = [1.0, 2.0, 3.0, 4.0]
percentile(x, q=30.0) # 2.0
percentile(x, q=30.0, interpolation="linear") # 1.9
percentile(x, q=[30.0, 70.0], interpolation="lower") # [1.0, 3.0]
percentile([[1.0, 2.0], [3.0, 4.0]], q=100.0, axis=[0]) # [3.0, 4.0]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric tensor with at least one dimension. |
required | |
q
|
Scalar or 1-D percentile(s) in |
required | |
axis
|
Int or list of ints: the axes indexing samples. If |
None
|
|
interpolation
|
One of |
None
|
|
keepdims
|
Whether to keep the reduced axes with size 1. |
False
|
Returns:
| Type | Description |
|---|---|
|
Tensor whose leading |
|
|
followed by the dimensions of |
quantiles ¶
Computes num_quantiles + 1 cut points of x along axis.
The cut points (c0, ..., cn) divide the samples into num_quantiles
intervals [c0, c1), ..., [c_{n-1}, cn] with roughly equal numbers of
samples; c0 is the minimum and cn the maximum.
Example:
x = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
quantiles(x, num_quantiles=4) # [0., 2., 5., 8., 10.]
quantiles(x, num_quantiles=4, interpolation="linear") # [0., 2.5, 5., 7.5, 10.]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric tensor with at least one dimension. |
required | |
num_quantiles
|
Number of intervals. |
required | |
axis
|
Int or list of ints: the axes indexing samples. If |
None
|
|
interpolation
|
See |
None
|
|
keepdims
|
Whether to keep the reduced axes with size 1. |
False
|
Returns:
| Type | Description |
|---|---|
|
Tensor of shape |
|
|
that of |