简体   繁体   English

Python,功能选择

[英]Python ,Feature selection

When I use RFE to select the most important features in my data set, it returns all features , instead of returning the number of features that I specified 当我使用RFE选择数据集中最重要的功能时,它将返回所有功能,而不是返回我指定的功能数量

here is simple code: 这是简单的代码:

  from sklearn.svm import SVC
  from sklearn.datasets import load_digits
  from sklearn.feature_selection import RFE
  import matplotlib.pyplot as plt
  new_X=np.array([[1,2,3,3],[1,2,4,4],[3,1,3,4],[3,1,4,5]])
  new_Y=np.array([1,1,0,0])
  svc = SVC(kernel="linear", C=1)
  rfe = RFE(estimator=svc, n_features_to_select=2, step=1)
  rfe.fit(new_X, new_Y)
  ranking = rfe.ranking_
  len(ranking)

You are looking at the wrong thing. 您正在看错东西。

rfe.ranking_ will always return the ranking of all the features. rfe.ranking_将始终返回所有功能的排名。 But the selected features have value 1 in ranking_ 但是所选功能的ranking_ 1

Print the ranking_ and see: 打印ranking_并查看:

ranking
# Output: array([1, 1, 3, 2])

This means that 1st and 2nd features are selected. 这意味着选择了第一和第二特征。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM