@@ -389,6 +389,17 @@ class SelectPercentile(_BaseFilter):
389
389
pvalues_ : array-like, shape=(n_features,)
390
390
p-values of feature scores, None if `score_func` returned only scores.
391
391
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
+
392
403
Notes
393
404
-----
394
405
Ties between features with equal scores will be broken in an unspecified
@@ -463,6 +474,17 @@ class SelectKBest(_BaseFilter):
463
474
pvalues_ : array-like, shape=(n_features,)
464
475
p-values of feature scores, None if `score_func` returned only scores.
465
476
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
+
466
488
Notes
467
489
-----
468
490
Ties between features with equal scores will be broken in an unspecified
@@ -536,6 +558,17 @@ class SelectFpr(_BaseFilter):
536
558
pvalues_ : array-like, shape=(n_features,)
537
559
p-values of feature scores.
538
560
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
+
539
572
See also
540
573
--------
541
574
f_classif: ANOVA F-value between label/feature for classification tasks.
@@ -579,6 +612,16 @@ class SelectFdr(_BaseFilter):
579
612
alpha : float, optional
580
613
The highest uncorrected p-value for features to keep.
581
614
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)
582
625
583
626
Attributes
584
627
----------
@@ -638,6 +681,17 @@ class SelectFwe(_BaseFilter):
638
681
alpha : float, optional
639
682
The highest uncorrected p-value for features to keep.
640
683
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
+
641
695
Attributes
642
696
----------
643
697
scores_ : array-like, shape=(n_features,)
@@ -700,6 +754,18 @@ class GenericUnivariateSelect(_BaseFilter):
700
754
pvalues_ : array-like, shape=(n_features,)
701
755
p-values of feature scores, None if `score_func` returned scores only.
702
756
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
+
703
769
See also
704
770
--------
705
771
f_classif: ANOVA F-value between label/feature for classification tasks.
0 commit comments