Skip to content

GBT fails with RF init #2691

Closed
Closed

Description

@agramfort

here is a tiny script which reproduces the crash.

from sklearn.datasets import load_iris
from sklearn import ensemble
from sklearn.cross_validation import train_test_split

iris = load_iris()
X, y = iris.data, iris.target
X, y = X[y < 2], y[y < 2]  # make it binary

X_train, X_test, y_train, y_test = train_test_split(X, y)

# Fit GBT init with RF
rf = ensemble.RandomForestClassifier()
clf = ensemble.GradientBoostingClassifier(init=rf)

clf.fit(X_train, y_train)
acc = clf.score(X_test, y_test)
print("Accuracy: {:.4f}".format(acc))

It also seems that the init param in GradientBoostingClassifier is
not really tested.

@pprett @glouppe @ogrisel

Activity

  1. pprett commented on Dec 26, 2013

    @pprett
    Member

    @agramfort thanks - I'm aware of the issue - but I was cautious to get rid of it because handling this properly would incur quite a test-time performance degradation for single instance prediction (checking isinstance or some try-except block).
    I'll solve this soon.

  2. agramfort commented on Dec 26, 2013

    @agramfort
    MemberAuthor

    ok thanks.

  3. amueller commented on Dec 27, 2013

    @amueller
    Member

    Hm I guess we should fix that before a release, right?

  4. pprett commented on Dec 27, 2013

    @pprett
    Member

    jep - lets put a milestone

  5. agramfort commented on Jan 8, 2014

    @agramfort
    MemberAuthor

    now that the big refactoring of GBRT is merged, what's needed here?

  6. pprett commented on Jan 9, 2014

    @pprett
    Member

    basically consolidating this check:

    if (not hasattr(self.init, 'fit') or not hasattr(self.init, 'predict'))
    

    to check on predict_proba for classification.
    Then we need to make sure that if an init estimator has predict_proba we use the log-odds for binary classification and the output of predict_proba for multi-class.
    Basically, the following lines have to be changed to accommodate this:

    y_pred = self.init_.predict(X)  # in fit
    

    and:

    score = self.init_.predict(X).astype(np.float64)  # in _init_decision_function
    
  7. ogrisel commented on Jan 9, 2014

    @ogrisel
    Member

    I think we need a better implementation of astype somewhere under sklearn/utils. The current implementation of numpy.astype always makes a copy of the data even when it already has the right type.

  8. GaelVaroquaux commented on Jan 9, 2014

    @GaelVaroquaux
    Member

    I think we need a better implementation of astype somewhere under sklearn/
    utils. The current implementation of numpy.astype always makes a copy of the
    data even when it already has the right type.

    check_arrays will do it, I believe.

  9. kaushik94 commented on Feb 27, 2014

    @kaushik94
    Contributor

    Is this the bug:

    Traceback (most recent call last):
      File "x.py", line 15, in <module>
        clf.fit(X_train, y_train)
      File "/home/kaushik/scikit-learn/sklearn/ensemble/gradient_boosting.py", line 1124, in fit
        return super(GradientBoostingClassifier, self).fit(X, y, monitor)
      File "/home/kaushik/scikit-learn/sklearn/ensemble/gradient_boosting.py", line 782, in fit
        begin_at_stage, monitor)
      File "/home/kaushik/scikit-learn/sklearn/ensemble/gradient_boosting.py", line 833, in _fit_stages
        criterion, splitter, random_state)
      File "/home/kaushik/scikit-learn/sklearn/ensemble/gradient_boosting.py", line 575, in _fit_stage
        sample_mask, self.learning_rate, k=k)
      File "/home/kaushik/scikit-learn/sklearn/ensemble/gradient_boosting.py", line 194, in update_terminal_regions
        y_pred[:, k])
    IndexError: too many indices
    
  10. pprett commented on Feb 27, 2014

    @pprett
    Member

    @kaushik94 more context please - arguments and dataset characteristics in particular

  11. agramfort commented on Feb 27, 2014

    @agramfort
    MemberAuthor

    yes it's the bug I observed. See my gist above

  12. abhishekkrthakur commented on May 1, 2014

    @abhishekkrthakur
    Contributor

    Is there any workaround available for this?

    On Thu, Feb 27, 2014 at 12:50 PM, Alexandre Gramfort <
    [email protected]> wrote:

    yes it's the bug I observed. See my gist above

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/2691#issuecomment-36234269
    .

    Regards

    Abhishek Thakur

    • de.linkedin.com/in/abhisvnit/
  13. removed this from the 0.15 milestone on Jun 4, 2014
  14. added this to the 0.15.1 milestone on Jul 18, 2014
  15. modified the milestones: 0.17, 0.16 on May 14, 2015
  16. modified the milestones: 0.18, 0.17 on Sep 20, 2015
  17. modified the milestones: 0.18, 0.19 on Sep 22, 2016
  18. modified the milestone: 0.19 on Jun 12, 2017
  19. minnich49 commented on Feb 24, 2018

    @minnich49

    @abhishekkrthakur Did you ever find a workaround for this? I saw that a solution here existed but I was wondering if you had come across anything else.

  20. jeremiedbb commented on Mar 2, 2020

    @jeremiedbb
    Member

    Fixed by #12983. Closing.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions