Home > Blockchain >  LightGBM binary classification model: predicted score to class probability
LightGBM binary classification model: predicted score to class probability

Time:10-10

I'm training a LGBM model on a classification (binary) dataset.

import lightgbm as lgb
def lgb_train(train_set, features, train_label_col, sample_weight_col=None, hyp = hyp):
    train_data = lgb.Dataset(data=train_set[features], label=train_set[train_label_col],)
    model = lgb.train(
        train_set=train_data,
        params=hyp,
        num_boost_round=hyp['num_boost_round'],
    )        
    return model

preds = np.array(model.predict(test_features))

Now, the problem is: when I call the predict function, I get a score [0.00012, 0.0035, 0.0000048], how can I calculate the probabilities of each class?

CodePudding user response:

As you mentioned in the comment section, you have 3 samples in your test_features and you got 3 scores from model.predict, those will be the probabilities for each sample.

Ref: https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.LGBMClassifier.html#lightgbm.LGBMClassifier.predict

CodePudding user response:

The model predicts the probability of class 1.

Ref: https://github.com/microsoft/LightGBM/issues/5352

  • Related