Skip to content

Drop the sample_weight entry from GMM.fit's docstring - #741

Open
VenishPaneliya wants to merge 1 commit into
yzhao062:masterfrom
VenishPaneliya:gmm-sample-weight-doc
Open

Drop the sample_weight entry from GMM.fit's docstring#741
VenishPaneliya wants to merge 1 commit into
yzhao062:masterfrom
VenishPaneliya:gmm-sample-weight-doc

Conversation

@VenishPaneliya

Copy link
Copy Markdown

What this fixes

GMM.fit has the signature fit(self, X, y=None), but its docstring documents a third argument:

sample_weight : array-like, shape (n_samples,)
    Per-sample weights. Rescale C per sample. Higher weights
    force the classifier to put more emphasis on these points.

There's no **kwargs to absorb it, so following the documentation fails:

>>> GMM().fit(X, sample_weight=w)
TypeError: GMM.fit() got an unexpected keyword argument 'sample_weight'

Two things say this is a stray copy rather than a missing feature:

  • The wording comes from OCSVM.fit, which really does take sample_weight (fit(self, X, y=None, sample_weight=None, **params)). "Rescale C per sample" refers to the SVM penalty parameter, which has no counterpart in a Gaussian mixture — and a GMM is not a classifier.
  • It couldn't be forwarded even if we wanted to: sklearn.mixture.GaussianMixture.fit is fit(self, X, y) with no sample_weight.

So the only correct reconciliation is removing the documentation. OCSVM is untouched — it documents the argument correctly because it accepts it.

GMM and OCSVM are the only two detectors in pyod/models/ whose fit docstring mentions sample_weight; OCSVM is the correct one.

Testing

Documentation-only, so no behaviour to test:

  • pyod/test/test_gmm.py: 14 passed
  • verified OCSVM().fit(X, sample_weight=w) still works and GMM.fit's signature is unchanged
  • flake8 reports the same single pre-existing finding as an unmodified checkout

`GMM.fit` is `fit(self, X, y=None)`, but its docstring documents a third
argument:

    sample_weight : array-like, shape (n_samples,)
        Per-sample weights. Rescale C per sample. Higher weights
        force the classifier to put more emphasis on these points.

Passing it raises `TypeError: GMM.fit() got an unexpected keyword
argument 'sample_weight'`.

The text is copied from `OCSVM.fit`, which does take the argument - "C"
is the SVM penalty parameter and has no counterpart in a Gaussian
mixture. It also cannot simply be forwarded: `sklearn.mixture
.GaussianMixture.fit` is `fit(self, X, y)` and has no `sample_weight`.

Only the stale documentation is removed; OCSVM is untouched.
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