def get_binary_threshold(
    scores: np.ndarray,
    labels: np.ndarray,
    objective: METRIC_FN,
    num_thresholds: int = 100,
) -> Tuple[float, float]:
    """Finds best threshold for binary classification task
    based on cross-validation estimates.

    Args:
        scores: estimated per-class scores/probabilities predicted by the model,
            numpy array with shape [num_examples, ]
        labels: ground truth labels, numpy array with shape [num_examples, ]
        objective: callable function, metric which we want to maximize
        num_thresholds: number of thresholds ot try for each class

    Returns:
        tuple with best found objective score and threshold
    """
    thresholds = np.linspace(scores.min(), scores.max(), num=num_thresholds)
    metric_values = []

    for threshold in thresholds:
        predictions = (scores >= threshold).astype(np.int32)
        if np.sum(predictions) > 0:
            metric_value = objective(labels, predictions)
            metric_values.append(metric_value)
        else:
            metric_values.append(0.0)

    if np.max(metric_values) == 0.0:
        best_metric_value = 0.0
        best_threshold = 1.0
    else:
        best_metric_value = metric_values[np.argmax(metric_values)]
        best_threshold = thresholds[np.argmax(metric_values)]

    return best_metric_value, best_threshold
Finds best threshold for binary classification task
    based on cross-validation estimates.

    Args:
        scores: estimated per-class scores/probabilities predicted by the model,
            numpy array with shape [num_examples, ]
        labels: ground truth labels, numpy array with shape [num_examples, ]
        objective: callable function, metric which we want to maximize
        num_thresholds: number of thresholds ot try for each class

    Returns:
        tuple with best found objective score and threshold
    
catalyst/contrib/utils/thresholds.py