Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I regularize a linear regression with scipy's curve_fit?

I have recently become proficient at using Python/scipy curve_fit to perform linear regression. However, with higher order polynomials, my data is sometimes overfit.

How can I add regularization to reduce over-fitting?

like image 505
rjurney Avatar asked Oct 20 '25 10:10

rjurney


1 Answers

I was wondering whether lasso penalization works for you:

# the high order items can be integrated into X (such as x1^2,x1*x2), and change it into a linear regression problem again
lasso.fit(X, y) 
# the selection range of lambda can be determined by yourself.
LassoCV(lambda=array([ 2, 1,9, ..., 0.2 , 0.1]),  
copy_X=True, cv=None, eps=0.001, fit_intercept=True, max_iter=1000,
n_alphas=100, normalize=False, precompute=’auto’, tol=0.0001,
verbose=False)

The optimal lambda is supposed to be chosen during cross validation.

like image 83
lennon310 Avatar answered Oct 22 '25 00:10

lennon310