Search code examples
pythonscikit-learnlogistic-regressionfeature-selection

Find selected features by RandomizedLogisticRegression


I'm doing binary classification on 300Ksamples and 19 features. I employed RandomizedLogisticRegression() in scikit for feature selection. I'd like to know how can I find which features are selected by RandomizedLogisticRegression().


Solution

  • You should use the get_support function:

    from sklearn.datasets import load_iris
    from sklearn.linear_model import RandomizedLogisticRegression
    
    iris = load_iris()
    X, y = iris.data, iris.target
    
    clf = RandomizedLogisticRegression()
    clf.fit(X,y)
    print clf.get_support()
    
    #prints [False  True  True  True]
    

    Alternatively, you can get the indices of the support features:

    print clf.get_support(indices=True)
    #prints [1 2 3]