.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/compose/plot_feature_union.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_compose_plot_feature_union.py: ================================================= 连接多种特征提取方法 ================================================= 在许多实际案例中,有多种方法可以从数据集中提取特征。通常,结合几种方法可以获得良好的性能。此示例展示了如何使用 ``FeatureUnion`` 来结合通过PCA和单变量选择获得的特征。 使用此转换器结合特征的好处是,它允许对整个过程进行交叉验证和网格搜索。 在此示例中使用的组合对该数据集并没有特别大的帮助,仅用于说明FeatureUnion的用法。 .. GENERATED FROM PYTHON SOURCE LINES 13-57 .. rst-class:: sphx-glr-script-out .. code-block:: none Combined space has 3 features Fitting 5 folds for each of 18 candidates, totalling 90 fits [CV 1/5; 1/18] START features__pca__n_components=1, features__univ_select__k=1, svm__C=0.1 [CV 1/5; 1/18] END features__pca__n_components=1, features__univ_select__k=1, svm__C=0.1;, score=0.933 total time= 0.0s [CV 2/5; 1/18] START features__pca__n_components=1, features__univ_select__k=1, svm__C=0.1 [CV 2/5; 1/18] END features__pca__n_components=1, features__univ_select__k=1, svm__C=0.1;, score=0.933 total time= 0.0s [CV 3/5; 1/18] START features__pca__n_components=1, features__univ_select__k=1, svm__C=0.1 [CV 3/5; 1/18] END features__pca__n_components=1, features__univ_select__k=1, svm__C=0.1;, score=0.867 total time= 0.0s [CV 4/5; 1/18] START features__pca__n_components=1, features__univ_select__k=1, svm__C=0.1 [CV 4/5; 1/18] END features__pca__n_components=1, features__univ_select__k=1, svm__C=0.1;, score=0.933 total time= 0.0s [CV 5/5; 1/18] START features__pca__n_components=1, features__univ_select__k=1, svm__C=0.1 [CV 5/5; 1/18] END features__pca__n_components=1, features__univ_select__k=1, svm__C=0.1;, score=1.000 total time= 0.0s [CV 1/5; 2/18] START features__pca__n_components=1, features__univ_select__k=1, svm__C=1 [CV 1/5; 2/18] END features__pca__n_components=1, features__univ_select__k=1, svm__C=1;, score=0.900 total time= 0.0s [CV 2/5; 2/18] START features__pca__n_components=1, features__univ_select__k=1, svm__C=1 [CV 2/5; 2/18] END features__pca__n_components=1, features__univ_select__k=1, svm__C=1;, score=1.000 total time= 0.0s [CV 3/5; 2/18] START features__pca__n_components=1, features__univ_select__k=1, svm__C=1 [CV 3/5; 2/18] END features__pca__n_components=1, features__univ_select__k=1, svm__C=1;, score=0.867 total time= 0.0s [CV 4/5; 2/18] START features__pca__n_components=1, features__univ_select__k=1, svm__C=1 [CV 4/5; 2/18] END features__pca__n_components=1, features__univ_select__k=1, svm__C=1;, score=0.933 total time= 0.0s [CV 5/5; 2/18] START features__pca__n_components=1, features__univ_select__k=1, svm__C=1 [CV 5/5; 2/18] END features__pca__n_components=1, features__univ_select__k=1, svm__C=1;, score=1.000 total time= 0.0s [CV 1/5; 3/18] START features__pca__n_components=1, features__univ_select__k=1, svm__C=10 [CV 1/5; 3/18] END features__pca__n_components=1, features__univ_select__k=1, svm__C=10;, score=0.933 total time= 0.0s [CV 2/5; 3/18] START features__pca__n_components=1, features__univ_select__k=1, svm__C=10 [CV 2/5; 3/18] END features__pca__n_components=1, features__univ_select__k=1, svm__C=10;, score=1.000 total time= 0.0s [CV 3/5; 3/18] START features__pca__n_components=1, features__univ_select__k=1, svm__C=10 [CV 3/5; 3/18] END features__pca__n_components=1, features__univ_select__k=1, svm__C=10;, score=0.900 total time= 0.0s [CV 4/5; 3/18] START features__pca__n_components=1, features__univ_select__k=1, svm__C=10 [CV 4/5; 3/18] END features__pca__n_components=1, features__univ_select__k=1, svm__C=10;, score=0.933 total time= 0.0s [CV 5/5; 3/18] START features__pca__n_components=1, features__univ_select__k=1, svm__C=10 [CV 5/5; 3/18] END features__pca__n_components=1, features__univ_select__k=1, svm__C=10;, score=1.000 total time= 0.0s [CV 1/5; 4/18] START features__pca__n_components=1, features__univ_select__k=2, svm__C=0.1 [CV 1/5; 4/18] END features__pca__n_components=1, features__univ_select__k=2, svm__C=0.1;, score=0.933 total time= 0.0s [CV 2/5; 4/18] START features__pca__n_components=1, features__univ_select__k=2, svm__C=0.1 [CV 2/5; 4/18] END features__pca__n_components=1, features__univ_select__k=2, svm__C=0.1;, score=0.967 total time= 0.0s [CV 3/5; 4/18] START features__pca__n_components=1, features__univ_select__k=2, svm__C=0.1 [CV 3/5; 4/18] END features__pca__n_components=1, features__univ_select__k=2, svm__C=0.1;, score=0.933 total time= 0.0s [CV 4/5; 4/18] START features__pca__n_components=1, features__univ_select__k=2, svm__C=0.1 [CV 4/5; 4/18] END features__pca__n_components=1, features__univ_select__k=2, svm__C=0.1;, score=0.933 total time= 0.0s [CV 5/5; 4/18] START features__pca__n_components=1, features__univ_select__k=2, svm__C=0.1 [CV 5/5; 4/18] END features__pca__n_components=1, features__univ_select__k=2, svm__C=0.1;, score=1.000 total time= 0.0s [CV 1/5; 5/18] START features__pca__n_components=1, features__univ_select__k=2, svm__C=1 [CV 1/5; 5/18] END features__pca__n_components=1, features__univ_select__k=2, svm__C=1;, score=0.933 total time= 0.0s [CV 2/5; 5/18] START features__pca__n_components=1, features__univ_select__k=2, svm__C=1 [CV 2/5; 5/18] END features__pca__n_components=1, features__univ_select__k=2, svm__C=1;, score=0.967 total time= 0.0s [CV 3/5; 5/18] START features__pca__n_components=1, features__univ_select__k=2, svm__C=1 [CV 3/5; 5/18] END features__pca__n_components=1, features__univ_select__k=2, svm__C=1;, score=0.933 total time= 0.0s [CV 4/5; 5/18] START features__pca__n_components=1, features__univ_select__k=2, svm__C=1 [CV 4/5; 5/18] END features__pca__n_components=1, features__univ_select__k=2, svm__C=1;, score=0.933 total time= 0.0s [CV 5/5; 5/18] START features__pca__n_components=1, features__univ_select__k=2, svm__C=1 [CV 5/5; 5/18] END features__pca__n_components=1, features__univ_select__k=2, svm__C=1;, score=1.000 total time= 0.0s [CV 1/5; 6/18] START features__pca__n_components=1, features__univ_select__k=2, svm__C=10 [CV 1/5; 6/18] END features__pca__n_components=1, features__univ_select__k=2, svm__C=10;, score=0.967 total time= 0.0s [CV 2/5; 6/18] START features__pca__n_components=1, features__univ_select__k=2, svm__C=10 [CV 2/5; 6/18] END features__pca__n_components=1, features__univ_select__k=2, svm__C=10;, score=0.967 total time= 0.0s [CV 3/5; 6/18] START features__pca__n_components=1, features__univ_select__k=2, svm__C=10 [CV 3/5; 6/18] END features__pca__n_components=1, features__univ_select__k=2, svm__C=10;, score=0.933 total time= 0.0s [CV 4/5; 6/18] START features__pca__n_components=1, features__univ_select__k=2, svm__C=10 [CV 4/5; 6/18] END features__pca__n_components=1, features__univ_select__k=2, svm__C=10;, score=0.933 total time= 0.0s [CV 5/5; 6/18] START features__pca__n_components=1, features__univ_select__k=2, svm__C=10 [CV 5/5; 6/18] END features__pca__n_components=1, features__univ_select__k=2, svm__C=10;, score=1.000 total time= 0.0s [CV 1/5; 7/18] START features__pca__n_components=2, features__univ_select__k=1, svm__C=0.1 [CV 1/5; 7/18] END features__pca__n_components=2, features__univ_select__k=1, svm__C=0.1;, score=0.933 total time= 0.0s [CV 2/5; 7/18] START features__pca__n_components=2, features__univ_select__k=1, svm__C=0.1 [CV 2/5; 7/18] END features__pca__n_components=2, features__univ_select__k=1, svm__C=0.1;, score=1.000 total time= 0.0s [CV 3/5; 7/18] START features__pca__n_components=2, features__univ_select__k=1, svm__C=0.1 [CV 3/5; 7/18] END features__pca__n_components=2, features__univ_select__k=1, svm__C=0.1;, score=0.867 total time= 0.0s [CV 4/5; 7/18] START features__pca__n_components=2, features__univ_select__k=1, svm__C=0.1 [CV 4/5; 7/18] END features__pca__n_components=2, features__univ_select__k=1, svm__C=0.1;, score=0.933 total time= 0.0s [CV 5/5; 7/18] START features__pca__n_components=2, features__univ_select__k=1, svm__C=0.1 [CV 5/5; 7/18] END features__pca__n_components=2, features__univ_select__k=1, svm__C=0.1;, score=1.000 total time= 0.0s [CV 1/5; 8/18] START features__pca__n_components=2, features__univ_select__k=1, svm__C=1 [CV 1/5; 8/18] END features__pca__n_components=2, features__univ_select__k=1, svm__C=1;, score=0.967 total time= 0.0s [CV 2/5; 8/18] START features__pca__n_components=2, features__univ_select__k=1, svm__C=1 [CV 2/5; 8/18] END features__pca__n_components=2, features__univ_select__k=1, svm__C=1;, score=1.000 total time= 0.0s [CV 3/5; 8/18] START features__pca__n_components=2, features__univ_select__k=1, svm__C=1 [CV 3/5; 8/18] END features__pca__n_components=2, features__univ_select__k=1, svm__C=1;, score=0.933 total time= 0.0s [CV 4/5; 8/18] START features__pca__n_components=2, features__univ_select__k=1, svm__C=1 [CV 4/5; 8/18] END features__pca__n_components=2, features__univ_select__k=1, svm__C=1;, score=0.933 total time= 0.0s [CV 5/5; 8/18] START features__pca__n_components=2, features__univ_select__k=1, svm__C=1 [CV 5/5; 8/18] END features__pca__n_components=2, features__univ_select__k=1, svm__C=1;, score=1.000 total time= 0.0s [CV 1/5; 9/18] START features__pca__n_components=2, features__univ_select__k=1, svm__C=10 [CV 1/5; 9/18] END features__pca__n_components=2, features__univ_select__k=1, svm__C=10;, score=0.967 total time= 0.0s [CV 2/5; 9/18] START features__pca__n_components=2, features__univ_select__k=1, svm__C=10 [CV 2/5; 9/18] END features__pca__n_components=2, features__univ_select__k=1, svm__C=10;, score=0.967 total time= 0.0s [CV 3/5; 9/18] START features__pca__n_components=2, features__univ_select__k=1, svm__C=10 [CV 3/5; 9/18] END features__pca__n_components=2, features__univ_select__k=1, svm__C=10;, score=0.900 total time= 0.0s [CV 4/5; 9/18] START features__pca__n_components=2, features__univ_select__k=1, svm__C=10 [CV 4/5; 9/18] END features__pca__n_components=2, features__univ_select__k=1, svm__C=10;, score=0.933 total time= 0.0s [CV 5/5; 9/18] START features__pca__n_components=2, features__univ_select__k=1, svm__C=10 [CV 5/5; 9/18] END features__pca__n_components=2, features__univ_select__k=1, svm__C=10;, score=1.000 total time= 0.0s [CV 1/5; 10/18] START features__pca__n_components=2, features__univ_select__k=2, svm__C=0.1 [CV 1/5; 10/18] END features__pca__n_components=2, features__univ_select__k=2, svm__C=0.1;, score=0.967 total time= 0.0s [CV 2/5; 10/18] START features__pca__n_components=2, features__univ_select__k=2, svm__C=0.1 [CV 2/5; 10/18] END features__pca__n_components=2, features__univ_select__k=2, svm__C=0.1;, score=1.000 total time= 0.0s [CV 3/5; 10/18] START features__pca__n_components=2, features__univ_select__k=2, svm__C=0.1 [CV 3/5; 10/18] END features__pca__n_components=2, features__univ_select__k=2, svm__C=0.1;, score=0.933 total time= 0.0s [CV 4/5; 10/18] START features__pca__n_components=2, features__univ_select__k=2, svm__C=0.1 [CV 4/5; 10/18] END features__pca__n_components=2, features__univ_select__k=2, svm__C=0.1;, score=0.933 total time= 0.0s [CV 5/5; 10/18] START features__pca__n_components=2, features__univ_select__k=2, svm__C=0.1 [CV 5/5; 10/18] END features__pca__n_components=2, features__univ_select__k=2, svm__C=0.1;, score=1.000 total time= 0.0s [CV 1/5; 11/18] START features__pca__n_components=2, features__univ_select__k=2, svm__C=1 [CV 1/5; 11/18] END features__pca__n_components=2, features__univ_select__k=2, svm__C=1;, score=0.967 total time= 0.0s [CV 2/5; 11/18] START features__pca__n_components=2, features__univ_select__k=2, svm__C=1 [CV 2/5; 11/18] END features__pca__n_components=2, features__univ_select__k=2, svm__C=1;, score=1.000 total time= 0.0s [CV 3/5; 11/18] START features__pca__n_components=2, features__univ_select__k=2, svm__C=1 [CV 3/5; 11/18] END features__pca__n_components=2, features__univ_select__k=2, svm__C=1;, score=0.933 total time= 0.0s [CV 4/5; 11/18] START features__pca__n_components=2, features__univ_select__k=2, svm__C=1 [CV 4/5; 11/18] END features__pca__n_components=2, features__univ_select__k=2, svm__C=1;, score=0.967 total time= 0.0s [CV 5/5; 11/18] START features__pca__n_components=2, features__univ_select__k=2, svm__C=1 [CV 5/5; 11/18] END features__pca__n_components=2, features__univ_select__k=2, svm__C=1;, score=1.000 total time= 0.0s [CV 1/5; 12/18] START features__pca__n_components=2, features__univ_select__k=2, svm__C=10 [CV 1/5; 12/18] END features__pca__n_components=2, features__univ_select__k=2, svm__C=10;, score=0.967 total time= 0.0s [CV 2/5; 12/18] START features__pca__n_components=2, features__univ_select__k=2, svm__C=10 [CV 2/5; 12/18] END features__pca__n_components=2, features__univ_select__k=2, svm__C=10;, score=1.000 total time= 0.0s [CV 3/5; 12/18] START features__pca__n_components=2, features__univ_select__k=2, svm__C=10 [CV 3/5; 12/18] END features__pca__n_components=2, features__univ_select__k=2, svm__C=10;, score=0.900 total time= 0.0s [CV 4/5; 12/18] START features__pca__n_components=2, features__univ_select__k=2, svm__C=10 [CV 4/5; 12/18] END features__pca__n_components=2, features__univ_select__k=2, svm__C=10;, score=0.933 total time= 0.0s [CV 5/5; 12/18] START features__pca__n_components=2, features__univ_select__k=2, svm__C=10 [CV 5/5; 12/18] END features__pca__n_components=2, features__univ_select__k=2, svm__C=10;, score=1.000 total time= 0.0s [CV 1/5; 13/18] START features__pca__n_components=3, features__univ_select__k=1, svm__C=0.1 [CV 1/5; 13/18] END features__pca__n_components=3, features__univ_select__k=1, svm__C=0.1;, score=0.967 total time= 0.0s [CV 2/5; 13/18] START features__pca__n_components=3, features__univ_select__k=1, svm__C=0.1 [CV 2/5; 13/18] END features__pca__n_components=3, features__univ_select__k=1, svm__C=0.1;, score=1.000 total time= 0.0s [CV 3/5; 13/18] START features__pca__n_components=3, features__univ_select__k=1, svm__C=0.1 [CV 3/5; 13/18] END features__pca__n_components=3, features__univ_select__k=1, svm__C=0.1;, score=0.933 total time= 0.0s [CV 4/5; 13/18] START features__pca__n_components=3, features__univ_select__k=1, svm__C=0.1 [CV 4/5; 13/18] END features__pca__n_components=3, features__univ_select__k=1, svm__C=0.1;, score=0.967 total time= 0.0s [CV 5/5; 13/18] START features__pca__n_components=3, features__univ_select__k=1, svm__C=0.1 [CV 5/5; 13/18] END features__pca__n_components=3, features__univ_select__k=1, svm__C=0.1;, score=1.000 total time= 0.0s [CV 1/5; 14/18] START features__pca__n_components=3, features__univ_select__k=1, svm__C=1 [CV 1/5; 14/18] END features__pca__n_components=3, features__univ_select__k=1, svm__C=1;, score=0.967 total time= 0.0s [CV 2/5; 14/18] START features__pca__n_components=3, features__univ_select__k=1, svm__C=1 [CV 2/5; 14/18] END features__pca__n_components=3, features__univ_select__k=1, svm__C=1;, score=1.000 total time= 0.0s [CV 3/5; 14/18] START features__pca__n_components=3, features__univ_select__k=1, svm__C=1 [CV 3/5; 14/18] END features__pca__n_components=3, features__univ_select__k=1, svm__C=1;, score=0.933 total time= 0.0s [CV 4/5; 14/18] START features__pca__n_components=3, features__univ_select__k=1, svm__C=1 [CV 4/5; 14/18] END features__pca__n_components=3, features__univ_select__k=1, svm__C=1;, score=0.967 total time= 0.0s [CV 5/5; 14/18] START features__pca__n_components=3, features__univ_select__k=1, svm__C=1 [CV 5/5; 14/18] END features__pca__n_components=3, features__univ_select__k=1, svm__C=1;, score=1.000 total time= 0.0s [CV 1/5; 15/18] START features__pca__n_components=3, features__univ_select__k=1, svm__C=10 [CV 1/5; 15/18] END features__pca__n_components=3, features__univ_select__k=1, svm__C=10;, score=1.000 total time= 0.0s [CV 2/5; 15/18] START features__pca__n_components=3, features__univ_select__k=1, svm__C=10 [CV 2/5; 15/18] END features__pca__n_components=3, features__univ_select__k=1, svm__C=10;, score=1.000 total time= 0.0s [CV 3/5; 15/18] START features__pca__n_components=3, features__univ_select__k=1, svm__C=10 [CV 3/5; 15/18] END features__pca__n_components=3, features__univ_select__k=1, svm__C=10;, score=0.933 total time= 0.0s [CV 4/5; 15/18] START features__pca__n_components=3, features__univ_select__k=1, svm__C=10 [CV 4/5; 15/18] END features__pca__n_components=3, features__univ_select__k=1, svm__C=10;, score=0.967 total time= 0.0s [CV 5/5; 15/18] START features__pca__n_components=3, features__univ_select__k=1, svm__C=10 [CV 5/5; 15/18] END features__pca__n_components=3, features__univ_select__k=1, svm__C=10;, score=1.000 total time= 0.0s [CV 1/5; 16/18] START features__pca__n_components=3, features__univ_select__k=2, svm__C=0.1 [CV 1/5; 16/18] END features__pca__n_components=3, features__univ_select__k=2, svm__C=0.1;, score=0.967 total time= 0.0s [CV 2/5; 16/18] START features__pca__n_components=3, features__univ_select__k=2, svm__C=0.1 [CV 2/5; 16/18] END features__pca__n_components=3, features__univ_select__k=2, svm__C=0.1;, score=1.000 total time= 0.0s [CV 3/5; 16/18] START features__pca__n_components=3, features__univ_select__k=2, svm__C=0.1 [CV 3/5; 16/18] END features__pca__n_components=3, features__univ_select__k=2, svm__C=0.1;, score=0.933 total time= 0.0s [CV 4/5; 16/18] START features__pca__n_components=3, features__univ_select__k=2, svm__C=0.1 [CV 4/5; 16/18] END features__pca__n_components=3, features__univ_select__k=2, svm__C=0.1;, score=0.967 total time= 0.0s [CV 5/5; 16/18] START features__pca__n_components=3, features__univ_select__k=2, svm__C=0.1 [CV 5/5; 16/18] END features__pca__n_components=3, features__univ_select__k=2, svm__C=0.1;, score=1.000 total time= 0.0s [CV 1/5; 17/18] START features__pca__n_components=3, features__univ_select__k=2, svm__C=1 [CV 1/5; 17/18] END features__pca__n_components=3, features__univ_select__k=2, svm__C=1;, score=0.967 total time= 0.0s [CV 2/5; 17/18] START features__pca__n_components=3, features__univ_select__k=2, svm__C=1 [CV 2/5; 17/18] END features__pca__n_components=3, features__univ_select__k=2, svm__C=1;, score=1.000 total time= 0.0s [CV 3/5; 17/18] START features__pca__n_components=3, features__univ_select__k=2, svm__C=1 [CV 3/5; 17/18] END features__pca__n_components=3, features__univ_select__k=2, svm__C=1;, score=0.967 total time= 0.0s [CV 4/5; 17/18] START features__pca__n_components=3, features__univ_select__k=2, svm__C=1 [CV 4/5; 17/18] END features__pca__n_components=3, features__univ_select__k=2, svm__C=1;, score=0.967 total time= 0.0s [CV 5/5; 17/18] START features__pca__n_components=3, features__univ_select__k=2, svm__C=1 [CV 5/5; 17/18] END features__pca__n_components=3, features__univ_select__k=2, svm__C=1;, score=1.000 total time= 0.0s [CV 1/5; 18/18] START features__pca__n_components=3, features__univ_select__k=2, svm__C=10 [CV 1/5; 18/18] END features__pca__n_components=3, features__univ_select__k=2, svm__C=10;, score=1.000 total time= 0.0s [CV 2/5; 18/18] START features__pca__n_components=3, features__univ_select__k=2, svm__C=10 [CV 2/5; 18/18] END features__pca__n_components=3, features__univ_select__k=2, svm__C=10;, score=1.000 total time= 0.0s [CV 3/5; 18/18] START features__pca__n_components=3, features__univ_select__k=2, svm__C=10 [CV 3/5; 18/18] END features__pca__n_components=3, features__univ_select__k=2, svm__C=10;, score=0.900 total time= 0.0s [CV 4/5; 18/18] START features__pca__n_components=3, features__univ_select__k=2, svm__C=10 [CV 4/5; 18/18] END features__pca__n_components=3, features__univ_select__k=2, svm__C=10;, score=0.967 total time= 0.0s [CV 5/5; 18/18] START features__pca__n_components=3, features__univ_select__k=2, svm__C=10 [CV 5/5; 18/18] END features__pca__n_components=3, features__univ_select__k=2, svm__C=10;, score=1.000 total time= 0.0s Pipeline(steps=[('features', FeatureUnion(transformer_list=[('pca', PCA(n_components=3)), ('univ_select', SelectKBest(k=1))])), ('svm', SVC(C=10, kernel='linear'))]) | .. code-block:: Python # 作者:scikit-learn 开发者 # SPDX-License-Identifier: BSD-3-Clause from sklearn.datasets import load_iris from sklearn.decomposition import PCA from sklearn.feature_selection import SelectKBest from sklearn.model_selection import GridSearchCV from sklearn.pipeline import FeatureUnion, Pipeline from sklearn.svm import SVC iris = load_iris() X, y = iris.data, iris.target # 这个数据集的维度太高了。最好做主成分分析(PCA): pca = PCA(n_components=2) # 也许一些原有的特性也很好? selection = SelectKBest(k=1) # 从PCA和单变量选择构建估计器: combined_features = FeatureUnion([("pca", pca), ("univ_select", selection)]) # 使用组合特征来转换数据集: X_features = combined_features.fit(X, y).transform(X) print("Combined space has", X_features.shape[1], "features") svm = SVC(kernel="linear") # 对 k、n_components 和 C 进行网格搜索: pipeline = Pipeline([("features", combined_features), ("svm", svm)]) param_grid = dict( features__pca__n_components=[1, 2, 3], features__univ_select__k=[1, 2], svm__C=[0.1, 1, 10], ) grid_search = GridSearchCV(pipeline, param_grid=param_grid, verbose=10) grid_search.fit(X, y) print(grid_search.best_estimator_) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.164 seconds) .. _sphx_glr_download_auto_examples_compose_plot_feature_union.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-learn/scikit-learn/main?urlpath=lab/tree/notebooks/auto_examples/compose/plot_feature_union.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_feature_union.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_feature_union.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_feature_union.zip ` .. include:: plot_feature_union.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_