Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TrAdaBoost can predict_proba or not #111

Open
jnuvenus opened this issue Aug 8, 2023 · 1 comment
Open

TrAdaBoost can predict_proba or not #111

jnuvenus opened this issue Aug 8, 2023 · 1 comment

Comments

@jnuvenus
Copy link

jnuvenus commented Aug 8, 2023

Can Tradaboost algorithm use the predict_proba() method to output the probability values of each sample belonging to the positive and negative classes in binary classification problems?

@antoinedemathelin
Copy link
Collaborator

Hi @jnuvenus,
Thank you for your interest in the Adapt library!
There is no predict_proba method implemented on the Tradaboost object but you can access the predict_proba method of each estimator in model.estimators_. Here is a little example to compute the weighted average probabilities among Tradaboost estimators (Note that the authors of Tradaboost suggests to use only the last half estimators for prediction):

import numpy as np
from sklearn.linear_model import LogisticRegression
from adapt.utils import make_classification_da
from adapt.instance_based import TrAdaBoost

Xs, ys, Xt, yt = make_classification_da()
model = TrAdaBoost(LogisticRegression(), n_estimators=10, Xt=Xt[:10], yt=yt[:10],
                   verbose=0, random_state=0)
model.fit(Xs, ys);

N = len(model.estimators_)
probas = [m.predict_proba(Xt) for m in model.estimators_[int(N/2):]]
probas = np.stack(probas, axis=-1)

weights = np.array(model.estimator_weights_)
weights = weights[int(N/2):]
weights /= weights.sum()

weighted_avg_probas = probas.dot(weights)
weighted_avg_probas

Thanks to your question, we will add the predict_proba feature for Tradaboost in the next release of Adapt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants