Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add classes_ to classifier attributes #12509

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

Closed

Conversation

jrbourbeau
Copy link
Contributor

Reference Issues/PRs

Fixes #11444

What does this implement/fix? Explain your changes.

This PR adds classes_ to the Attributes section for classification estimators. I've also added a test in sklearn/tests/test_docstring_parameters.py to check that each classifier has an Attributes section in its docstring and classes_ is listed as an attribute (as proposed in #11444 (comment))

Any other comments?

The list of classifiers that are being checked is given by all_estimators(type_filter='classifier') from sklearn.utils.testing. If there are other classifiers that should also be added, just let me know and I'll add them to this PR.

Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

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

I think you might find classes_ has a different shape in some multi output classifiers. Try nearest neighbors, decision tree and MLP...

@judithabk6
Copy link
Contributor

addition of the attribute classes_ in the doc was actually implemented in all classes addressed by this PR, in a variety of other PRs

class QuadraticDiscriminantAnalysis #14374
class GradientBoostingClassifier #14459
class LogisticRegression #12795
class LogisticRegressionCV #12795
class PassiveAggressiveClassifier #14459
class Perceptron #14459
class RidgeClassifier #14459
class RidgeClassifierCV #14459
class SGDClassifier #14459
class GaussianNB #14354
class MultinomialNB #15998
class ComplementNB #14354
class BernoulliNB #14354
class KNeighborsClassifier #14374
class RadiusNeighborsClassifier #14374
class NearestCentroid #14459
class LabelPropagation #16042
class LabelSpreading #16042
class LinearSVC #14459 #16060
class SVC #14459 #16060
class NuSVC #14459 #16060
class ExtraTreeClassifier #14339

probably should be closed, and related issue #11444 as well.

Only the test could be relevant.

@lesteve
Copy link
Member

lesteve commented Jan 29, 2020

Only the test could be relevant.

Agreed it would be good to add this test in a separate PR and fix the few remaining cases. Running this test on master, I found that there were still issues (probably because these classes were added since this PR was made):

  • sklearn.utils._mocking.CheckingClassifier (probably can be skipped because it is used just for tests)
  • sklearn.ensemble.HistGradientBoostingClassifier
  • sklearn.multioutput.MultiOutputClassifier
  • sklearn.ensemble.StackingClassifier

@lesteve
Copy link
Member

lesteve commented Jan 29, 2020

I am going to close this PR, thanks for drawing our attention to it @judithabk6.

@lesteve
Copy link
Member

lesteve commented Jan 29, 2020

@judithabk6 I opened #16273. If you are still at the sprint, that would be a good one to tackle.

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.

AttributeError: 'LogisticRegression' object has no attribute 'classes_'
5 participants