Skip to content

[MRG] Add docs for TfidfTransformer.idf_ (Fixes #8267) #8528

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
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions sklearn/feature_extraction/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def build_preprocessor(self):
# hundreds of nanoseconds which is negligible when compared to the
# cost of tokenizing a string of 1000 chars for instance.
noop = lambda x: x

Copy link
Member

Choose a reason for hiding this comment

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

please remove the whitespace

# accent stripping
if not self.strip_accents:
strip_accents = noop
Expand Down Expand Up @@ -996,6 +996,12 @@ class TfidfTransformer(BaseEstimator, TransformerMixin):
sublinear_tf : boolean, default=False
Apply sublinear tf scaling, i.e. replace tf with 1 + log(tf).

Attributes
----------
idf_ : numpy array of shape [n_features, 1]
Copy link
Member

Choose a reason for hiding this comment

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

Copying @jmschrei's comment from #8532 -

This class doesn't seem to have or use a self.idf_ attribute. Do you mean self._idf_diag?

Copy link
Member

Choose a reason for hiding this comment

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

There is a property.

returns None unless use_idf=True, then
Copy link
Member

Choose a reason for hiding this comment

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

We would not usually describe an attribute with "returns".

returns 1-D matrix containing idf(d,t).
Copy link
Member

Choose a reason for hiding this comment

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

I don't get what d is and why this 1-d vector is a function of two indices.


References
----------

Expand Down Expand Up @@ -1035,9 +1041,8 @@ def fit(self, X, y=None):
# log+1 instead of log makes sure terms with zero idf don't get
# suppressed entirely.
idf = np.log(float(n_samples) / df) + 1.0
self._idf_diag = sp.spdiags(idf, diags=0, m=n_features,
self._idf_diag = sp.spdiags(idf, diags=0, m=n_features,
n=n_features, format='csr')

return self

def transform(self, X, copy=True):
Expand Down