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

Access "sample_weight" in adaboost #9305

Open
pierthodo opened this issue Jul 9, 2017 · 2 comments
Open

Access "sample_weight" in adaboost #9305

pierthodo opened this issue Jul 9, 2017 · 2 comments

Comments

@pierthodo
Copy link

Hello,

For a research paper I need to access the weights calculated by the Adaboostclassifier. Would it be possible to add the variable "sample_weight" as an attribute so I could publish code working with scikit-learn out of the box ?

Thank you,

Pierre

@jmschrei
Copy link
Member

jmschrei commented Jul 9, 2017

I'm not entirely sure how this would fit in with our current API. If you have a suggestion, the best idea is probably for you to submit a pull request and we'd be happy to review it.

@tgsmith61591
Copy link
Contributor

tgsmith61591 commented Aug 1, 2017

From this block:

for iboost in range(self.n_estimators):
    # Boosting step
    sample_weight, estimator_weight, estimator_error = self._boost(
        iboost,
        X, y,
        sample_weight,
        random_state)

    # Early termination
    if sample_weight is None:
        break

    self.estimator_weights_[iboost] = estimator_weight
    self.estimator_errors_[iboost] = estimator_error

Wouldn't it be as simple as maintaining another list (similar to estimator_weights_)? For example (larger block for context):

# Clear any previous fit results
self.estimators_ = []
self.sample_weights_ = []  # add this list
self.estimator_weights_ = np.zeros(self.n_estimators, dtype=np.float64)
self.estimator_errors_ = np.ones(self.n_estimators, dtype=np.float64)

random_state = check_random_state(self.random_state)

for iboost in range(self.n_estimators):
    # Boosting step
    sample_weight, estimator_weight, estimator_error = self._boost(
        iboost,
        X, y,
        sample_weight,
        random_state)

    # Early termination
    if sample_weight is None:
        break

    self.sample_weights_.append(sample_weight)  # add this append statement
    self.estimator_weights_[iboost] = estimator_weight
    self.estimator_errors_[iboost] = estimator_error

(Happy to add and submit a PR, if you think it might be worthwhile)

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

Successfully merging a pull request may close this issue.

4 participants