Skip to content

Fix NameError in MondrianCategorizer.apply() when oob=False - #51

Open
shivamlalakiya wants to merge 1 commit into
henrikbostrom:mainfrom
shivamlalakiya:fix-apply-undefined-learner
Open

Fix NameError in MondrianCategorizer.apply() when oob=False#51
shivamlalakiya wants to merge 1 commit into
henrikbostrom:mainfrom
shivamlalakiya:fix-apply-undefined-learner

Conversation

@shivamlalakiya

Copy link
Copy Markdown

MondrianCategorizer.apply()'s oob=False branch reads a bare name learner,
which is neither a parameter of apply() nor an attribute on the instance —
it is self.learner, assigned in fit(). The branch therefore raises
NameError on every call:

from crepes.extras import MondrianCategorizer
from sklearn.ensemble import RandomForestRegressor

rf = RandomForestRegressor(n_estimators=10, oob_score=True, random_state=0).fit(X, y)
mc = MondrianCategorizer()
mc.fit(X=X, learner=rf, oob=False)   # succeeds
mc.apply(X)                          # NameError: name 'learner' is not defined

oob=False is fit()'s documented default (its own docstring documents the
learner parameter), so this is the documented, default combination, not an
edge case. The oob=True branch two lines above already reads
self.learner.estimators_, so this is the one call site that never picked up
self..

One-line fix: learner.predict(X)self.learner.predict(X). The branch
currently raises unconditionally, so no existing output can change.

apply() calls learner.predict(X) but learner is not a parameter or
attribute of apply(); it is self.learner, set in fit(). The oob=False
branch (fit's own default and documented combination) therefore raises
NameError: name 'learner' is not defined on every call. The sibling
line seven lines above already reads self.learner.estimators_.
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

Successfully merging this pull request may close these issues.

1 participant