8000 DOC univariate_selection examples in docstrings (#11720) · scikit-learn/scikit-learn@360fc07 · GitHub
[go: up one dir, main page]

Skip to content

Commit 360fc07

Browse files
adrinjalalijnothman
authored andcommitted
DOC univariate_selection examples in docstrings (#11720)
1 parent a141e2b commit 360fc07

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

sklearn/feature_selection/univariate_selection.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,17 @@ class SelectPercentile(_BaseFilter):
389389
pvalues_ : array-like, shape=(n_features,)
390390
p-values of feature scores, None if `score_func` returned only scores.
391391
392+
Examples
393+
--------
394+
>>> from sklearn.datasets import load_digits
395+
>>> from sklearn.feature_selection import SelectPercentile, chi2
396+
>>> X, y = load_digits(return_X_y=True)
397+
>>> X.shape
398+
(1797, 64)
399+
>>> X_new = SelectPercentile(chi2, percentile=10).fit_transform(X, y)
400+
>>> X_new.shape
401+
(1797, 7)
402+
392403
Notes
393404
-----
394405
Ties between features with equal scores will be broken in an unspecified
@@ -463,6 +474,17 @@ class SelectKBest(_BaseFilter):
463474
pvalues_ : array-like, shape=(n_features,)
464475
p-values of feature scores, None if `score_func` returned only scores.
465476
477+
Examples
478+
--------
479+
>>> from sklearn.datasets import load_digits
480+
>>> from sklearn.feature_selection import SelectKBest, chi2
481+
>>> X, y = load_digits(return_X_y=True)
482+
>>> X.shape
483+
(1797, 64)
484+
>>> X_new = SelectKBest(chi2, k=20).fit_transform(X, y)
485+
>>> X_new.shape
486+
(1797, 20)
487+
466488
Notes
467489
-----
468490
Ties between features with equal scores will be broken in an unspecified
@@ -536,6 +558,17 @@ class SelectFpr(_BaseFilter):
536558
pvalues_ : array-like, shape=(n_features,)
537559
p-values of feature scores.
538560
561+
Examples
562+
--------
563+
>>> from sklearn.datasets import load_breast_cancer
564+
>>> from sklearn.feature_selection import SelectFpr, chi2
565+
>>> X, y = load_breast_cancer(return_X_y=True)
566+
>>> X.shape
567+
(569, 30)
568+
>>> X_new = SelectFpr(chi2, alpha=0.01).fit_transform(X, y)
569+
>>> X_new.shape
570+
(569, 16)
571+
539572
See also
540573
--------
541574
f_classif: ANOVA F-value between label/feature for classification tasks.
@@ -579,6 +612,16 @@ class SelectFdr(_BaseFilter):
579612
alpha : float, optional
580613
The highest uncorrected p-value for features to keep.
581614
615+
Examples
616+
--------
617+
>>> from sklearn.datasets import load_breast_cancer
618+
>>> from sklearn.feature_selection import SelectFdr, chi2
619+
>>> X, y = load_breast_cancer(return_X_y=True)
620+
>>> X.shape
621+
(569, 30)
622+
>>> X_new = SelectFdr(chi2, alpha=0.01).fit_transform(X, y)
623+
>>> X_new.shape
624+
(569, 16)
582625
583626
Attributes
584627
----------
@@ -638,6 +681,17 @@ class SelectFwe(_BaseFilter):
638681
alpha : float, optional
639682
The highest uncorrected p-value for features to keep.
640683
684+
Examples
685+
--------
686+
>>> from sklearn.datasets import load_breast_cancer
687+
>>> from sklearn.feature_selection import SelectFwe, chi2
688+
>>> X, y = load_breast_cancer(return_X_y=True)
689+
>>> X.shape
690+
(569, 30)
691+
>>> X_new = SelectFwe(chi2, alpha=0.01).fit_transform(X, y)
692+
>>> X_new.shape
693+
(569, 15)
694+
641695
Attributes
642696
----------
643697
scores_ : array-like, shape=(n_features,)
@@ -700,6 +754,18 @@ class GenericUnivariateSelect(_BaseFilter):
700754
pvalues_ : array-like, shape=(n_features,)
701755
p-values of feature scores, None if `score_func` returned scores only.
702756
757+
Examples
758+
--------
759+
>>> from sklearn.datasets import load_breast_cancer
760+
>>> from sklearn.feature_selection import GenericUnivariateSelect, chi2
761+
>>> X, y = load_breast_cancer(return_X_y=True)
762+
>>> X.shape
763+
(569, 30)
764+
>>> transformer = GenericUnivariateSelect(chi2, 'k_best', param=20)
765+
>>> X_new = transformer.fit_transform(X, y)
766+
>>> X_new.shape
767+
(569, 20)
768+
703769
See also
704770
--------
705771
f_classif: ANOVA F-value between label/feature for classification tasks.

0 commit comments

Comments
 (0)
0