mlnext.score.apply_threshold#

mlnext.score.apply_threshold(x: ndarray, *, threshold: float = 0.5, pos_label: int = 1) ndarray[source]#

Applies threshold t to x. Values that are greater than or equal than the threshold are changed to pos_label and below to 1 - pos_label.

Parameters:
  • x (np.ndarray) – Input array.

  • t (float) – Threshold. Defaults to 0.5.

  • pos_label (int) – Label for the class above the threshold. Defaults to 1. The other labels is 1 - pos_label. Should be either 1 or 0.

Returns:

Returns the result of the threshold operation.

Return type:

np.ndarray

Example

>>> apply_threshold(np.array([0.1, 0.4, 0.8, 1.0]), threshold=0.5)
np.ndarray([0, 0, 0, 1, 1])