def get_binary_threshold_cv(
    scores: np.ndarray,
    labels: np.ndarray,
    objective: METRIC_FN,
    num_splits: int = 5,
    num_repeats: int = 1,
    random_state: int = 42,
):
    """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_splits: number of splits to use for cross-validation
        num_repeats: number of repeats to use for cross-validation
        random_state: random state to use for cross-validation

    Returns:
        tuple with best found objective score and threshold
    """
    rkf = RepeatedStratifiedKFold(
        n_splits=num_splits, n_repeats=num_repeats, random_state=random_state
    )
    fold_metrics, fold_thresholds = [], []

    for train_index, valid_index in rkf.split(labels, labels):
        labels_train, labels_valid = labels[train_index], labels[valid_index]
        scores_train, scores_valid = scores[train_index], scores[valid_index]

        _, best_threshold = get_binary_threshold(
            labels=labels_train, scores=scores_train, objective=objective
        )

        valid_predictions = (scores_valid >= best_threshold).astype(np.int32)
        best_metric_value = objective(labels_valid, valid_predictions)

        fold_metrics.append(best_metric_value)
        fold_thresholds.append(best_threshold)

    return np.mean(fold_metrics), np.mean(fold_thresholds)
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_splits: number of splits to use for cross-validation
        num_repeats: number of repeats to use for cross-validation
        random_state: random state to use for cross-validation

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