Skip to content

Commit 74581c3

Browse files
authored
Missing word (have) and typos
1 parent 269600c commit 74581c3

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

faq/underscore-convention.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ instead of
1818
def sigmoid(self, z):
1919
return 1.0 / (1.0 + np.exp(-z))
2020

21-
The short answer is, the trailing underscore (`self.gamma_`) in class attributes is a scikit-learn convention to denote "estimated" or "fitted" attributes. The leading underscores are (`_sigmoid(self, z)`) denote private methods that the user shouldn't bother with.
21+
The short answer is, the trailing underscore (`self.gamma_`) in class attributes is a scikit-learn convention to denote "estimated" or "fitted" attributes.
22+
The leading underscores are (`_sigmoid(self, z)`) denote private methods that the user should not bother with.
2223

2324

2425
In brief: As a reader, you can safely ignore those underscores, however, if you are curious about their intention, please read on!
2526

2627
## Leading underscores in class methods
2728

28-
The usage of underscores for naming class methods is a common Python convention to distinguish between private and public methods. Basically, you don't want the user to worry about these private methods, which is why they don't appear in the help menu.
29+
The usage of underscores for naming class methods is a common Python convention to distinguish between private and public methods. Basically, you do not want the user to worry about these private methods, which is why they do not appear in the help menu.
2930

3031
class MyClass(object):
3132
def __init__(self, param='some_value'):
@@ -67,7 +68,7 @@ The usage of underscores for naming class methods is a common Python convention
6768

6869
* Note that `__init__` is an exception, `__init__` is a special method that is required to initialize a class.
6970

70-
Let’s initialize a new object and call this public class:
71+
Let us initialize a new object and call this "public" class:
7172

7273
>>> MyObj = MyClass()
7374
>>> MyObj.public()
@@ -81,7 +82,7 @@ The single underscore in `_indicate_private` indicates privacy. Typically, priva
8182

8283
- Please keep in mind that calling private methods is at your own risk; the developers usually take no responsibilities for odd things that may happen if you call private methods as a user.
8384

84-
The indication of privacy is a bit stronger if we use 2 preceding underscores, for example, calling the `__pseudo_private` method directly like a regular method doesn’t work anymore:
85+
The indication of "privacy" is a bit stronger if we use 2 preceding underscores, for example, calling the `__pseudo_private` method directly like a regular method does not work anymore:
8586

8687
>>> MyObj.__pseudo_private()
8788
---------------------------------------------------------------------------
@@ -91,7 +92,7 @@ The indication of “privacy” is a bit stronger if we use 2 preceding undersco
9192

9293
AttributeError: 'MyClass' object has no attribute '__pseudo_private'
9394

94-
To call the a private methods that is prefaced with 2 underscores, we need to adhere to the name mangling rules; that is, we need to add a `_classname` prefix, to call the method, for example,
95+
To call the a private methods that is prefaced with 2 underscores, we need to adhere to the "name mangling" rules; that is, we need to add a `_classname` prefix, to call the method, for example,
9596

9697
>>> MyObj._MyClass__pseudo_private()
9798
'really private method'
@@ -100,16 +101,16 @@ To call the a private methods that is prefaced with 2 underscores, we need to ad
100101

101102
## Class attributes with trailing underscores
102103

103-
In contrast to the leading underscore, the trailing underscores in class attributes don't any "technical" effects. In fact, this is just a convention that I adopted from scikit-learn out of habit.
104+
In contrast to the leading underscore, the trailing underscores in class attributes do not have any "technical" effects. In fact, this is just a convention that I adopted from scikit-learn out of habit.
104105

105106
Here are two excerpts from the scikit-learn [developer/contributor documentation](http://scikit-learn.org/stable/developers/):
106107

107-
> Attributes that have been estimated from the data must always have a name ending with trailing underscore, for example, the coefficients of some regression estimator would be stored in a coef_ attribute after fit has been called.
108+
> Attributes that have been estimated from the data must always have a name ending with trailing underscore `_`, for example, the coefficients of some regression estimator would be stored in a `coef_` attribute after `fit()` has been called.
108109
109110

110-
> Also it is expected that parameters with trailing _ are not to be set inside the ``__init__`` method. All and only the public attributes set by fit have a trailing _. As a result the existence of parameters with trailing _ is used to check if the estimator has been fitted.
111+
> Also it is expected that parameters with trailing underscore `_` are not to be set inside the ``__init__`` method. All and only the public attributes set by `fit()` have a trailing `_`. As a result the existence of parameters with trailing `_` is used to check if the estimator has been fitted.
111112
112-
To see it in action, let's create a primitive `Estimator`:
113+
To see it in action, let us create a primitive `Estimator`:
113114

114115
class MyEstimator():
115116
def __init__(self):
@@ -118,7 +119,7 @@ To see it in action, let's create a primitive `Estimator`:
118119
def fit(self):
119120
self.fit_param_ = 0.1
120121

121-
Intuitively, attributes that are in `__init__` are accessible after we initialized a new object
122+
Intuitively, attributes that are in `__init__` are accessible after we initialized a new object:
122123

123124
>>> est = MyEstimator()
124125
>>> est.param

0 commit comments

Comments
 (0)