diff --git a/sklearn/cluster/_affinity_propagation.py b/sklearn/cluster/_affinity_propagation.py index 67c1fb42b650b..cf0da5c5bc0f3 100644 --- a/sklearn/cluster/_affinity_propagation.py +++ b/sklearn/cluster/_affinity_propagation.py @@ -312,6 +312,8 @@ class AffinityPropagation(ClusterMixin, BaseEstimator): n_features_in_ : int Number of features seen during :term:`fit`. + .. versionadded:: 0.24 + Notes ----- For an example, see :ref:`examples/cluster/plot_affinity_propagation.py diff --git a/sklearn/cluster/_agglomerative.py b/sklearn/cluster/_agglomerative.py index 05f57ff238bcf..a1adb8492ab89 100644 --- a/sklearn/cluster/_agglomerative.py +++ b/sklearn/cluster/_agglomerative.py @@ -776,6 +776,8 @@ class AgglomerativeClustering(ClusterMixin, BaseEstimator): n_features_in_ : int Number of features seen during :term:`fit`. + .. versionadded:: 0.24 + children_ : array-like of shape (n_samples-1, 2) The children of each non-leaf node. Values less than `n_samples` correspond to leaves of the tree which are the original samples. @@ -1045,6 +1047,8 @@ class FeatureAgglomeration(AgglomerativeClustering, AgglomerationTransform): n_features_in_ : int Number of features seen during :term:`fit`. + .. versionadded:: 0.24 + children_ : array-like of shape (n_nodes-1, 2) The children of each non-leaf node. Values less than `n_features` correspond to leaves of the tree which are the original samples. diff --git a/sklearn/cluster/_bicluster.py b/sklearn/cluster/_bicluster.py index 1be7dd4e64186..939f044002f2d 100644 --- a/sklearn/cluster/_bicluster.py +++ b/sklearn/cluster/_bicluster.py @@ -261,6 +261,8 @@ class SpectralCoclustering(BaseSpectral): n_features_in_ : int Number of features seen during :term:`fit`. + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.cluster import SpectralCoclustering @@ -401,6 +403,8 @@ class SpectralBiclustering(BaseSpectral): n_features_in_ : int Number of features seen during :term:`fit`. + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.cluster import SpectralBiclustering diff --git a/sklearn/cluster/_birch.py b/sklearn/cluster/_birch.py index 81c9312f1488a..fc4bfdcfc902d 100644 --- a/sklearn/cluster/_birch.py +++ b/sklearn/cluster/_birch.py @@ -404,6 +404,8 @@ class Birch(ClusterMixin, TransformerMixin, BaseEstimator): n_features_in_ : int Number of features seen during :term:`fit`. + .. versionadded:: 0.24 + See Also -------- MiniBatchKMeans : Alternative implementation that does incremental updates diff --git a/sklearn/cluster/_dbscan.py b/sklearn/cluster/_dbscan.py index abbb35e6e04af..e862ee1080ace 100644 --- a/sklearn/cluster/_dbscan.py +++ b/sklearn/cluster/_dbscan.py @@ -220,6 +220,8 @@ class DBSCAN(ClusterMixin, BaseEstimator): n_features_in_ : int Number of features seen during :term:`fit`. + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.cluster import DBSCAN diff --git a/sklearn/cluster/_kmeans.py b/sklearn/cluster/_kmeans.py index fc9ba7a868d10..6b54ec99ae825 100644 --- a/sklearn/cluster/_kmeans.py +++ b/sklearn/cluster/_kmeans.py @@ -769,6 +769,8 @@ class KMeans(TransformerMixin, ClusterMixin, BaseEstimator): n_features_in_ : int Number of features seen during :term:`fit`. + .. versionadded:: 0.24 + See Also -------- MiniBatchKMeans : Alternative online implementation that does incremental @@ -1471,6 +1473,8 @@ class MiniBatchKMeans(KMeans): n_features_in_ : int Number of features seen during :term:`fit`. + .. versionadded:: 0.24 + See Also -------- KMeans : The classic implementation of the clustering method based on the diff --git a/sklearn/cluster/_mean_shift.py b/sklearn/cluster/_mean_shift.py index 147ec6c626eb0..619d52cb7313b 100644 --- a/sklearn/cluster/_mean_shift.py +++ b/sklearn/cluster/_mean_shift.py @@ -314,6 +314,8 @@ class MeanShift(ClusterMixin, BaseEstimator): n_features_in_ : int Number of features seen during :term:`fit`. + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.cluster import MeanShift diff --git a/sklearn/cluster/_optics.py b/sklearn/cluster/_optics.py index 0f2b96346660b..1d04ea7a3214f 100755 --- a/sklearn/cluster/_optics.py +++ b/sklearn/cluster/_optics.py @@ -181,6 +181,8 @@ class OPTICS(ClusterMixin, BaseEstimator): n_features_in_ : int Number of features seen during :term:`fit`. + .. versionadded:: 0.24 + See Also -------- DBSCAN : A similar clustering for a specified neighborhood radius (eps). diff --git a/sklearn/cluster/_spectral.py b/sklearn/cluster/_spectral.py index de0192987f595..8cdbd859fde02 100644 --- a/sklearn/cluster/_spectral.py +++ b/sklearn/cluster/_spectral.py @@ -421,6 +421,8 @@ class SpectralClustering(ClusterMixin, BaseEstimator): n_features_in_ : int Number of features seen during :term:`fit`. + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.cluster import SpectralClustering diff --git a/sklearn/covariance/_elliptic_envelope.py b/sklearn/covariance/_elliptic_envelope.py index ad7904dc7831a..3e0c6a41d5913 100644 --- a/sklearn/covariance/_elliptic_envelope.py +++ b/sklearn/covariance/_elliptic_envelope.py @@ -83,6 +83,11 @@ class EllipticEnvelope(OutlierMixin, MinCovDet): Mahalanobis distances of the training set (on which :meth:`fit` is called) observations. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np diff --git a/sklearn/covariance/_empirical_covariance.py b/sklearn/covariance/_empirical_covariance.py index 02bddd0f50330..9c3d94c863c72 100644 --- a/sklearn/covariance/_empirical_covariance.py +++ b/sklearn/covariance/_empirical_covariance.py @@ -125,6 +125,11 @@ class EmpiricalCovariance(BaseEstimator): Estimated pseudo-inverse matrix. (stored only if store_precision is True) + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np diff --git a/sklearn/covariance/_graph_lasso.py b/sklearn/covariance/_graph_lasso.py index 091d4f82e7e3e..398a8af72f3a9 100644 --- a/sklearn/covariance/_graph_lasso.py +++ b/sklearn/covariance/_graph_lasso.py @@ -339,6 +339,11 @@ class GraphicalLasso(EmpiricalCovariance): n_iter_ : int Number of iterations run. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np @@ -635,6 +640,11 @@ class GraphicalLassoCV(GraphicalLasso): n_iter_ : int Number of iterations run for the optimal alpha. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np diff --git a/sklearn/covariance/_robust_covariance.py b/sklearn/covariance/_robust_covariance.py index 337ba23f19059..2323d14d3359a 100644 --- a/sklearn/covariance/_robust_covariance.py +++ b/sklearn/covariance/_robust_covariance.py @@ -582,6 +582,11 @@ class MinCovDet(EmpiricalCovariance): Mahalanobis distances of the training set (on which :meth:`fit` is called) observations. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np diff --git a/sklearn/covariance/_shrunk_covariance.py b/sklearn/covariance/_shrunk_covariance.py index 5fe590b33a1db..a4dea261f2a45 100644 --- a/sklearn/covariance/_shrunk_covariance.py +++ b/sklearn/covariance/_shrunk_covariance.py @@ -91,6 +91,11 @@ class ShrunkCovariance(EmpiricalCovariance): Estimated pseudo inverse matrix. (stored only if store_precision is True) + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np @@ -356,6 +361,11 @@ class LedoitWolf(EmpiricalCovariance): Coefficient in the convex combination used for the computation of the shrunk estimate. Range is [0, 1]. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np @@ -533,6 +543,11 @@ class OAS(EmpiricalCovariance): coefficient in the convex combination used for the computation of the shrunk estimate. Range is [0, 1]. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np diff --git a/sklearn/decomposition/_dict_learning.py b/sklearn/decomposition/_dict_learning.py index 80b64570b3401..030ac06b454b1 100644 --- a/sklearn/decomposition/_dict_learning.py +++ b/sklearn/decomposition/_dict_learning.py @@ -1259,6 +1259,11 @@ class DictionaryLearning(_BaseSparseCoding, BaseEstimator): error_ : array vector of errors at each iteration + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int Number of iterations run. @@ -1492,6 +1497,11 @@ class MiniBatchDictionaryLearning(_BaseSparseCoding, BaseEstimator): `A` `(n_components, n_components)` is the dictionary covariance matrix. `B` `(n_features, n_components)` is the data approximation matrix. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int Number of iterations run. diff --git a/sklearn/decomposition/_factor_analysis.py b/sklearn/decomposition/_factor_analysis.py index 830e81e9268d5..f3167ff225584 100644 --- a/sklearn/decomposition/_factor_analysis.py +++ b/sklearn/decomposition/_factor_analysis.py @@ -120,6 +120,11 @@ class FactorAnalysis(TransformerMixin, BaseEstimator): mean_ : ndarray of shape (n_features,) Per-feature empirical mean, estimated from the training set. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.datasets import load_digits diff --git a/sklearn/decomposition/_fastica.py b/sklearn/decomposition/_fastica.py index 6c374e6e420f8..5faf1985d3fc9 100644 --- a/sklearn/decomposition/_fastica.py +++ b/sklearn/decomposition/_fastica.py @@ -362,6 +362,11 @@ def my_g(x): mean_ : ndarray of shape(n_features,) The mean over features. Only set if `self.whiten` is True. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int If the algorithm is "deflation", n_iter is the maximum number of iterations run across all components. Else diff --git a/sklearn/decomposition/_incremental_pca.py b/sklearn/decomposition/_incremental_pca.py index 486d4a22d8cdb..b1221d69cf914 100644 --- a/sklearn/decomposition/_incremental_pca.py +++ b/sklearn/decomposition/_incremental_pca.py @@ -107,6 +107,11 @@ class IncrementalPCA(_BasePCA): batch_size_ : int Inferred batch size from ``batch_size``. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.datasets import load_digits diff --git a/sklearn/decomposition/_kernel_pca.py b/sklearn/decomposition/_kernel_pca.py index 1e1cdb1722029..70a12f5cb2e38 100644 --- a/sklearn/decomposition/_kernel_pca.py +++ b/sklearn/decomposition/_kernel_pca.py @@ -164,6 +164,11 @@ class KernelPCA(TransformerMixin, BaseEstimator): The data used to fit the model. If `copy_X=False`, then `X_fit_` is a reference. This attribute is used for the calls to transform. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.datasets import load_digits diff --git a/sklearn/decomposition/_lda.py b/sklearn/decomposition/_lda.py index 75b123a118338..3739a66a871e3 100644 --- a/sklearn/decomposition/_lda.py +++ b/sklearn/decomposition/_lda.py @@ -248,6 +248,11 @@ class LatentDirichletAllocation(TransformerMixin, BaseEstimator): n_batch_iter_ : int Number of iterations of the EM step. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int Number of passes over the dataset. diff --git a/sklearn/decomposition/_nmf.py b/sklearn/decomposition/_nmf.py index c8239147eb6c4..39d38af4c5f5a 100644 --- a/sklearn/decomposition/_nmf.py +++ b/sklearn/decomposition/_nmf.py @@ -1179,6 +1179,11 @@ class NMF(TransformerMixin, BaseEstimator): n_iter_ : int Actual number of iterations. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np diff --git a/sklearn/decomposition/_pca.py b/sklearn/decomposition/_pca.py index 765320ccdb5a8..afeedeba28edb 100644 --- a/sklearn/decomposition/_pca.py +++ b/sklearn/decomposition/_pca.py @@ -264,6 +264,11 @@ class PCA(_BasePCA): Equal to the average of (min(n_features, n_samples) - n_components) smallest eigenvalues of the covariance matrix of X. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + See Also -------- KernelPCA : Kernel Principal Component Analysis. diff --git a/sklearn/decomposition/_sparse_pca.py b/sklearn/decomposition/_sparse_pca.py index 7f280db3a3af6..19ff950228f62 100644 --- a/sklearn/decomposition/_sparse_pca.py +++ b/sklearn/decomposition/_sparse_pca.py @@ -88,6 +88,11 @@ class SparsePCA(TransformerMixin, BaseEstimator): Per-feature empirical mean, estimated from the training set. Equal to ``X.mean(axis=0)``. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np @@ -279,6 +284,11 @@ class MiniBatchSparsePCA(SparsePCA): Per-feature empirical mean, estimated from the training set. Equal to ``X.mean(axis=0)``. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np diff --git a/sklearn/decomposition/_truncated_svd.py b/sklearn/decomposition/_truncated_svd.py index 7aa36c59da00e..677c6f1f36fb7 100644 --- a/sklearn/decomposition/_truncated_svd.py +++ b/sklearn/decomposition/_truncated_svd.py @@ -84,6 +84,11 @@ class TruncatedSVD(TransformerMixin, BaseEstimator): The singular values are equal to the 2-norms of the ``n_components`` variables in the lower-dimensional space. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.decomposition import TruncatedSVD diff --git a/sklearn/discriminant_analysis.py b/sklearn/discriminant_analysis.py index 4d94b19574f53..3cb6cc1712f29 100644 --- a/sklearn/discriminant_analysis.py +++ b/sklearn/discriminant_analysis.py @@ -278,6 +278,11 @@ class LinearDiscriminantAnalysis(LinearClassifierMixin, classes_ : array-like of shape (n_classes,) Unique class labels. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + See Also -------- QuadraticDiscriminantAnalysis : Quadratic Discriminant Analysis. @@ -732,6 +737,11 @@ class QuadraticDiscriminantAnalysis(ClassifierMixin, BaseEstimator): classes_ : ndarray of shape (n_classes,) Unique class labels. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis diff --git a/sklearn/dummy.py b/sklearn/dummy.py index 575b38aa7d2a8..d78336730fc99 100644 --- a/sklearn/dummy.py +++ b/sklearn/dummy.py @@ -75,6 +75,11 @@ class DummyClassifier(MultiOutputMixin, ClassifierMixin, BaseEstimator): n_outputs_ : int Number of outputs. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + sparse_output_ : bool True if the array returned from predict is to be in sparse CSC format. Is automatically set to True if the input y is passed in sparse format. @@ -425,6 +430,11 @@ class DummyRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator): Mean or median or quantile of the training targets or constant value given by the user. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_outputs_ : int Number of outputs. diff --git a/sklearn/ensemble/_bagging.py b/sklearn/ensemble/_bagging.py index a4be68ba5e2d6..d63c42d8f5539 100644 --- a/sklearn/ensemble/_bagging.py +++ b/sklearn/ensemble/_bagging.py @@ -537,6 +537,11 @@ class BaggingClassifier(ClassifierMixin, BaseBagging): Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + estimators_ : list of estimators The collection of fitted base estimators. @@ -928,6 +933,11 @@ class BaggingRegressor(RegressorMixin, BaseBagging): Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + estimators_ : list of estimators The collection of fitted sub-estimators. diff --git a/sklearn/ensemble/_forest.py b/sklearn/ensemble/_forest.py index bc29c0362bb3e..ef2de299c27ea 100644 --- a/sklearn/ensemble/_forest.py +++ b/sklearn/ensemble/_forest.py @@ -1199,6 +1199,11 @@ class labels (multi-output problem). Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_outputs_ : int The number of outputs when ``fit`` is performed. @@ -1516,6 +1521,11 @@ class RandomForestRegressor(ForestRegressor): Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_outputs_ : int The number of outputs when ``fit`` is performed. @@ -1841,6 +1851,11 @@ class labels (multi-output problem). Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_outputs_ : int The number of outputs when ``fit`` is performed. @@ -2140,6 +2155,11 @@ class ExtraTreesRegressor(ForestRegressor): Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_outputs_ : int The number of outputs. @@ -2368,6 +2388,11 @@ class RandomTreesEmbedding(BaseForest): Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_outputs_ : int The number of outputs when ``fit`` is performed. diff --git a/sklearn/ensemble/_gb.py b/sklearn/ensemble/_gb.py index 78fee588ecf4e..496757ee9d605 100644 --- a/sklearn/ensemble/_gb.py +++ b/sklearn/ensemble/_gb.py @@ -1052,6 +1052,11 @@ class GradientBoostingClassifier(ClassifierMixin, BaseGradientBoosting): Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_classes_ : int The number of classes. @@ -1604,6 +1609,11 @@ class GradientBoostingRegressor(RegressorMixin, BaseGradientBoosting): Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + max_features_ : int The inferred value of max_features. diff --git a/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py b/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py index 99eb0d265b100..b33b0652ca5be 100644 --- a/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py +++ b/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py @@ -1030,6 +1030,10 @@ class HistGradientBoostingRegressor(RegressorMixin, BaseHistGradientBoosting): is_categorical_ : ndarray, shape (n_features, ) or None Boolean mask for the categorical features. ``None`` if there are no categorical features. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 Examples -------- @@ -1288,6 +1292,10 @@ class HistGradientBoostingClassifier(ClassifierMixin, is_categorical_ : ndarray, shape (n_features, ) or None Boolean mask for the categorical features. ``None`` if there are no categorical features. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 Examples -------- diff --git a/sklearn/ensemble/_iforest.py b/sklearn/ensemble/_iforest.py index 3d2ac0928bd3f..fb8614ae0528e 100644 --- a/sklearn/ensemble/_iforest.py +++ b/sklearn/ensemble/_iforest.py @@ -147,6 +147,11 @@ class IsolationForest(OutlierMixin, BaseBagging): Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Notes ----- The implementation is based on an ensemble of ExtraTreeRegressor. The diff --git a/sklearn/ensemble/_weight_boosting.py b/sklearn/ensemble/_weight_boosting.py index 1b6689b50fafc..7d146e428a50b 100644 --- a/sklearn/ensemble/_weight_boosting.py +++ b/sklearn/ensemble/_weight_boosting.py @@ -359,6 +359,11 @@ class AdaBoostClassifier(ClassifierMixin, BaseWeightBoosting): high cardinality features (many unique values). See :func:`sklearn.inspection.permutation_importance` as an alternative. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + See Also -------- AdaBoostRegressor : An AdaBoost regressor that begins by fitting a @@ -935,6 +940,11 @@ class AdaBoostRegressor(RegressorMixin, BaseWeightBoosting): high cardinality features (many unique values). See :func:`sklearn.inspection.permutation_importance` as an alternative. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.ensemble import AdaBoostRegressor diff --git a/sklearn/feature_selection/_univariate_selection.py b/sklearn/feature_selection/_univariate_selection.py index 989288dbb4ec7..f74ca0e0ac2e2 100644 --- a/sklearn/feature_selection/_univariate_selection.py +++ b/sklearn/feature_selection/_univariate_selection.py @@ -453,6 +453,11 @@ class SelectPercentile(_BaseFilter): pvalues_ : array-like of shape (n_features,) p-values of feature scores, None if `score_func` returned only scores. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.datasets import load_digits @@ -539,6 +544,11 @@ class SelectKBest(_BaseFilter): pvalues_ : array-like of shape (n_features,) p-values of feature scores, None if `score_func` returned only scores. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.datasets import load_digits @@ -624,6 +634,11 @@ class SelectFpr(_BaseFilter): pvalues_ : array-like of shape (n_features,) p-values of feature scores. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.datasets import load_breast_cancer @@ -698,6 +713,11 @@ class SelectFdr(_BaseFilter): pvalues_ : array-like of shape (n_features,) p-values of feature scores. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + References ---------- https://en.wikipedia.org/wiki/False_discovery_rate @@ -768,6 +788,11 @@ class SelectFwe(_BaseFilter): pvalues_ : array-like of shape (n_features,) p-values of feature scores. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + See Also -------- f_classif : ANOVA F-value between label/feature for classification tasks. @@ -823,6 +848,11 @@ class GenericUnivariateSelect(_BaseFilter): pvalues_ : array-like of shape (n_features,) p-values of feature scores, None if `score_func` returned scores only. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.datasets import load_breast_cancer diff --git a/sklearn/feature_selection/_variance_threshold.py b/sklearn/feature_selection/_variance_threshold.py index 39892876a6478..aabbc44ab8fc8 100644 --- a/sklearn/feature_selection/_variance_threshold.py +++ b/sklearn/feature_selection/_variance_threshold.py @@ -28,6 +28,11 @@ class VarianceThreshold(SelectorMixin, BaseEstimator): variances_ : array, shape (n_features,) Variances of individual features. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Notes ----- Allows NaN in the input. diff --git a/sklearn/gaussian_process/_gpc.py b/sklearn/gaussian_process/_gpc.py index d2b418b131c2f..491c33b9621e8 100644 --- a/sklearn/gaussian_process/_gpc.py +++ b/sklearn/gaussian_process/_gpc.py @@ -576,6 +576,11 @@ def optimizer(obj_func, initial_theta, bounds): n_classes_ : int The number of classes in the training data + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.datasets import load_iris diff --git a/sklearn/gaussian_process/_gpr.py b/sklearn/gaussian_process/_gpr.py index ae9e5c403fcf2..4583e013d06df 100644 --- a/sklearn/gaussian_process/_gpr.py +++ b/sklearn/gaussian_process/_gpr.py @@ -137,6 +137,11 @@ def optimizer(obj_func, initial_theta, bounds): log_marginal_likelihood_value_ : float The log-marginal-likelihood of ``self.kernel_.theta`` + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.datasets import make_friedman2 diff --git a/sklearn/impute/_base.py b/sklearn/impute/_base.py index 85303f29c93e9..396b3b95234dc 100644 --- a/sklearn/impute/_base.py +++ b/sklearn/impute/_base.py @@ -187,6 +187,11 @@ class SimpleImputer(_BaseImputer): Indicator used to add binary indicators for missing values. ``None`` if add_indicator is False. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + See Also -------- IterativeImputer : Multivariate imputation of missing values. @@ -604,6 +609,11 @@ class MissingIndicator(TransformerMixin, BaseEstimator): They are computed during ``fit``. For ``features='all'``, it is to ``range(n_features)``. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np diff --git a/sklearn/impute/_iterative.py b/sklearn/impute/_iterative.py index f5688fa96d238..3832bd9d35aa0 100644 --- a/sklearn/impute/_iterative.py +++ b/sklearn/impute/_iterative.py @@ -164,6 +164,11 @@ class IterativeImputer(_BaseImputer): Number of iteration rounds that occurred. Will be less than ``self.max_iter`` if early stopping criterion was reached. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_features_with_missing_ : int Number of features with missing values. diff --git a/sklearn/impute/_knn.py b/sklearn/impute/_knn.py index b9cfe0e1a60a0..f32232512dcde 100644 --- a/sklearn/impute/_knn.py +++ b/sklearn/impute/_knn.py @@ -76,6 +76,11 @@ class KNNImputer(_BaseImputer): Indicator used to add binary indicators for missing values. ``None`` if add_indicator is False. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + References ---------- * Olga Troyanskaya, Michael Cantor, Gavin Sherlock, Pat Brown, Trevor diff --git a/sklearn/kernel_approximation.py b/sklearn/kernel_approximation.py index e7020dea0e970..d6d67fe85e941 100644 --- a/sklearn/kernel_approximation.py +++ b/sklearn/kernel_approximation.py @@ -77,6 +77,11 @@ class PolynomialCountSketch(BaseEstimator, TransformerMixin): Array with random entries in {+1, -1}, used to represent the 2-wise independent hash functions for Count Sketch computation. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.kernel_approximation import PolynomialCountSketch @@ -228,6 +233,10 @@ class RBFSampler(TransformerMixin, BaseEstimator): Random projection directions drawn from the Fourier transform of the RBF kernel. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 Examples -------- @@ -340,6 +349,11 @@ class SkewedChi2Sampler(TransformerMixin, BaseEstimator): Bias term, which will be added to the data. It is uniformly distributed between 0 and 2*pi. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.kernel_approximation import SkewedChi2Sampler @@ -462,6 +476,11 @@ class AdditiveChi2Sampler(TransformerMixin, BaseEstimator): Stored sampling interval. Specified as a parameter if sample_steps not in {1,2,3}. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.datasets import load_digits @@ -690,6 +709,11 @@ class Nystroem(TransformerMixin, BaseEstimator): Normalization matrix needed for embedding. Square root of the kernel matrix on ``components_``. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn import datasets, svm diff --git a/sklearn/kernel_ridge.py b/sklearn/kernel_ridge.py index e562c22daed2f..2bb0b83763625 100644 --- a/sklearn/kernel_ridge.py +++ b/sklearn/kernel_ridge.py @@ -89,6 +89,11 @@ class KernelRidge(MultiOutputMixin, RegressorMixin, BaseEstimator): kernel == "precomputed" this is instead the precomputed training matrix, of shape (n_samples, n_samples). + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + References ---------- * Kevin P. Murphy diff --git a/sklearn/linear_model/_base.py b/sklearn/linear_model/_base.py index 09eeced4f3a09..3a55e3b0090c5 100644 --- a/sklearn/linear_model/_base.py +++ b/sklearn/linear_model/_base.py @@ -560,6 +560,11 @@ class LinearRegression(MultiOutputMixin, RegressorMixin, LinearModel): Independent term in the linear model. Set to 0.0 if `fit_intercept = False`. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + See Also -------- Ridge : Ridge regression addresses some of the diff --git a/sklearn/linear_model/_bayes.py b/sklearn/linear_model/_bayes.py index 1d25ac20aa34e..aabd3d2e0f5a2 100644 --- a/sklearn/linear_model/_bayes.py +++ b/sklearn/linear_model/_bayes.py @@ -131,6 +131,11 @@ class BayesianRidge(RegressorMixin, LinearModel): If `normalize=True`, parameter used to scale data to a unit standard deviation. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn import linear_model @@ -491,6 +496,11 @@ class ARDRegression(RegressorMixin, LinearModel): If `normalize=True`, parameter used to scale data to a unit standard deviation. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn import linear_model diff --git a/sklearn/linear_model/_coordinate_descent.py b/sklearn/linear_model/_coordinate_descent.py index da50a3a817a38..99517ff6e5bbf 100644 --- a/sklearn/linear_model/_coordinate_descent.py +++ b/sklearn/linear_model/_coordinate_descent.py @@ -666,6 +666,11 @@ class ElasticNet(MultiOutputMixin, RegressorMixin, LinearModel): Given param alpha, the dual gaps at the end of the optimization, same shape as each observation of y. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.linear_model import ElasticNet @@ -993,6 +998,11 @@ class Lasso(ElasticNet): Number of iterations run by the coordinate descent solver to reach the specified tolerance. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn import linear_model @@ -1482,6 +1492,11 @@ class LassoCV(RegressorMixin, LinearModelCV): Number of iterations run by the coordinate descent solver to reach the specified tolerance for the optimal alpha. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.linear_model import LassoCV @@ -1667,6 +1682,11 @@ class ElasticNetCV(RegressorMixin, LinearModelCV): Number of iterations run by the coordinate descent solver to reach the specified tolerance for the optimal alpha. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.linear_model import ElasticNetCV @@ -1848,6 +1868,11 @@ class MultiTaskElasticNet(Lasso): (n_tasks, n_features) Sparse representation of the `coef_`. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn import linear_model @@ -2049,6 +2074,11 @@ class MultiTaskLasso(MultiTaskElasticNet): (n_tasks, n_features) Sparse representation of the `coef_`. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn import linear_model @@ -2228,6 +2258,11 @@ class MultiTaskElasticNetCV(RegressorMixin, LinearModelCV): dual_gap_ : float The dual gap at the end of the optimization for the optimal alpha. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn import linear_model @@ -2407,6 +2442,11 @@ class MultiTaskLassoCV(RegressorMixin, LinearModelCV): dual_gap_ : float The dual gap at the end of the optimization for the optimal alpha. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.linear_model import MultiTaskLassoCV diff --git a/sklearn/linear_model/_glm/glm.py b/sklearn/linear_model/_glm/glm.py index 7d98f7734b322..5da65c77cf2f4 100644 --- a/sklearn/linear_model/_glm/glm.py +++ b/sklearn/linear_model/_glm/glm.py @@ -433,6 +433,11 @@ class PoissonRegressor(GeneralizedLinearRegressor): intercept_ : float Intercept (a.k.a. bias) added to linear predictor. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int Actual number of iterations used in the solver. @@ -517,6 +522,11 @@ class GammaRegressor(GeneralizedLinearRegressor): intercept_ : float Intercept (a.k.a. bias) added to linear predictor. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int Actual number of iterations used in the solver. @@ -633,6 +643,11 @@ class TweedieRegressor(GeneralizedLinearRegressor): n_iter_ : int Actual number of iterations used in the solver. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples ---------- >>> from sklearn import linear_model diff --git a/sklearn/linear_model/_huber.py b/sklearn/linear_model/_huber.py index a8ae066d9ff63..93cdb4ae8b5dc 100644 --- a/sklearn/linear_model/_huber.py +++ b/sklearn/linear_model/_huber.py @@ -179,6 +179,11 @@ class HuberRegressor(LinearModel, RegressorMixin, BaseEstimator): scale_ : float The value by which ``|y - X'w - c|`` is scaled down. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int Number of iterations that ``scipy.optimize.minimize(method="L-BFGS-B")`` has run for. diff --git a/sklearn/linear_model/_least_angle.py b/sklearn/linear_model/_least_angle.py index 3485344b99e02..a1fe31557cbe6 100644 --- a/sklearn/linear_model/_least_angle.py +++ b/sklearn/linear_model/_least_angle.py @@ -899,6 +899,11 @@ class Lars(MultiOutputMixin, RegressorMixin, LinearModel): The number of iterations taken by lars_path to find the grid of alphas for each target. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn import linear_model @@ -1157,6 +1162,11 @@ class LassoLars(Lars): The number of iterations taken by lars_path to find the grid of alphas for each target. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn import linear_model @@ -1420,6 +1430,11 @@ class LarsCV(Lars): n_iter_ : array-like or int the number of iterations run by Lars with the optimal alpha. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.linear_model import LarsCV @@ -1654,6 +1669,11 @@ class LassoLarsCV(LarsCV): active_ : list of int Indices of active variables at the end of the path. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.linear_model import LassoLarsCV @@ -1799,6 +1819,10 @@ class LassoLarsIC(LassoLars): chosen. This value is larger by a factor of ``n_samples`` compared to Eqns. 2.15 and 2.16 in (Zou et al, 2007). + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 Examples -------- diff --git a/sklearn/linear_model/_logistic.py b/sklearn/linear_model/_logistic.py index abca6bb30e71f..c4876486e16de 100644 --- a/sklearn/linear_model/_logistic.py +++ b/sklearn/linear_model/_logistic.py @@ -1212,6 +1212,11 @@ class LogisticRegression(LinearClassifierMixin, corresponds to outcome 1 (True) and `-intercept_` corresponds to outcome 0 (False). + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : ndarray of shape (n_classes,) or (1, ) Actual number of iterations for all classes. If binary or multinomial, it returns only 1 element. For liblinear solver, only the maximum @@ -1764,6 +1769,10 @@ class LogisticRegressionCV(LogisticRegression, If ``penalty='elasticnet'``, the shape is ``(n_classes, n_folds, n_cs, n_l1_ratios)`` or ``(1, n_folds, n_cs, n_l1_ratios)``. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 Examples -------- diff --git a/sklearn/linear_model/_omp.py b/sklearn/linear_model/_omp.py index c362fd4d73469..d61f8ba82a20c 100644 --- a/sklearn/linear_model/_omp.py +++ b/sklearn/linear_model/_omp.py @@ -592,6 +592,11 @@ class OrthogonalMatchingPursuit(MultiOutputMixin, RegressorMixin, LinearModel): `n_nonzero_coefs` is None and `tol` is None this value is either set to 10% of `n_features` or 1, whichever is greater. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.linear_model import OrthogonalMatchingPursuit @@ -835,6 +840,11 @@ class OrthogonalMatchingPursuitCV(RegressorMixin, LinearModel): Number of active features across every target for the model refit with the best hyperparameters got by cross-validating across all folds. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.linear_model import OrthogonalMatchingPursuitCV diff --git a/sklearn/linear_model/_passive_aggressive.py b/sklearn/linear_model/_passive_aggressive.py index 678061be3c691..3a0a82debcc7b 100644 --- a/sklearn/linear_model/_passive_aggressive.py +++ b/sklearn/linear_model/_passive_aggressive.py @@ -120,6 +120,11 @@ class PassiveAggressiveClassifier(BaseSGDClassifier): intercept_ : array, shape = [1] if n_classes == 2 else [n_classes] Constants in decision function. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int The actual number of iterations to reach the stopping criterion. For multiclass fits, it is the maximum over every binary fit. @@ -354,6 +359,11 @@ class PassiveAggressiveRegressor(BaseSGDRegressor): intercept_ : array, shape = [1] if n_classes == 2 else [n_classes] Constants in decision function. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int The actual number of iterations to reach the stopping criterion. diff --git a/sklearn/linear_model/_perceptron.py b/sklearn/linear_model/_perceptron.py index b2bb145b904c8..632996cd00c48 100644 --- a/sklearn/linear_model/_perceptron.py +++ b/sklearn/linear_model/_perceptron.py @@ -117,6 +117,11 @@ class Perceptron(BaseSGDClassifier): The function that determines the loss, or difference between the output of the algorithm and the target values. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int The actual number of iterations to reach the stopping criterion. For multiclass fits, it is the maximum over every binary fit. diff --git a/sklearn/linear_model/_quantile.py b/sklearn/linear_model/_quantile.py index bf8fea4552c9d..a39f48a804ffc 100644 --- a/sklearn/linear_model/_quantile.py +++ b/sklearn/linear_model/_quantile.py @@ -59,6 +59,11 @@ class QuantileRegressor(LinearModel, RegressorMixin, BaseEstimator): intercept_ : float The intercept of the model, aka bias term. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int The actual number of iterations performed by the solver. diff --git a/sklearn/linear_model/_ransac.py b/sklearn/linear_model/_ransac.py index f53785cfe0ced..5ee5b1e2fa502 100644 --- a/sklearn/linear_model/_ransac.py +++ b/sklearn/linear_model/_ransac.py @@ -192,6 +192,11 @@ class RANSACRegressor(MetaEstimatorMixin, RegressorMixin, .. versionadded:: 0.19 + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.linear_model import RANSACRegressor diff --git a/sklearn/linear_model/_ridge.py b/sklearn/linear_model/_ridge.py index 433e0c4313efc..d82aca05fee7c 100644 --- a/sklearn/linear_model/_ridge.py +++ b/sklearn/linear_model/_ridge.py @@ -717,6 +717,11 @@ class Ridge(MultiOutputMixin, RegressorMixin, _BaseRidge): .. versionadded:: 0.17 + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + See Also -------- RidgeClassifier : Ridge classifier. @@ -877,6 +882,11 @@ class RidgeClassifier(LinearClassifierMixin, _BaseRidge): classes_ : ndarray of shape (n_classes,) The classes labels. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + See Also -------- Ridge : Ridge regression. @@ -1793,6 +1803,11 @@ class RidgeCV(MultiOutputMixin, RegressorMixin, _BaseRidgeCV): .. versionadded:: 0.23 + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.datasets import load_diabetes @@ -1908,6 +1923,11 @@ class RidgeClassifierCV(LinearClassifierMixin, _BaseRidgeCV): classes_ : ndarray of shape (n_classes,) The classes labels. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.datasets import load_breast_cancer diff --git a/sklearn/linear_model/_stochastic_gradient.py b/sklearn/linear_model/_stochastic_gradient.py index 78565178706a8..eb84c06ac93b3 100644 --- a/sklearn/linear_model/_stochastic_gradient.py +++ b/sklearn/linear_model/_stochastic_gradient.py @@ -934,6 +934,11 @@ class SGDClassifier(BaseSGDClassifier): Number of weight updates performed during training. Same as ``(n_iter_ * n_samples)``. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + See Also -------- sklearn.svm.LinearSVC : Linear support vector classification. @@ -1538,6 +1543,11 @@ class SGDRegressor(BaseSGDRegressor): Number of weight updates performed during training. Same as ``(n_iter_ * n_samples)``. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np @@ -1693,6 +1703,11 @@ class SGDOneClassSVM(BaseSGD, OutlierMixin): loss_function_ : concrete ``LossFunction`` + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np diff --git a/sklearn/linear_model/_theil_sen.py b/sklearn/linear_model/_theil_sen.py index 4c75613c28a9b..c14b6979ef4d9 100644 --- a/sklearn/linear_model/_theil_sen.py +++ b/sklearn/linear_model/_theil_sen.py @@ -272,6 +272,11 @@ class TheilSenRegressor(RegressorMixin, LinearModel): Number of combinations taken into account from 'n choose k', where n is the number of samples and k is the number of subsamples. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.linear_model import TheilSenRegressor diff --git a/sklearn/manifold/_isomap.py b/sklearn/manifold/_isomap.py index 63be19c1c287d..4cf3b1885d2d0 100644 --- a/sklearn/manifold/_isomap.py +++ b/sklearn/manifold/_isomap.py @@ -104,6 +104,11 @@ class Isomap(TransformerMixin, BaseEstimator): dist_matrix_ : array-like, shape (n_samples, n_samples) Stores the geodesic distance matrix of training data. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.datasets import load_digits diff --git a/sklearn/manifold/_locally_linear.py b/sklearn/manifold/_locally_linear.py index 0fcd5f543c4d0..17e829270f1a7 100644 --- a/sklearn/manifold/_locally_linear.py +++ b/sklearn/manifold/_locally_linear.py @@ -603,6 +603,11 @@ class LocallyLinearEmbedding(TransformerMixin, reconstruction_error_ : float Reconstruction error associated with `embedding_` + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + nbrs_ : NearestNeighbors object Stores nearest neighbors instance, including BallTree or KDtree if applicable. diff --git a/sklearn/manifold/_mds.py b/sklearn/manifold/_mds.py index d92ab67767fa3..f833f24f981a3 100644 --- a/sklearn/manifold/_mds.py +++ b/sklearn/manifold/_mds.py @@ -343,6 +343,11 @@ class MDS(BaseEstimator): - or constructs a dissimilarity matrix from data using Euclidean distances. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int The number of iterations corresponding to the best stress. diff --git a/sklearn/manifold/_spectral_embedding.py b/sklearn/manifold/_spectral_embedding.py index 49e64401b6c00..01bdf06b92ed0 100644 --- a/sklearn/manifold/_spectral_embedding.py +++ b/sklearn/manifold/_spectral_embedding.py @@ -440,6 +440,11 @@ class SpectralEmbedding(BaseEstimator): affinity_matrix_ : ndarray of shape (n_samples, n_samples) Affinity_matrix constructed from samples or precomputed. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_neighbors_ : int Number of nearest neighbors effectively used. diff --git a/sklearn/manifold/_t_sne.py b/sklearn/manifold/_t_sne.py index 8e42d48f4ef07..7142909ae292c 100644 --- a/sklearn/manifold/_t_sne.py +++ b/sklearn/manifold/_t_sne.py @@ -627,6 +627,11 @@ class TSNE(BaseEstimator): kl_divergence_ : float Kullback-Leibler divergence after optimization. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int Number of iterations run. diff --git a/sklearn/model_selection/_search_successive_halving.py b/sklearn/model_selection/_search_successive_halving.py index 2f5c465d6cf41..81c70945b894e 100644 --- a/sklearn/model_selection/_search_successive_halving.py +++ b/sklearn/model_selection/_search_successive_halving.py @@ -560,6 +560,13 @@ class HalvingGridSearchCV(BaseSuccessiveHalving): This is present only if ``refit`` is not False. + multimetric_ : bool + Whether or not the scorers compute several metrics. + + classes_ : ndarray of shape (n_classes,) + The classes labels. This is present only if ``refit`` is specified and + the underlying estimator is a classifier. + See Also -------- :class:`HalvingRandomSearchCV`: @@ -850,6 +857,13 @@ class HalvingRandomSearchCV(BaseSuccessiveHalving): This is present only if ``refit`` is not False. + multimetric_ : bool + Whether or not the scorers compute several metrics. + + classes_ : ndarray of shape (n_classes,) + The classes labels. This is present only if ``refit`` is specified and + the underlying estimator is a classifier. + See Also -------- :class:`HalvingGridSearchCV`: diff --git a/sklearn/naive_bayes.py b/sklearn/naive_bayes.py index 7e936ac3a0c8e..7c46a771a2fd4 100644 --- a/sklearn/naive_bayes.py +++ b/sklearn/naive_bayes.py @@ -150,10 +150,15 @@ class GaussianNB(_BaseNB): probability of each class. classes_ : ndarray of shape (n_classes,) - class labels known to the classifier + class labels known to the classifier. epsilon_ : float - absolute additive value to variances + absolute additive value to variances. + + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 sigma_ : ndarray of shape (n_classes, n_features) Variance of each feature per class. @@ -168,7 +173,7 @@ class labels known to the classifier .. versionadded:: 1.0 theta_ : ndarray of shape (n_classes, n_features) - mean of each feature per class + mean of each feature per class. Examples -------- @@ -767,6 +772,11 @@ class MultinomialNB(_BaseDiscreteNB): Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np @@ -896,6 +906,11 @@ class ComplementNB(_BaseDiscreteNB): Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np @@ -1016,6 +1031,11 @@ class BernoulliNB(_BaseDiscreteNB): Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np @@ -1157,6 +1177,11 @@ class CategoricalNB(_BaseDiscreteNB): Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_categories_ : ndarray of shape (n_features,), dtype=np.int64 Number of categories for each feature. This value is inferred from the data or set by the minimum number of categories. diff --git a/sklearn/neighbors/_classification.py b/sklearn/neighbors/_classification.py index 1fd1fb01c9762..76dd3db7444ab 100644 --- a/sklearn/neighbors/_classification.py +++ b/sklearn/neighbors/_classification.py @@ -101,6 +101,11 @@ class KNeighborsClassifier(KNeighborsMixin, `p` parameter value if the `effective_metric_` attribute is set to 'minkowski'. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_samples_fit_ : int Number of samples in the fitted data. @@ -365,6 +370,11 @@ class RadiusNeighborsClassifier(RadiusNeighborsMixin, `p` parameter value if the `effective_metric_` attribute is set to 'minkowski'. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_samples_fit_ : int Number of samples in the fitted data. diff --git a/sklearn/neighbors/_graph.py b/sklearn/neighbors/_graph.py index 7676d42d62c18..247aef31ba2f7 100644 --- a/sklearn/neighbors/_graph.py +++ b/sklearn/neighbors/_graph.py @@ -286,6 +286,11 @@ class KNeighborsTransformer(KNeighborsMixin, `p` parameter value if the `effective_metric_` attribute is set to 'minkowski'. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_samples_fit_ : int Number of samples in the fitted data. @@ -468,6 +473,11 @@ class RadiusNeighborsTransformer(RadiusNeighborsMixin, `p` parameter value if the `effective_metric_` attribute is set to 'minkowski'. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_samples_fit_ : int Number of samples in the fitted data. diff --git a/sklearn/neighbors/_kde.py b/sklearn/neighbors/_kde.py index 816b023e0f23e..1ebd713b16e69 100644 --- a/sklearn/neighbors/_kde.py +++ b/sklearn/neighbors/_kde.py @@ -71,6 +71,11 @@ class KernelDensity(BaseEstimator): Attributes ---------- + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + tree_ : ``BinaryTree`` instance The tree algorithm for fast generalized N-point problems. diff --git a/sklearn/neighbors/_lof.py b/sklearn/neighbors/_lof.py index 941b9de781f9a..7b87076516687 100644 --- a/sklearn/neighbors/_lof.py +++ b/sklearn/neighbors/_lof.py @@ -157,6 +157,11 @@ class LocalOutlierFactor(KNeighborsMixin, effective_metric_params_ : dict The effective additional keyword arguments for the metric function. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_samples_fit_ : int It is the number of samples in the fitted data. diff --git a/sklearn/neighbors/_nca.py b/sklearn/neighbors/_nca.py index 5951b66ea7dbf..a3701a28909e8 100644 --- a/sklearn/neighbors/_nca.py +++ b/sklearn/neighbors/_nca.py @@ -121,6 +121,11 @@ class NeighborhoodComponentsAnalysis(TransformerMixin, BaseEstimator): components_ : ndarray of shape (n_components, n_features) The linear transformation learned during fitting. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int Counts the number of iterations performed by the optimizer. diff --git a/sklearn/neighbors/_nearest_centroid.py b/sklearn/neighbors/_nearest_centroid.py index c5f6a612b0395..4908465d7fafd 100644 --- a/sklearn/neighbors/_nearest_centroid.py +++ b/sklearn/neighbors/_nearest_centroid.py @@ -55,6 +55,11 @@ class NearestCentroid(ClassifierMixin, BaseEstimator): classes_ : array of shape (n_classes,) The unique classes labels. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.neighbors import NearestCentroid diff --git a/sklearn/neighbors/_regression.py b/sklearn/neighbors/_regression.py index be60abcc64cb5..64a4e3df8fcae 100644 --- a/sklearn/neighbors/_regression.py +++ b/sklearn/neighbors/_regression.py @@ -106,6 +106,11 @@ class KNeighborsRegressor(KNeighborsMixin, `p` parameter value if the `effective_metric_` attribute is set to 'minkowski'. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_samples_fit_ : int Number of samples in the fitted data. @@ -313,6 +318,11 @@ class RadiusNeighborsRegressor(RadiusNeighborsMixin, `p` parameter value if the `effective_metric_` attribute is set to 'minkowski'. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_samples_fit_ : int Number of samples in the fitted data. diff --git a/sklearn/neighbors/_unsupervised.py b/sklearn/neighbors/_unsupervised.py index 0f14c56e8bac2..df452ff4ff1fa 100644 --- a/sklearn/neighbors/_unsupervised.py +++ b/sklearn/neighbors/_unsupervised.py @@ -72,6 +72,11 @@ class NearestNeighbors(KNeighborsMixin, effective_metric_params_ : dict Parameters for the metric used to compute distances to neighbors. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_samples_fit_ : int Number of samples in the fitted data. diff --git a/sklearn/neural_network/_multilayer_perceptron.py b/sklearn/neural_network/_multilayer_perceptron.py index 72120ad369275..e6c1ba340a7b3 100644 --- a/sklearn/neural_network/_multilayer_perceptron.py +++ b/sklearn/neural_network/_multilayer_perceptron.py @@ -886,6 +886,11 @@ class MLPClassifier(ClassifierMixin, BaseMultilayerPerceptron): The ith element in the list represents the bias vector corresponding to layer i + 1. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int The number of iterations the solver has run. @@ -1310,6 +1315,11 @@ class MLPRegressor(RegressorMixin, BaseMultilayerPerceptron): The ith element in the list represents the bias vector corresponding to layer i + 1. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int The number of iterations the solver has run. diff --git a/sklearn/neural_network/_rbm.py b/sklearn/neural_network/_rbm.py index b69a2c496a2c9..42a9eb81e30cd 100644 --- a/sklearn/neural_network/_rbm.py +++ b/sklearn/neural_network/_rbm.py @@ -85,6 +85,11 @@ class BernoulliRBM(TransformerMixin, BaseEstimator): where batch_size in the number of examples per minibatch and n_components is the number of hidden units. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- diff --git a/sklearn/preprocessing/_data.py b/sklearn/preprocessing/_data.py index 393693fc87d2d..82e6d5d85ec19 100644 --- a/sklearn/preprocessing/_data.py +++ b/sklearn/preprocessing/_data.py @@ -307,6 +307,11 @@ class MinMaxScaler(TransformerMixin, BaseEstimator): .. versionadded:: 0.17 *data_range_* + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_samples_seen_ : int The number of samples processed by the estimator. It will be reset on new calls to fit, but increments across @@ -657,6 +662,11 @@ class StandardScaler(TransformerMixin, BaseEstimator): The variance for each feature in the training set. Used to compute `scale_`. Equal to ``None`` when ``with_std=False``. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_samples_seen_ : int or ndarray of shape (n_features,) The number of samples processed by the estimator for each feature. If there are no missing samples, the ``n_samples_seen`` will be an @@ -990,6 +1000,11 @@ class MaxAbsScaler(TransformerMixin, BaseEstimator): max_abs_ : ndarray of shape (n_features,) Per feature maximum absolute value. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_samples_seen_ : int The number of samples processed by the estimator. Will be reset on new calls to fit, but increments across ``partial_fit`` calls. @@ -1300,6 +1315,11 @@ class RobustScaler(TransformerMixin, BaseEstimator): .. versionadded:: 0.17 *scale_* attribute. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.preprocessing import RobustScaler @@ -1701,19 +1721,12 @@ class Normalizer(TransformerMixin, BaseEstimator): copy (if the input is already a numpy array or a scipy.sparse CSR matrix). - Examples - -------- - >>> from sklearn.preprocessing import Normalizer - >>> X = [[4, 1, 2, 2], - ... [1, 3, 9, 3], - ... [5, 7, 5, 1]] - >>> transformer = Normalizer().fit(X) # fit does nothing. - >>> transformer - Normalizer() - >>> transformer.transform(X) - array([[0.8, 0.2, 0.4, 0.4], - [0.1, 0.3, 0.9, 0.3], - [0.5, 0.7, 0.5, 0.1]]) + Attributes + ---------- + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 Notes ----- @@ -1727,6 +1740,20 @@ class Normalizer(TransformerMixin, BaseEstimator): See Also -------- normalize : Equivalent function without the estimator API. + + Examples + -------- + >>> from sklearn.preprocessing import Normalizer + >>> X = [[4, 1, 2, 2], + ... [1, 3, 9, 3], + ... [5, 7, 5, 1]] + >>> transformer = Normalizer().fit(X) # fit does nothing. + >>> transformer + Normalizer() + >>> transformer.transform(X) + array([[0.8, 0.2, 0.4, 0.4], + [0.1, 0.3, 0.9, 0.3], + [0.5, 0.7, 0.5, 0.1]]) """ def __init__(self, norm='l2', *, copy=True): @@ -1856,6 +1883,13 @@ class Binarizer(TransformerMixin, BaseEstimator): set to False to perform inplace binarization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR matrix). + Attributes + ---------- + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> from sklearn.preprocessing import Binarizer @@ -1972,6 +2006,11 @@ class KernelCenterer(TransformerMixin, BaseEstimator): K_fit_all_ : float Average of kernel matrix. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + References ---------- .. [1] `Schölkopf, Bernhard, Alexander Smola, and Klaus-Robert Müller. @@ -2199,6 +2238,11 @@ class QuantileTransformer(TransformerMixin, BaseEstimator): references_ : ndarray of shape (n_quantiles, ) Quantiles of references. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np @@ -2724,6 +2768,11 @@ class PowerTransformer(TransformerMixin, BaseEstimator): lambdas_ : ndarray of float of shape (n_features,) The parameters of the power transformation for the selected features. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + Examples -------- >>> import numpy as np diff --git a/sklearn/preprocessing/_discretization.py b/sklearn/preprocessing/_discretization.py index d7565ff2fb4b3..327c6211d66f2 100644 --- a/sklearn/preprocessing/_discretization.py +++ b/sklearn/preprocessing/_discretization.py @@ -64,13 +64,18 @@ class KBinsDiscretizer(TransformerMixin, BaseEstimator): Attributes ---------- + bin_edges_ : ndarray of ndarray of shape (n_features,) + The edges of each bin. Contain arrays of varying shapes ``(n_bins_, )`` + Ignored features will have empty arrays. + n_bins_ : ndarray of shape (n_features,), dtype=np.int_ Number of bins per feature. Bins whose width are too small (i.e., <= 1e-8) are removed with a warning. - bin_edges_ : ndarray of ndarray of shape (n_features,) - The edges of each bin. Contain arrays of varying shapes ``(n_bins_, )`` - Ignored features will have empty arrays. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 See Also -------- diff --git a/sklearn/preprocessing/_polynomial.py b/sklearn/preprocessing/_polynomial.py index 930e85c783711..6c520354b379d 100644 --- a/sklearn/preprocessing/_polynomial.py +++ b/sklearn/preprocessing/_polynomial.py @@ -53,26 +53,6 @@ class PolynomialFeatures(TransformerMixin, BaseEstimator): .. versionadded:: 0.21 - Examples - -------- - >>> import numpy as np - >>> from sklearn.preprocessing import PolynomialFeatures - >>> X = np.arange(6).reshape(3, 2) - >>> X - array([[0, 1], - [2, 3], - [4, 5]]) - >>> poly = PolynomialFeatures(2) - >>> poly.fit_transform(X) - array([[ 1., 0., 1., 0., 0., 1.], - [ 1., 2., 3., 4., 6., 9.], - [ 1., 4., 5., 16., 20., 25.]]) - >>> poly = PolynomialFeatures(interaction_only=True) - >>> poly.fit_transform(X) - array([[ 1., 0., 1., 0.], - [ 1., 2., 3., 6.], - [ 1., 4., 5., 20.]]) - Attributes ---------- powers_ : ndarray of shape (n_output_features, n_input_features) @@ -81,6 +61,11 @@ class PolynomialFeatures(TransformerMixin, BaseEstimator): n_input_features_ : int The total number of input features. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_output_features_ : int The total number of polynomial output features. The number of output features is computed by iterating over all suitably sized combinations @@ -99,6 +84,26 @@ class PolynomialFeatures(TransformerMixin, BaseEstimator): See :ref:`examples/linear_model/plot_polynomial_interpolation.py ` + + Examples + -------- + >>> import numpy as np + >>> from sklearn.preprocessing import PolynomialFeatures + >>> X = np.arange(6).reshape(3, 2) + >>> X + array([[0, 1], + [2, 3], + [4, 5]]) + >>> poly = PolynomialFeatures(2) + >>> poly.fit_transform(X) + array([[ 1., 0., 1., 0., 0., 1.], + [ 1., 2., 3., 4., 6., 9.], + [ 1., 4., 5., 16., 20., 25.]]) + >>> poly = PolynomialFeatures(interaction_only=True) + >>> poly.fit_transform(X) + array([[ 1., 0., 1., 0.], + [ 1., 2., 3., 6.], + [ 1., 4., 5., 20.]]) """ def __init__(self, degree=2, *, interaction_only=False, include_bias=True, order='C'): diff --git a/sklearn/semi_supervised/_label_propagation.py b/sklearn/semi_supervised/_label_propagation.py index e89dfab9310ab..944b6b7acb149 100644 --- a/sklearn/semi_supervised/_label_propagation.py +++ b/sklearn/semi_supervised/_label_propagation.py @@ -350,6 +350,11 @@ class LabelPropagation(BaseLabelPropagation): transduction_ : ndarray of shape (n_samples) Label assigned to each item via the transduction. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int Number of iterations run. @@ -463,6 +468,11 @@ class LabelSpreading(BaseLabelPropagation): transduction_ : ndarray of shape (n_samples,) Label assigned to each item via the transduction. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int Number of iterations run. diff --git a/sklearn/semi_supervised/_self_training.py b/sklearn/semi_supervised/_self_training.py index 54fa9ba45e1b8..761909903e8b0 100644 --- a/sklearn/semi_supervised/_self_training.py +++ b/sklearn/semi_supervised/_self_training.py @@ -86,6 +86,11 @@ class SelfTrainingClassifier(MetaEstimatorMixin, BaseEstimator): When a sample has iteration -1, the sample was not labeled in any iteration. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int The number of rounds of self-training, that is the number of times the base estimator is fitted on relabeled variants of the training set. diff --git a/sklearn/svm/_classes.py b/sklearn/svm/_classes.py index 050855c25c06a..8946e77ef905f 100644 --- a/sklearn/svm/_classes.py +++ b/sklearn/svm/_classes.py @@ -114,6 +114,11 @@ class LinearSVC(LinearClassifierMixin, classes_ : ndarray of shape (n_classes,) The unique classes labels. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int Maximum number of iterations run across all classes. @@ -331,6 +336,11 @@ class LinearSVR(RegressorMixin, LinearModel): intercept_ : ndarray of shape (1) if n_classes == 2 else (n_classes) Constants in decision function. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_iter_ : int Maximum number of iterations run across all classes. @@ -583,6 +593,11 @@ class SVC(BaseSVC): intercept_ : ndarray of shape (n_classes * (n_classes - 1) / 2,) Constants in decision function. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + support_ : ndarray of shape (n_SV) Indices of support vectors. @@ -803,6 +818,11 @@ class NuSVC(BaseSVC): intercept_ : ndarray of shape (n_classes * (n_classes - 1) / 2,) Constants in decision function. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + support_ : ndarray of shape (n_SV,) Indices of support vectors. @@ -981,6 +1001,11 @@ class SVR(RegressorMixin, BaseLibSVM): intercept_ : ndarray of shape (1,) Constants in decision function. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_support_ : ndarray of shape (n_classes,), dtype=int32 Number of support vectors for each class. @@ -1133,6 +1158,11 @@ class NuSVR(RegressorMixin, BaseLibSVM): intercept_ : ndarray of shape (1,) Constants in decision function. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_support_ : ndarray of shape (n_classes,), dtype=int32 Number of support vectors for each class. @@ -1281,6 +1311,11 @@ class OneClassSVM(OutlierMixin, BaseLibSVM): intercept_ : ndarray of shape (1,) Constant in the decision function. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_support_ : ndarray of shape (n_classes,), dtype=int32 Number of support vectors for each class. diff --git a/sklearn/tests/test_docstring_parameters.py b/sklearn/tests/test_docstring_parameters.py index 85d8ad0cf6a36..ae9a29622c4aa 100644 --- a/sklearn/tests/test_docstring_parameters.py +++ b/sklearn/tests/test_docstring_parameters.py @@ -176,30 +176,8 @@ def _construct_searchcv_instance(SearchCV): N_FEATURES_MODULES_TO_IGNORE = { - 'compose', - 'covariance', - 'decomposition', - 'discriminant_analysis', - 'dummy', - 'ensemble', - 'feature_selection', - 'gaussian_process', - 'impute', - 'isotonic', - 'kernel_approximation', - 'kernel_ridge', - 'linear_model', - 'manifold', 'model_selection', 'multioutput', - 'naive_bayes', - 'neighbors', - 'neural_network', - 'preprocessing', - 'random_projection', - 'semi_supervised', - 'svm', - 'tree' } @@ -212,22 +190,28 @@ def test_fit_docstring_attributes(name, Estimator): doc = docscrape.ClassDoc(Estimator) attributes = doc['Attributes'] - IGNORED = {'ClassifierChain', 'ColumnTransformer', - 'CountVectorizer', 'DictVectorizer', - 'GaussianRandomProjection', - 'MultiOutputClassifier', 'MultiOutputRegressor', - 'NoSampleWeightWrapper', 'RFE', 'RFECV', - 'RegressorChain', 'SelectFromModel', - 'SparseCoder', 'SparseRandomProjection', - 'SpectralBiclustering', 'StackingClassifier', - 'StackingRegressor', 'TfidfVectorizer', 'VotingClassifier', - 'VotingRegressor', 'SequentialFeatureSelector', - 'HalvingGridSearchCV', 'HalvingRandomSearchCV'} + IGNORED = { + 'ClassifierChain', + 'CountVectorizer', 'DictVectorizer', + 'GaussianRandomProjection', + 'MultiOutputClassifier', 'MultiOutputRegressor', + 'NoSampleWeightWrapper', 'RFE', 'RFECV', + 'RegressorChain', 'SelectFromModel', + 'SparseCoder', 'SparseRandomProjection', + 'SpectralBiclustering', 'StackingClassifier', + 'StackingRegressor', 'TfidfVectorizer', 'VotingClassifier', + 'VotingRegressor', 'SequentialFeatureSelector', + } if Estimator.__name__ in IGNORED or Estimator.__name__.startswith('_'): pytest.skip("Estimator cannot be fit easily to test fit attributes") - if Estimator.__name__ in ("RandomizedSearchCV", "GridSearchCV"): + if Estimator.__name__ in ( + "HalvingRandomSearchCV", + "RandomizedSearchCV", + "HalvingGridSearchCV", + "GridSearchCV", + ): est = _construct_searchcv_instance(Estimator) else: est = _construct_instance(Estimator) diff --git a/sklearn/tree/_classes.py b/sklearn/tree/_classes.py index a79a850f3b7c7..ba5bf2873bf18 100644 --- a/sklearn/tree/_classes.py +++ b/sklearn/tree/_classes.py @@ -796,6 +796,11 @@ class DecisionTreeClassifier(ClassifierMixin, BaseDecisionTree): n_features_ : int The number of features when ``fit`` is performed. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_outputs_ : int The number of outputs when ``fit`` is performed. @@ -1161,6 +1166,11 @@ class DecisionTreeRegressor(RegressorMixin, BaseDecisionTree): n_features_ : int The number of features when ``fit`` is performed. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_outputs_ : int The number of outputs when ``fit`` is performed. @@ -1477,6 +1487,11 @@ class ExtraTreeClassifier(DecisionTreeClassifier): n_features_ : int The number of features when ``fit`` is performed. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + n_outputs_ : int The number of outputs when ``fit`` is performed. @@ -1699,6 +1714,11 @@ class ExtraTreeRegressor(DecisionTreeRegressor): n_features_ : int The number of features when ``fit`` is performed. + n_features_in_ : int + Number of features seen during :term:`fit`. + + .. versionadded:: 0.24 + feature_importances_ : ndarray of shape (n_features,) Return impurity-based feature importances (the higher, the more important the feature).