【机器学习笔记】逻辑回归

本文详细介绍了逻辑回归,从线性回归到Sigmoid函数,再到数学推导,包括二元逻辑回归模型、似然与概率、损失函数和正则化。重点讨论了L1与L2正则化的区别,并探讨了在机器学习库`linear_model.LogisticRegression`中的参数设置,如penalty和max_iter。
摘要由CSDN通过智能技术生成


此为个人学习笔记,参考B站 《机器学习白板推导系列》课程、周志华《机器学习》、李航《统计学习方法》。

1 导论

1.1 线性回归

代 数 形 式 : z = θ 0 + θ 1 x 1 + θ 2 x 2 + … θ n x n 令 : θ = [ θ 1 θ 2 ⋯ θ n ] ,    x = [ x 1 x 2 ⋯ x n ] , 那 么 :   z = θ T x + θ 0    , 令 : θ = [ θ 0 θ 1 θ 2 ⋯ θ n ] ,    x = [ x 0 x 1 x 2 ⋯ x n ] , 那 么 :   z = θ T x    ( x 0 = 1 ) \begin{aligned} & 代数形式:z=\theta_0+\theta_1 x_1+\theta_2 x_2+\dots\theta_n x_n \\ & 令: \theta=\left[ \begin{matrix} \theta_1 \\ \theta_2 \\ \cdots \\ \theta_n \end{matrix} \right], \ \ x=\left[ \begin{matrix} x_1 \\ x_2 \\ \cdots \\ x_n \end{matrix} \right], 那么:\ z= \theta^Tx+\theta_0 \ \ ,\\ & 令: \theta=\left[ \begin{matrix} \theta_0 \\ \theta_1 \\ \theta_2 \\ \cdots \\ \theta_n \end{matrix} \right], \ \ x=\left[ \begin{matrix} x_0 \\ x_1 \\ x_2 \\ \cdots \\ x_n \end{matrix} \right], 那么:\ z= \theta^Tx\ \ (x_0=1) \end{aligned} z=θ0+θ1x1+θ2x2+θnxn:θ=θ1θ2θn,  x=x1x2xn,: z=θTx+θ0  ,:θ=θ0θ1θ2θn,  x=x0x1x2xn,: z=θTx  (x0=1)

线性回归矩阵表示:
z = θ T x   ( x 0 = 1 ) z=\theta^Tx \ (x_0=1) z=θTx (x0=1)

1.2 Sigmoid 函数

g ( z ) = 1 1 + e − z \large g(z)=\frac{1}{1+e^{-z}} g(z)=1+ez1

S型函数,取值范围在(0,1)区间,可以将任意值函数转换为适合二分类的函数。

与MinMaxScaler相比:

  • MinMaxScaler,可以将数据压缩到[0,1]区间,可以取到0和1
  • Sigmoid函数,将数据压缩到(0,1)区间,不能取到0和1

2 数学推导

2.1 二元逻辑回归模型一般形式

将线性回归 z = θ T x z=\theta^Tx z=θTx ,代入到Sigmoid函数中,可以得到二元逻辑回归的一般形式:
y ( x ) = 1 1 + e − θ T x = e θ T x 1 + e θ T x y(x)=\frac{1}{1+e^{-\theta^Tx}} =\frac{e^{\theta^Tx}}{1+e^{\theta^Tx}} y(x)=1+eθTx1=1+eθTxeθTx
1 − y ( x ) = 1 1 + e − θ T x = 1 1 + e θ T x 1-y(x)=\frac{1}{1+e^{-\theta^Tx}} =\frac{1}{1+e^{\theta^Tx}} 1y(x)=1+eθTx1=1+eθ

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值