我对使用lasso algro显示所选功能有问题
X = df.drop(['Target'], axis=1)
y = df.Target
# We use the base estimator LassoCV
clf = LassoCV(cv=3)
# Set a minimum threshold of 0.70
sfm = SelectFromModel(clf, threshold=0.70)
sfm.fit(X, y)
n_features = sfm.transform(X).shape[1]
# Extracting the index of important features
feature_idx = sfm.get_support()
当我想看到选定的功能时,它会抛出eror
df.columns[feature_idx]
错误
IndexError: boolean index did not match indexed array along dimension 0; dimension is 1075 but corresponding boolean dimension is 1074
我知道df.columns包含目标Y,是否有方法删除第一个索引并保留其余索引以避免错误
这意味着布尔数组(例如,
[False, True, True]
)的大小与您尝试索引的数组的大小不对应。如果你只是顺序将保持不变,因为特性选择器适用于
df.drop(['Target'], axis=1)
相关问题 更多 >
编程相关推荐