Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean for an attribute name to end in an underscore?

Similar question: What's the advantage of a trailing underscore in Python naming?. This addresses advantages/disadvantages, whereas this addresses the reasoning behind doing it, both broadly and specifically to sklearn.

I am looking through the sklearn documentation, and I noticed that the sklearn.model_selection.GridSearchCV attributes all end in underscore. For example:

  • cv_results_
  • best_params_
  • best_score_

Why is this? What does the underscore do? Please be as broad as possible in your answer (i.e. don't just refer to sklearn's GridSearchCV.

I'm assuming this isn't just an sklearn thing, and I have no idea what the appropriate tag is for this so I'm tagging sklearn. Please correct the tags (or me!).

like image 580
quanty Avatar asked Mar 06 '18 19:03

quanty


1 Answers

For sklearn, there is a specific interpretation. Check the sklearn developer guideline, which has a note on this. The convention is used for attributes of estimators that have a meaningful value after fit() was called.

These are then used to for instance check if the estimator was fitted, see for instance here:

class LinearModel(six.with_metaclass(ABCMeta, BaseEstimator)):
    """Base class for Linear Models"""

    [...]

    def _decision_function(self, X):
        check_is_fitted(self, "coef_")

   [...]
like image 105
Marcus V. Avatar answered Sep 18 '22 15:09

Marcus V.