zoukankan      html  css  js  c++  java
  • 特征选择--联合方法的特征提取

    """
    =================================================
    Concatenating multiple feature extraction methods
    =================================================
      
    In many real-world examples, there are many ways to extract features from a
    dataset. Often it is beneficial to combine several methods to obtain good
    performance. This example shows how to use ``FeatureUnion`` to combine
    features obtained by PCA and univariate selection.
      
    Combining features using this transformer has the benefit that it allows
    cross validation and grid searches over the whole process.
      
    The combination used in this example is not particularly helpful on this
    dataset and is only used to illustrate the usage of FeatureUnion.
    """
      
    # Author: Andreas Mueller <amueller@ais.uni-bonn.de>
    #
    # License: BSD 3 clause
      
    from sklearn.pipeline import Pipeline, FeatureUnion
    from sklearn.grid_search import GridSearchCV
    from sklearn.svm import SVC
    from sklearn.datasets import load_iris
    from sklearn.decomposition import PCA
    from sklearn.feature_selection import SelectKBest
      
    iris = load_iris()
      
    X, y = iris.data, iris.target
      
    # This dataset is way to high-dimensional. Better do PCA:
    pca = PCA(n_components=2)
      
    # Maybe some original features where good, too?
    selection = SelectKBest(k=1)
      
    # Build estimator from PCA and Univariate selection:
      
    combined_features = FeatureUnion([("pca", pca), ("univ_select", selection)])
      
    # Use combined features to transform dataset:
    X_features = combined_features.fit(X, y).transform(X)
      
    # Classify:
    svm = SVC(kernel="linear")
    svm.fit(X_features, y)
      
    # Do grid search over k, n_components and 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_)

  • 相关阅读:
    通过 WakaTime 统计你写代码的时长
    CCF 202012-3 带配额的文件系统
    1
    prometheus 获取cpu利用率
    springboot使用@data注解,减少不必要代码-lombok插件
    django官方教程部署simpleui时候发现加载不到静态文件解决办法
    echarts关系图研究01
    SpringBoot代码方式禁用Druid Monitor
    virtualbox给已有磁盘扩展容量
    centos7 ssh免密登录配置
  • 原文地址:https://www.cnblogs.com/xinping-study/p/7116982.html
Copyright © 2011-2022 走看看