简体   繁体   中英

fit_transform with the training data and transform with the testing

正如标题所说,我使用fit_transformCountVectorizer训练数据..然后我使用tranform仅与测试数据... ...将这个给了我一样使用fit只在训练和tranform只对测试数据?

The answer is YES :

fit_transform is equivalent to fit followed by transform , but more efficiently implemented. See documentation

Both fit and fit_transform fit your classifier to your dataset. You can then use the same classifier to transform any other dataset (in your case the test set).

If you use fit only on the training and transform on the test data, you won't get the correct result.

When using fit_transform on the training data, it means that the machine is learning from the parameters in the feature space and also transforming (scaling) the training data. On the other hand, you should only use transform on the test data to scale it according to the parameters learned from the training data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM