【问题标题】:How can I regularize a linear regression with scipy's curve_fit?如何使用 scipy 的 curve_fit 对线性回归进行正则化?
【发布时间】:2013-12-27 15:20:43
【问题描述】:

我最近开始熟练使用 Python/scipy curve_fit 来执行线性回归。但是,对于高阶多项式,我的数据有时会过拟合。

如何添加正则化以减少过拟合?

【问题讨论】:

    标签: python numpy machine-learning scipy linear-regression


    【解决方案1】:

    我想知道lasso penalization 是否适合你:

    # 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)
    

    应该在交叉验证期间选择最佳 lambda。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-13
      • 2018-07-31
      • 2019-01-23
      • 1970-01-01
      相关资源
      最近更新 更多