0
$\begingroup$

I need to implement least square regression to fit polynomials of degree 1-27. I then need to get the leave-one-out error (kfold cross validation where k = n). After doing a lot of research it seems the best way to get the LOO error is to use sklearn cross_val_score(). My problem is I do not know how or if it is possible to use with regression models.

n = len(x)
p, res, _, _, _  = numpy.polyfit(x,y,1,full=True)

cv = cross_val_score(?, X, y, scoring=mse, cv=n)

I cannot figure out what the estimator would be or how to make it in cross_val_score. Being new to python and these topics make this twice as challenging.

$\endgroup$
0
$\begingroup$

numpy and scikit-learn are quite separate open-source projects. As such, they are compatible in some ways but not in others. All scikit-learn models are variants on the fundamental estimator object (see https://scikit-learn.org/stable/tutorial/statistical_inference/settings.html). The cross_val_score function expects a scikit-learn-style estimator object and there's no easy way to create such an object from the output of numpy.polyfit.

I'd suggest working entirely in scikit-learn, creating a regression estimator that you can cross-validate with cross_val_score. This SO post shows you how to build that polynomial regression estimator.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.