1
$\begingroup$

I trained a LGBMClassifier model and saved in a file in this way:


clf = lgb.LGBMClassifier( ... )
clf.fit(X_train, y_train, **fit_params)
clf.booster_.save_model("model1.txt")

##Predictions
y_pred = clf.predict_proba(X_data, num_iteration=clf.best_iteration_)[:, 1]

Now what I want is to use the saved model for another prediction. But if I do this:

## new predictions:
clf_fs = lgb.Booster(model_file='model1.txt')
y_pred2 = clf_fs.predict_proba(X_data2, num_iteration=clf_fs.best_iteration_)[:, 1]

I got an error as

AttributeError: 'Booster' object has no attribute 'predict_proba'

I understand that cls_fs is an object of class Booster and not of a class LGBMClassifier, and that I can use clf_fs.predict(), but how I can get back a LGBMClassifier object from the saved booster file and all its specific attributes?

$\endgroup$

1 Answer 1

2
$\begingroup$

Use clf_fs.predict instead.

Reference link

$\endgroup$
1
  • $\begingroup$ While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review $\endgroup$
    – Ethan
    Commented Oct 18, 2021 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.