def sk_feature_ref():
# load the iris datasets
dataset = datasets.load_iris()
# create a base classifier used to evaluate a subset of attributes
model_lr = LogisticRegression()
# create the RFE model and select 3 attributes
rfe = RFE(model_lr, 3)
rfe = rfe.fit(dataset.data, dataset.target)
# summarize the selection of the attributes
print rfe.support_
# [False True True True]
print rfe.ranking_
# [2 1 1 1]
print sorted(zip(map(lambda x: round(x, 4), rfe.ranking_), dataset.feature_names))
# [(1.0, 'petal length (cm)'), (1.0, 'petal width (cm)'), (1.0, 'sepal width (cm)'), (2.0, 'sepal length (cm)')]
评论列表
文章目录