Search code examples
pythonpython-3.xfeature-selectionadaboost

select Important-feature with Adaboost in python


I want to select Important feature with adaboost. I found 'yellowbrick.model_selection' is very good and fast for this work. and I used this code. but it has problem. "ValueError: could not broadcast input array from shape (260200) into shape (1)
My feature vector has 1*260200 for every Image. I can't Underestand How adaboost make a model, so I can't debug the code. would you help me please? thank you a lot :)

   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()


Solution

  • this code, make a rank for every feature

    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 is a vector which show U index of important feature. good luke