Skip to content

DOC use notebook style in AdaBoostClassifier example - #26486

Merged
glemaitre merged 14 commits into
scikit-learn:mainfrom
StefanieSenger:AdaBoostClassifier_example
Jul 6, 2023
Merged

glemaitre merged 14 commits into
scikit-learn:mainfrom
StefanieSenger:AdaBoostClassifier_example

Conversation

@StefanieSenger

Copy link
Copy Markdown
Member

What does this implement/fix? Explain your changes.

This PR suggests an improved formatting of the AdaBoostClassifier example, with code cell functionality.
I've also edited the text, so it becomes better understandable.

@adrinjalali
adrinjalali requested a review from glemaitre June 1, 2023 15:13
@glemaitre glemaitre changed the title Improved formatting of AdaBoostClassifier example DOC use notebook style in AdaBoostClassifier example Jun 1, 2023
@glemaitre

Copy link
Copy Markdown
Member

Ups, I posted my review to early. This is only a partial review. Let me finish it :)

@glemaitre glemaitre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is another partial review. I will look at the comparison in few hours.

@StefanieSenger

Copy link
Copy Markdown
Member Author

@glemaitre Thank you for your suggestions. I've implemented all of them and also worked on the text regarding the performance comparison. Let me know what you think, especially on the descriptions of the plots.

@glemaitre

Copy link
Copy Markdown
Member

OK, I finish the round of review at least for the first pass.

I am almost sure that we have an issue with the SAMME.R algorithm. I don't know if this is because of the code or if this is only the theory that does not work. I will try to investigate a bit more.

I think that we can go around this problem in this example by discussing only the weak learner errors and weights of the SAMME algorithm since they are also the ones depicted in the paper.

We should only be careful to have truthful statements until we find the reason that the SAMME.R can start to diverge. I will make a minimal reproducer and add it in #20443.

@StefanieSenger

Copy link
Copy Markdown
Member Author

@glemaitre Just saw your other comments from the last hour. I will go through them and reply later today.

@StefanieSenger

StefanieSenger commented Jun 2, 2023 •

Copy link
Copy Markdown
Member Author

@glemaitre

I‘ve implemented basically as you suggested. Thanks for your thorough review. Please have a look at my descriptions of the plots.

The main differences to what you suggested are:

  1. I have kept the learning rate at 1.0 for both algorithms, because I think the goal is to graphically compare them.
  2. Regarding the paper stating that they used 3000 samples for train and 10000 for test: I kept it as is was, since it would be unusual to swap. For more clarity we could explicitly differ from the paper. Something like creating 10000 samples in total and then train-test-split of 70:30.
  3. Also, for good practice, I think we should shuffle the data for the train-test-split. At least I can‘t think of any reason why we shouldn't.

Note: the reference section doesn‘t work for me, need to find out how to repair the on another day.

.. topic:: References:
.. [1] J. Zhu, H. Zou, S. Rosset, T. Hastie,
`"Multi-class AdaBoost"
<https://hastie.su.domains/Papers/samme.pdf>`_,
2009.

PS: Re-reading my own message I want to add, that those things I kept unchanged for the moment are of cause up to discussion. When I summed them up I was looking for a way to structure the discussion. (Sorry, it was late when I wrote that and I didn't double check for tone and politeness as I'd usually do.)

@glemaitre glemaitre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here comes another review. Once addressed, I would reevaluate the message of the example since I think we should remove the part about SAMME.R

@StefanieSenger

Copy link
Copy Markdown
Member Author

Hi @glemaitre, I have extracted the SAMME.R algorithm and made a little comparison between the accuracies of a single DecisionTreeClassifier and boosted DecisionTreeClassifiers, as suggested. :)

Maybe we should also add an interpretation of the last two plots.
The left plot is a miracle to me. Why are the errors slightly incleasing?
Weights going down on the right plot might be explainable by AdaBoost having seen the more extreme cases and the following trees have been regulated. I'm not 100 percent sure of this, though. What do you think?

@glemaitre
glemaitre self-requested a review June 14, 2023 17:49
@glemaitre

Copy link
Copy Markdown
Member

The left plot is a miracle to me. Why are the errors slightly increasing?

The intuition behind this is that the first classifier (or a couple of classifiers) will be stronger (with a lower error or a higher score). Since all samples have equal weights they will provide an answer for the general trends of the data.

Later classifiers in the boosting chain will not have such a choice because due to the boosting reweighting, we force them to focus on the difficult samples. Let's for one second imagine that after the first classifier, only noisy samples remain misclassified, you will create classifiers that would try to find a specific rule for those samples without any attention to the majority of samples. So in practice, those classifiers will have a decrease in statistical performance. And to counterbalance that, you affect a lower weight when making the final additive model (since the weights (in binary case) are defined as 1/2 * ln ((1- err) / err)).

That is why I would expect the error to increase and the associated weight to decrease.

@glemaitre

Copy link
Copy Markdown
Member

I will have a pass again and the full example now that you trimmed it. It will be easier to have targetted comment :).

@glemaitre glemaitre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the example converges :)
So I made a full pass on the example and propose a couple of changes.

@github-actions

github-actions Bot commented Jun 27, 2023 •

Copy link
Copy Markdown

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 828c121. Link to the linter CI: here

@glemaitre
glemaitre self-requested a review July 5, 2023 09:13

@glemaitre glemaitre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good. Only some minor changes.

@glemaitre glemaitre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I just made 2 small nitpicks and merge them directly.
This example is much better. Thanks a lot, @StefanieSenger.
Merging.

@glemaitre
glemaitre merged commit 3a4a1d5 into scikit-learn:main Jul 6, 2023
@StefanieSenger

Copy link
Copy Markdown
Member Author

Oh, it was all for your support. :) Thanks.

@StefanieSenger
StefanieSenger deleted the AdaBoostClassifier_example branch July 6, 2023 12:36
punndcoder28 pushed a commit to punndcoder28/scikit-learn that referenced this pull request Jul 29, 2023
glemaitre added a commit to glemaitre/scikit-learn that referenced this pull request Sep 18, 2023
jeremiedbb pushed a commit that referenced this pull request Sep 20, 2023
REDVM pushed a commit to REDVM/scikit-learn that referenced this pull request Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants