【问题标题】:select Important-feature with Adaboost in python在 python 中使用 Adaboost 选择重要功能
【发布时间】:2021-05-11 18:26:48
【问题描述】:

我想用 adaboost 选择重要功能。我发现 'yellowbrick.model_selection' 对于这项工作来说非常好和快。我使用了这段代码。但它有问题。 “ValueError:无法将输入数组从形状 (260200) 广播到形状 (1)
我的特征向量对于每个图像都有 1*260200。我无法理解 adaboost 如何制作模型,因此无法调试代码。 你能帮帮我吗? 非常感谢:)

   from sklearn.ensemble import AdaBoostClassifier
   from yellowbrick.model_selection import FeatureImportances

    model = AdaBoostClassifier(n_estimators=10, random_state=1)
    model.fit(X_train, Y_train)
    visualizer = FeatureImportances(model)
    visualizer.show()

【问题讨论】:

    标签: python python-3.x feature-selection adaboost


    【解决方案1】:

    这段代码,为每个特征做一个排名

    from sklearn.ensemble import AdaBoostClassifier
    
    ab_model = AdaBoostClassifier(n_estimators=20,random_state=0)
    ab_model.fit(x_train, y_train)
    importances = ab_model.feature_importances_
    non_zero=np.nonzero(importances)
    

    non_zero 是一个向量,表示重要特征的 U 索引。 祝你好运

    【讨论】:

      猜你喜欢
      • 2013-04-26
      • 2014-02-17
      • 1970-01-01
      • 2013-04-27
      • 2018-02-20
      • 2014-11-15
      • 2012-04-20
      • 2019-06-29
      • 1970-01-01
      相关资源
      最近更新 更多