[英]Which features selects fit_transform?
I'm selecting features using LinearSVC. 我正在使用LinearSVC选择功能。 All the features are binaries. 所有功能都是二进制文件。 This is how it looks like: 它是这样的:
In> X0.shape
Out> (6876299, 49)
In> lsvc = LinearSVC(C=0.01, penalty="l1", dual=False)
In> X_new = lsvc.fit_transform(X0, y0)
In> X_new.shape
Out> (6876299, 41)
My problem is very simple, but I haven't found any specific solution. 我的问题很简单,但是我还没有找到任何具体的解决方案。 How am I supposed to know which features have been selected by fit_transform? 我应该如何知道fit_transform选择了哪些功能?
Thks! THKS!
You can take a look at lsvc.coef_
. 您可以看看lsvc.coef_
。 The features with non-zero coefficients will be the ones that have been chosen. 具有非零系数的特征将是已选择的特征。 For example the following will give you a mask of all non-zero features: 例如,以下内容将为您提供所有非零特征的掩码:
>>> from sklearn.datasets import load_iris
>>> iris = load_iris()
>>> X, y = iris.data, iris.target
>>> X.shape
(150, 4)
>>> lsvc = LinearSVC(C=0.01, penalty="l1", dual=False)
>>> X_new = lsvc.fit_transform(X, y)
>>> X_new.shape
(150, 3)
>>> lsvc.coef_
array([[ 0. , 0.21680351, -0.28727891, 0. ],
[ 0. , -0.09186784, 0. , 0. ],
[-0.03501512, -0.17022421, 0.13485806, 0. ]])
>>> ~np.all(lsvc.coef_==0, axis=0)
array([ True, True, True, False], dtype=bool)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.