[scikit-learn] Use of Scaler with LassoCV, RidgeCV

Brenet, Yoann yoann.brenet at se1.bp.com
Tue Sep 13 08:45:13 EDT 2016


Hi Sebastian,

Many thanks, that's what I was thinking I should be doing, so thanks a lot for confirming that was the way to go.

Really appreciate the help,
Yoann 

Date: Tue, 13 Sep 2016 08:33:52 -0400
From: Sebastian Raschka <se.raschka at gmail.com>
To: Scikit-learn user and developer mailing list
	<scikit-learn at python.org>
Subject: Re: [scikit-learn] Use of Scaler with LassoCV, RidgeCV
Message-ID: <65093BCA-70D7-4DCF-9EDC-C4EA7B513C3C at gmail.com>
Content-Type: text/plain; charset=utf-8

Hi, Yoann,

when I understand correctly, you want to apply the scaling to each iteration in cross-validation (i.e., the recommended way to do it)? Here, you could use the make_pipeline function, which will call fit on each training fold and call transform on each test fold:


from sklearn.preprocessing import StandardScaler from sklearn.pipeline import make_pipeline from sklearn.cross_validation import cross_val_score from sklearn.linear_model import Ridge

pipe = make_pipeline(StandardScaler(), Ridge()) cross_val_score(pipe, X, y)

You can think of ?pipe? as an Ridge estimator with a StandardScaler attached to it.

Best,
Sebastian


> On Sep 13, 2016, at 8:16 AM, Brenet, Yoann <yoann.brenet at se1.bp.com> wrote:
> 
> Hi all,
>  
> I was trying to use scikit-learn LassoCV/RidgeCV while applying a 'StandardScaler' on each fold set. I do not want to apply the scaler before the cross-validation to avoid leakage but I cannot figure out how I am supposed to do that with LassoCV/RidgeCV.
>  
> Is there a way to do this ? Or should I create a pipeline with Lasso/Ridge and 'manually' search for the hyper-parameters (using GridSearchCV for instance) ?
>  
> Many thanks.
>  
> Yoann
> _______________________________________________
> scikit-learn mailing list
> scikit-learn at python.org
> https://mail.python.org/mailman/listinfo/scikit-learn



------------------------------

Subject: Digest Footer

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


------------------------------

End of scikit-learn Digest, Vol 6, Issue 15
*******************************************


More information about the scikit-learn mailing list