[scikit-learn] how to preprocess in the cross_validate

charujing123 charujing123 at 163.com
Wed Jul 10 03:53:58 EDT 2019


Hi Oliver 
For example 5-cross validation. In the cross_validate function,  the StandardScaler would be fit in the trainning data, generating a model transformation? Then test data would also be transformed based on this model transformation. This two steps would be done 5 times.
If I used make_pipeline(StandardScaler(), SVC()), is this right?
Thanks.
Rujing

2019-07-10 

charujing123 



发件人:Oliver Rausch <oliverrausch99 at gmail.com>
发送时间:2019-07-09 17:00
主题:Re: [scikit-learn] how to preprocess in the cross_validate
收件人:"Scikit-learn mailing list"<scikit-learn at python.org>
抄送:

Hi Rujing,
You can integrate the preprocessing into the estimator by placing an estimator at the end of the pipeline.


For example:
make_pipeline(StandardScaler(), SVC())


This pipeline has a Support vector classifier at the end. Calling a function of the pipeline, for example fit(X, y), will first apply the StandardScaler to X, and then use the preprocessed X to fit the SVC.


When you use such an estimator in the cross_validate function, the result is that the preprocessing will be applied during cross validation, like you wanted.


Let me know if you have more questions.
Oliver 


On Tue, Jul 9, 2019 at 03:04 charujing123 <charujing123 at 163.com> wrote:

Hi Oliver,
Thanks for your kind reply. I read the manual, however, i did not find any options in the function of cross_validate to control the fit transformation. The fit_transform could be used to preprocessing in the pipeline, however, how to integrate this into the function of sklearn.model_selection.cross_validate?
Thanks.
Rujing

2019-07-09 

charujing123 



发件人:Oliver Rausch <oliverrausch99 at gmail.com>
发送时间:2019-07-07 16:03
主题:Re: [scikit-learn] how to preprocess in the cross_validate
收件人:"Scikit-learn mailing list"<scikit-learn at python.org>
抄送:

Hi Rujing,
The Pipeline [0] from sklearn may be of interest to you.


Best regards,
Oliver 
—
[0] https://scikit-learn.org/stable/modules/compose.html


On Sun, Jul 7, 2019 at 08:50 charujing123 <charujing123 at 163.com> wrote:

Hi
It's easy to preprocess when i used part of data to train and test. However, how to preprocess within the function of sklearn.model_selection.cross_validate?
Thanks.
Rujing

2019-07-07



charujing123 
_______________________________________________
scikit-learn mailing list
scikit-learn at python.org
https://mail.python.org/mailman/listinfo/scikit-learn

-- 

Best Regards,
Oliver


_______________________________________________
scikit-learn mailing list
scikit-learn at python.org
https://mail.python.org/mailman/listinfo/scikit-learn

-- 

Best Regards,
Oliver
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-learn/attachments/20190710/2a074689/attachment.html>


More information about the scikit-learn mailing list