我使用scikit learn中的各种机制来创建训练数据集和由文本特性组成的测试集的tf-idf表示。两个数据集都经过预处理以使用相同的词汇表,因此特征和特征的数量是相同的。我可以在训练数据上创建一个模型,并在测试数据上评估它的性能。我想知道如果我使用SelectPercentile来减少转换后训练集中的特征的数量,那么如何在测试集中识别相同的特征以用于预测?在
trainDenseData = trainTransformedData.toarray()
testDenseData = testTransformedData.toarray()
if ( useFeatureReduction== True):
reducedTrainData = SelectPercentile(f_regression,percentile=10).fit_transform(trainDenseData,trainYarray)
clf.fit(reducedTrainData, trainYarray)
# apply feature reduction to the test data
您应该存储
SelectPercentile
对象,并使用它来transform
测试数据:请参阅下面的代码和注释。在
相关问题 更多 >
编程相关推荐