Skip to content

use class_weight='auto' and multi_class='multinomial' in LogisticRegression cause UnboundLocalError in line 637 of logistic.py #5415

@luoq

Description

@luoq

code to reproduce

from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
X, y = make_classification(n_classes=5, n_informative=5, random_state=42)
model = LogisticRegression(multi_class='multinomial', class_weight='auto', solver='lbfgs')
model.fit(X, y)

innermost exception

/home/qiang.luo/.local/lib/python3.4/site-packages/sklearn/linear_model/logistic.py in logistic_regression_path(X, y, pos_class, Cs, fit_intercept, max_iter, tol, verbose, solver, coef, copy, class_weight, dual, penalty, intercept_scaling, multi_class, random_state, check_input, max_squared_sum, sample_weight)
    635     if class_weight == "auto":
    636         class_weight_ = compute_class_weight(class_weight, mask_classes,
--> 637                                              y_bin)
    638         sample_weight *= class_weight_[le.fit_transform(y_bin)]
    639 

UnboundLocalError: local variable 'y_bin' referenced before assignment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions