【发布时间】:2021-01-28 11:39:20
【问题描述】:
我正在Iris dateset 上尝试功能选择。
我从Feature Selection with Univariate Statistical Tests引用
我正在使用以下几行,我想找出重要的功能:
import pandas
from pandas import read_csv
from numpy import set_printoptions
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import f_classif
dataframe = pandas.read_csv("C:\\dateset\\iris.csv"]))
array = dataframe.values
X = array[:,0:4]
Y = array[:,4]
test = SelectKBest(score_func=f_classif, k=2)
fit = test.fit(X, Y)
set_printoptions(precision=2)
arr = fit.scores_
print (arr)
# [ 119.26 47.36 1179.03 959.32]
为了按分数显示前 2 名的索引,我添加了:
idx = (-arr).argsort()[:2]
print (idx)
# [2 3]
此外,我怎样才能获得列/变量名称(而不是它们的索引)?
【问题讨论】:
标签: python pandas dataframe feature-selection