[scikit-learn] Linear Discriminant Analysis with Cross Validation in Python

Serafeim Loukas seralouk at gmail.com
Wed Mar 8 04:16:44 EST 2017


Dear Sebastian,

Thank you for your response.

Best,
S

.............................................
Loukas Serafeim
University of Geneva
email: seralouk at gmail.com


2017-03-07 17:56 GMT+01:00 Sebastian Raschka <se.raschka at gmail.com>:

> Hi, Loukas and Mahesh,
> for LOOCV, you could e.g., use the LeaveOneOut class
>
> ```
> from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
> from sklearn.model_selection import LeaveOneOut
>
> loo = LeaveOneOut()
> lda = LinearDiscriminantAnalysis()
>
> test_fold_predictions = []
>
> for train_index, test_index in loo.split(X):
>     X_train, X_test = X[train_index], X[test_index]
>     y_train, y_test = y[train_index], y[test_index]
>     lda.fit(X_train, y_train)
>     test_fold_predictions.append(lda.predict(X_test))
> ```
>
> or you could pass the loo to the cross_val_score function directly:
>
> ```
> from sklearn.model_selection import cross_val_score
> cross_val_score(estimator=lda, X=X, y=y, cv=loo)
> ```
>
>
> Best,
> Sebastian
>
>
> > On Mar 7, 2017, at 10:01 AM, Serafeim Loukas <seralouk at gmail.com> wrote:
> >
> > Dear Mahesh,
> >
> > Thank you for your response.
> >
> > I read the documentation however I did not find anything related to
> cross-validation (leave one out).
> > Can you give me a hint?
> >
> > Thank you,
> > S
> >
> > .............................................
> > Loukas Serafeim
> > University of Geneva
> > email: seralouk at gmail.com
> >
> >
> > 2017-03-07 10:56 GMT+01:00 Mahesh Kulkarni <maheshak04 at gmail.com>:
> > Yes. Please see following link:
> >
> > http://scikit-learn.org/stable/modules/generated/
> sklearn.discriminant_analysis.LinearDiscriminantAnalysis.html
> >
> > On Tue, Mar 7, 2017 at 3:18 PM, Serafeim Loukas <seralouk at gmail.com>
> wrote:
> > Dear scikit members,
> >
> >
> > I would like to ask if there is any function that implements Linear
> Discriminant Analysis with Cross Validation (leave one out).
> >
> > Thank you in advance,
> > S
> >
> > _______________________________________________
> > scikit-learn mailing list
> > scikit-learn at python.org
> > https://mail.python.org/mailman/listinfo/scikit-learn
> >
> >
> >
> > _______________________________________________
> > scikit-learn mailing list
> > scikit-learn at python.org
> > https://mail.python.org/mailman/listinfo/scikit-learn
> >
> >
> > _______________________________________________
> > scikit-learn mailing list
> > scikit-learn at python.org
> > https://mail.python.org/mailman/listinfo/scikit-learn
>
> _______________________________________________
> scikit-learn mailing list
> scikit-learn at python.org
> https://mail.python.org/mailman/listinfo/scikit-learn
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-learn/attachments/20170308/52d3949e/attachment.html>


More information about the scikit-learn mailing list