我试图应用未来的选择。问题是使用整个数据帧会引发内存错误。所以我决定削减我的数据框,以便能够在将来的选择中使用:
# this is original dataframes
X_full = df_train[df_train.columns[0:size]] # 76000(rows)*300(cols)
y_full = df_train[[len(df_train.columns)-1]] # 76000(rows)*1(col)
y_full
包含0和1,数字1&#39}低于5%。所有其他列仅包含数字,但我们不知道它们的含义。
#this is way, I reduce the number of rows to 10%
test_frac = 0.10
count = len(X_full)
X = X_full.iloc[-int(count*test_frac):]
y = y_full.iloc[-int(count*test_frac):]
#Then I use Linear models penalized with the L1 norm to reduce the dimensionality of the data
lsvc = LinearSVC(C=0.01, penalty="l1", dual=False).fit(X, y)
model = SelectFromModel(lsvc, prefit=True)
X_new = model.transform(X)
print "X_new.shape", X_new.shape
print X_new
问题是我需要获取已删除的列的列表,以便从原始数据帧中删除它们。我怎么能这样做?
答案 0 :(得分:1)
听起来像是在寻找SelectFromModel.get_support()
。根据文档,它可以返回(1)一个布尔数组,其长度等于所有特征的数量(2)包含的特征的整数索引:
从特征向量中选择保留要素的索引。如果indices为False,则这是形状[#input features]的布尔数组,如果选择其相应的特征进行保留,则元素为True。如果indices为True,则这是一个形状[#output features]的整数数组,其值是输入特征向量的索引。