Repository: scikit-learn/scikit-learn
File: sklearn/linear_model/_logistic.py (Python)

Code before:
        classes=classes,
        Cs=Cs,
        l1_ratio=l1_ratio,
        fit_intercept=fit_intercept,
        solver=solver,
        max_iter=max_iter,
        class_weight=class_weight,
        tol=tol,
        verbose=verbose,
        dual=dual,
        penalty=penalty,
        intercept_scaling=intercept_scaling,
        random_state=random_state,
        check_input=False,
        max_squared_sum=max_squared_sum,
        sample_weight=sw_train,
    )

    log_reg = LogisticRegression(solver=solver)

    # The score method of Logistic Regression has a classes_ attribute.
    log_reg.classes_ = classes

    scores = list()

    # Prepare the call the get the score per fold: calc_score
    scoring = get_scorer(scoring)
    if scoring is None:

        def calc_score(log_reg):
            return log_reg.score(X_test, y_test, sample_weight=sw_test)

    else:
        is_binary = len(classes) <= 2
        score_params = score_params or {}
        score_params = _check_method_params(X=X, params=score_params, indices=test)
        # We need to pass the classes as "labels" argument to scorers that support
        # it, e.g. scoring = "neg_brier_score", because y_test may not contain all
        # class labels.
        # There are at least 2 possibilities:
        # 1. Metadata routing is enabled: A try except clause is possible with
        #   adding labels to score_params. We could then pass the already instantiated
        #   log_reg instance to scoring.
        # 2. We reconstruct the scorer and pass labels as kwargs explicitly.
        # We implement the 2nd option even if it seems a bit hacky because it works
        # with and without metadata routing.
        if hasattr(scoring, "_score_func"):
            sig = inspect.signature(scoring._score_func).parameters
        else:
            sig = []


Review comment (suggestion):
```suggestion
    # Prepare the call to get the score per fold: calc_score
```

Code after:
        classes=classes,
        Cs=Cs,
        l1_ratio=l1_ratio,
        fit_intercept=fit_intercept,
        solver=solver,
        max_iter=max_iter,
        class_weight=class_weight,
        tol=tol,
        verbose=verbose,
        dual=dual,
        penalty=penalty,
        intercept_scaling=intercept_scaling,
        random_state=random_state,
        check_input=False,
        max_squared_sum=max_squared_sum,
        sample_weight=sw_train,
    )

    log_reg = LogisticRegression(solver=solver)

    # The score method of Logistic Regression has a classes_ attribute.
    log_reg.classes_ = classes

    scores = list()

    # Prepare the call to get the score per fold: calc_score
    scoring = get_scorer(scoring)
    if scoring is None:

        def calc_score(log_reg):
            return log_reg.score(X_test, y_test, sample_weight=sw_test)

    else:
        is_binary = len(classes) <= 2
        score_params = score_params or {}
        score_params = _check_method_params(X=X, params=score_params, indices=test)
        # We need to pass the classes as "labels" argument to scorers that support
        # it, e.g. scoring = "neg_brier_score", because y_test may not contain all
        # class labels.
        # There are at least 2 possibilities:
        # 1. Metadata routing is enabled: A try except clause is possible with
        #   adding labels to score_params. We could then pass the already instantiated
        #   log_reg instance to scoring.
        # 2. We reconstruct the scorer and pass labels as kwargs explicitly.
        # We implement the 2nd option even if it seems a bit hacky because it works
        # with and without metadata routing.
        if hasattr(scoring, "_score_func"):
            sig = inspect.signature(scoring._score_func).parameters
        else:
            sig = []