[Python] Have only 2 classes but why am I getting ValueError: Target is multiclass but average...

Discussão em 'Python' iniciado por Stack, Janeiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying build an employee churn prediction model using GridSearchCV on OneClassSVM. My code is as below:

    from sklearn.svm import OneClassSVM
    from sklearn.model_selection import GridSearchCV
    from sklearn.metrics import precision, recall, f1_score

    grid = {'nu' : [0.02, 0.03],
    'kernel' : ['poly', 'sigmoid', 'linear', 'rbf'],
    'degree' : [1,3,5,7],
    'gamma' : [.01, .1, 1, 10, 500]
    'coeff0' : [1,2,3]
    }

    mod = GridSearchCV(OneClassSVM(),
    grid,
    cv = 3,
    scoring = ['f1', 'precision', 'recall'],
    refit = 'f1',
    return_train_score = True)


    mod.fit(x_train, y_train)

    Here the y has only 0s and 1s (essentially resigned or not), but not sure why I am getting:

    ValueError: Target is multiclass but average='binary'. Please choose another average setting, one of [None, 'micro', 'macro', 'weighted']

    Can someone please help me with this.

    Continue reading...

Compartilhe esta Página