我对fit_transform
函数有问题。有人能解释为什么数组大小不同吗?在
In [5]: X.shape, test.shape
Out[5]: ((1000, 1932), (1000, 1932))
In [6]: from sklearn.feature_selection import VarianceThreshold
sel = VarianceThreshold(threshold=(.8 * (1 - .8)))
features = sel.fit_transform(X)
features_test = sel.fit_transform(test)
In [7]: features.shape, features_test.shape
Out[7]:((1000, 1663), (1000, 1665))
UPD:哪个转换可以帮助我获得相同大小的数组?在
这是因为您安装了两次选择器。在
首先,注意}的调用。在
fit_transform
只是对fit
的调用,然后是对{fit
方法允许您的VarianceThreshold
选择器根据您给它的参数查找它希望保留在数据集中的特性。在transform
方法执行实际的特性选择,并返回一个n数组,其中只包含选定的特性。在因为
fit_transform
对数组应用了维数缩减。这就是结果数组的维数与输入不一样的原因。在看到这个what is the difference between 'transform' and 'fit_transform' in sklearn和这个http://scikit-learn.org/stable/modules/feature_extraction.html
相关问题 更多 >
编程相关推荐