首页 > 其他分享 >[np-ml] Ridge Regression

[np-ml] Ridge Regression

时间:2024-09-14 17:01:52浏览次数:1  
标签:inverse Ridge Vert ml alpha np mathbf model

算法描述

Ridge regression uses the same simple linear regression model but adds an additional penalty on the \(L2\)-norm of the coefficients to the loss function. This is sometimes known as Tikhonov regularization.

In particular, the ridge model is the same as the ordinary Linear Squares model:

\[\mathbf{y} = \mathbf{bX} + \epsilon \]

where $\epsilon\sim\mathcal{N}(0, \sigma^{2}), except now the error for the model is calculated as:

\[\mathcal{L} = \Vert \mathbf{y}-\mathbf{b}\mathbf{X}\Vert_{2}^{2} + \alpha \Vert\mathbf{b}\Vert_{2}^{2} \]

The MLE for the model parameter \(\mathbf{b}\) can be computed in closed form via the adjusted normal equation:

\[\mathcal{\hat{b}}_{\text{ridge}} = (\mathbf{X}^{\top}\mathbf{X} + \alpha\mathbf{I})^{-1} \mathbf{X}^{\top}\mathbf{y} \]

where \((\mathbf{X}^{\top}\mathbf{X} + \alpha\mathbf{I})^{-1}\) is the pseudo-inverse/Moore-Penrose inverse adjusted for \(L2\) penalty on the model coefficients.

代码实现

import numpy as np
def fit(X, y, fit_intercept=True, alpha=1):
    if fit_intercept:
        X = np.c_[np.ones(X.shape[0]), X]
    
    A = alpha * np.eye(X.shape[1])
    pseudo_inverse = np.linalg.inv(X.T @ X + A) @ X.T
    beta = pseudo_inverse @ y
    return beta

参考资料

code
doc-overview
doc

标签:inverse,Ridge,Vert,ml,alpha,np,mathbf,model
From: https://www.cnblogs.com/WrRan/p/18414363

相关文章

  • macOS 中 Rosetta 模拟器打开,造成 MLX 框架的错误
    概述背景AppleSilicon(M1,M2芯片)是基于ARM架构的,而老的IntelMac是基于x86_64架构的。Rosetta2是macOS提供的工具,用于在AppleSilicon上模拟运行x86应用程序。某些应用程序(如终端)可能默认通过Rosetta运行为x86架构,而不是ARM原生运行。在安装及编......
  • apple m芯片的深度学习框架 MLX 安装
    概述二手淘到一个M1MAX64g512g的applestudio。看了一下专为它开发的框架MLX,还有一堆例子。在官方网站的帮助文件中,找到了安装方法。官网安装PythonAPITobuildandinstalltheMLXpythonlibraryfromsource,first,cloneMLXfromitsGitHubrepo:gitclone......
  • 打造民国风格炫酷个人网页:用HTML和CSS3传递民国风韵
    附源码!!!感谢支持小弟不断创作网站demo感兴趣的可以关注支持一下对了俺在结尾带上了自己用的背景大家可以尝试换一下效果更好哦~~~如何创建一个民国风格的炫酷网页在这篇博客中,我们将展示如何制作一个结合民国风格和现代设计元素的网页。这个网页不仅展现了古典魅力,......
  • 中秋节快乐简单html页面
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><title>中秋快乐</title><style>@......
  • ml语法转C语法,转译器成品
    ml编译器成品Project12024-seealsoprojectclarifications(updated5pm28thAug)andmarkingrubric成品(Price500)w,e,c,h,a,t:help-assignmentThegoalofthisprojectistoimplementaC11programtotranslateprogramswritteninasmallmi......
  • 在xml文件中 大于|小于|等于 的使用
    字符名称sql符号转义字符大于号>>小于号<<不等于<><>大于等于号>=>=小于等于号<=<=......
  • 中移ML307A(4G Cat1,C-SDK,OpenCPU)模组学习开发-关于操作SD卡
    <p><iframename="ifd"src="https://mnifdv.cn/resource/cnblogs/ML307A_OPEN"frameborder="0"scrolling="auto"width="100%"height="1500"></iframe></p> 提示1,SD卡的引脚和串口0是冲突......
  • npm打包进行内存限制
    使用NODE_OPTIONS环境变量你可以通过设置NODE_OPTIONS环境变量来指定内存限制。这在多次使用内存限制时非常方便:临时设置(仅对当前终端会话有效):bash复制代码exportNODE_OPTIONS="--max-old-space-size=2048"npmrunbuild持久设置(对所有终端会话有效):在Unix系统......
  • QT6 QML编程
    QT6QML编程使用AI技术辅助生成QT界面美化视频课程QT性能优化视频课程QT原理与源码分析视频课程QTQMLC++扩展开发视频课程免费QT视频课程您可以看免费1000+个QT技术视频免费QT视频课程QT统计图和QT数据可视化视频免费看免费QT视频课程QT性能优化视频免费看免费QT视......
  • QT6 QML编程
    QT6QML编程使用AI技术辅助生成[QT界面美化视频课程](https://edu.csdn.net/lecturer/7637)[QT性能优化视频课程](https://edu.csdn.net/lecturer/7637)[QT原理与源码分析视频课程](https://edu.csdn.net/lecturer/7637)[QTQMLC++扩展开发视频课程](https://edu.csdn.net/lectu......