8000 DOC Ensures that MissingIndicator passes numpydoc validation (#21149) · scikit-learn/scikit-learn@1b51ae2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1b51ae2

Browse files
authored
DOC Ensures that MissingIndicator passes numpydoc validation (#21149)
1 parent f33fb0a commit 1b51ae2

File tree

2 files changed

+49
-44
lines changed

2 files changed

+49
-44
lines changed

maint_tools/test_docstrings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"LocalOutlierFactor",
1717
"LocallyLinearEmbedding",
1818
"MiniBatchKMeans",
19-
"MissingIndicator",
2019
"MultiLabelBinarizer",
2120
"MultiTaskElasticNet",
2221
"MultiTaskElasticNetCV",

sklearn/impute/_base.py

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ class MissingIndicator(TransformerMixin, BaseEstimator):
610610
611611
Parameters
612612
----------
613-
missing_values : int, float, string, np.nan or None, default=np.nan
613+
missing_values : int, float, str, np.nan or None, default=np.nan
614614
The placeholder for the missing values. All occurrences of
615615
`missing_values` will be imputed. For pandas' dataframes with
616616
nullable integer dtypes with missing values, `missing_values`
@@ -620,29 +620,29 @@ class MissingIndicator(TransformerMixin, BaseEstimator):
620620
Whether the imputer mask should represent all or a subset of
621621
features.
622622
623-
- If 'missing-only' (default), the imputer mask will only represent
623+
- If `'missing-only'` (default), the imputer mask will only represent
624624
features containing missing values during fit time.
625-
- If 'all', the imputer mask will represent all features.
625+
- If `'all'`, the imputer mask will represent all features.
626626
627627
sparse : bool or 'auto', default='auto'
628628
Whether the imputer mask format should be sparse or dense.
629629
630-
- If 'auto' (default), the imputer mask will be of same type as
630+
- If `'auto'` (default), the imputer mask will be of same type as
631631
input.
632-
- If True, the imputer mask will be a sparse matrix.
633-
- If False, the imputer mask will be a numpy array.
632+
- If `True`, the imputer mask will be a sparse matrix.
633+
- If `False`, the imputer mask will be a numpy array.
634634
635635
error_on_new : bool, default=True
636-
If True, transform will raise an error when there are features with
637-
missing values in transform that have no missing values in fit. This is
638-
applicable only when `features='missing-only'`.
636+
If `True`, :meth:`transform` will raise an error when there are
637+
features with missing values that have no missing values in
638+
:meth:`fit`. This is applicable only when `features='missing-only'`.
639639
640640
Attributes
641641
----------
642-
features_ : ndarray, shape (n_missing_features,) or (n_features,)
643-
The features indices which will be returned when calling ``transform``.
644-
They are computed during ``fit``. For ``features='all'``, it is
645-
to ``range(n_features)``.
642+
features_ : ndarray of shape (n_missing_features,) or (n_features,)
643+
The features indices which will be returned when calling
644+
:meth:`transform`. They are computed during :meth:`fit`. If
645+
`features='all'`, `features_` is equal to `range(n_features)`.
646646
647647
n_features_in_ : int
648648
Number of features seen during :term:`fit`.
@@ -655,6 +655,11 @@ class MissingIndicator(TransformerMixin, BaseEstimator):
655655
656656
.. versionadded:: 1.0
657657
658+
See Also
659+
--------
660+
SimpleImputer : Univariate imputation of missing values.
661+
IterativeImputer : Multivariate imputation of missing values.
662+
658663
Examples
659664
--------
660665
>>> import numpy as np
@@ -673,7 +678,6 @@ class MissingIndicator(TransformerMixin, BaseEstimator):
673678
array([[False, True],
674679
[ True, False],
675680
[False, False]])
676-
677681
"""
678682

679683
def __init__(
@@ -695,19 +699,19 @@ def _get_missing_features_info(self, X):
695699
696700
Parameters
697701
----------
698-
X : {ndarray or sparse matrix}, shape (n_samples, n_features)
699-
The input data with missing values. Note that ``X`` has been
700-
checked in ``fit`` and ``transform`` before to call this function.
702+
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
703+
The input data with missing values. Note that `X` has been
704+
checked in :meth:`fit` and :meth:`transform` before to call this
705+
function.
701706
702707
Returns
703708
-------
704-
imputer_mask : {ndarray or sparse matrix}, shape \
709+
imputer_mask : {ndarray, sparse matrix} of shape \
705710
(n_samples, n_features)
706711
The imputer mask of the original data.
707712
708-
features_with_missing : ndarray, shape (n_features_with_missing)
713+
features_with_missing : ndarray of shape (n_features_with_missing)
709714
The features containing missing values.
710-
711715
"""
712716
if not self._precomputed:
713717
imputer_mask = _get_mask(X, self.missing_values)
@@ -778,25 +782,23 @@ def _validate_input(self, X, in_fit):
778782
return X
779783

780784
def _fit(self, X, y=None, precomputed=False):
781-
"""Fit the transformer on X.
785+
"""Fit the transformer on `X`.
782786
783787
Parameters
784788
----------
785-
X : {array-like, sparse matrix}, shape (n_samples, n_features)
786-
Input data, where ``n_samples`` is the number of samples and
787-
``n_features`` is the number of features.
788-
If `precomputed` is True, then `X` is a mask of the
789-
input data.
789+
X : {array-like, sparse matrix} of shape (n_samples, n_features)
790+
Input data, where `n_samples` is the number of samples and
791+
`n_features` is the number of features.
792+
If `precomputed=True`, then `X` is a mask of the input data.
790793
791794
precomputed : bool
792795
Whether the input data is a mask.
793796
794797
Returns
795798
-------
796-
imputer_mask : {ndarray or sparse matrix}, shape (n_samples, \
799+
imputer_mask : {ndarray, sparse matrix} of shape (n_samples, \
797800
n_features)
798801
The imputer mask of the original data.
799-
800802
"""
801803
if precomputed:
802804
if not (hasattr(X, "dtype") and X.dtype.kind == "b"):
@@ -834,38 +836,40 @@ def _fit(self, X, y=None, precomputed=False):
834836
return missing_features_info[0]
835837

836838
def fit(self, X, y=None):
837-
"""Fit the transformer on X.
839+
"""Fit the transformer on `X`.
838840
839841
Parameters
840842
----------
841-
X : {array-like, sparse matrix}, shape (n_samples, n_features)
842-
Input data, where ``n_samples`` is the number of samples and
843-
``n_features`` is the number of features.
843+
X : {array-like, sparse matrix} of shape (n_samples, n_features)
844+
Input data, where `n_samples` is the number of samples and
845+
`n_features` is the number of features.
846+
847+
y : Ignored
848+
Not used, present for API consistency by convention.
844849
845850
Returns
846851
-------
847852
self : object
848-
Returns self.
853+
Fitted estimator.
849854
"""
850855
self._fit(X, y)
851856

852857
return self
853858

854859
def transform(self, X):
855-
"""Generate missing values indicator for X.
860+
"""Generate missing values indicator for `X`.
856861
857862
Parameters
858863
----------
859-
X : {array-like, sparse matrix}, shape (n_samples, n_features)
864+
X : {array-like, sparse matrix} of shape (n_samples, n_features)
860865
The input data to complete.
861866
862867
Returns
863868
-------
864-
Xt : {ndarray or sparse matrix}, shape (n_samples, n_features) \
869+
Xt : {ndarray, sparse matrix} of shape (n_samples, n_features) \
865870
or (n_samples, n_features_with_missing)
866-
The missing indicator for input data. The data type of ``Xt``
871+
The missing indicator for input data. The data type of `Xt`
867872
will be boolean.
868-
869873
"""
870874
check_is_fitted(self)
871875

@@ -894,20 +898,22 @@ def transform(self, X):
894898
return imputer_mask
895899

896900
def fit_transform(self, X, y=None):
897-
"""Generate missing values indicator for X.
901+
"""Generate missing values indicator for `X`.
898902
899903
Parameters
900904
----------
901-
X : {array-like, sparse matrix}, shape (n_samples, n_features)
905+
X : {array-like, sparse matrix} of shape (n_samples, n_features)
902906
The input data to complete.
903907
908+
y : Ignored
909+
Not used, present for API consistency by convention.
910+
904911
Returns
905912
-------
906-
Xt : {ndarray or sparse matrix}, shape (n_samples, n_features) \
913+
Xt : {ndarray, sparse matrix} of shape (n_samples, n_features) \
907914
or (n_samples, n_features_with_missing)
908-
The missing indicator for input data. The data type of ``Xt``
915+
The missing indicator for input data. The data type of `Xt`
909916
will be boolean.
910-
911917
"""
912918
imputer_mask = self._fit(X, y)
913919

0 commit comments

Comments
 (0)
0