Regression

DeeLMind大约 2 分钟

Regression

一元线性回归

回归分析中,只包括一个自变量和一个因变量,且二者的关系可用一条直线近似表示,这种回归分析称为一元线性回归分析。

X, Y = make_regression(n_samples=6,n_features=1,noise=3.5)
f(x) = coef_*x + intercept_
广告费1.339970.344230.23107-0.84034-0.95766-2.28887
房价36.21921-69.29114-20.529098.278768.45972-24.92423

GAN

f(x) = coef_*x + intercept_

f(1.33997) = coef_*1.33997 + intercept_
f(0.34423) = coef_*(0.34423) + intercept_
f(0.23107) = coef_*(0.23107) + intercept_
f(-0.84034) = coef_*(-0.84034) + intercept_
f(-0.95766) = coef_*(-0.95766) + intercept_
f(-2.28887 ) = coef_*(-2.28887) + intercept_

(f(i) - (coef_*i + intercept_))^2 最小值

(coef_*1.33997 + intercept_ - 36.21921)^2
(coef_*0.34423 + intercept_ - (-69.29114))^2
(coef_*0.23107 + intercept_ - (-20.52909))^2
(coef_*(-0.84034) + intercept_ - 8.27876)^2
(coef_*(-0.95766) + intercept_ - 8.45972)^2
(coef_*(-2.28887) + intercept_ - (-24.92423))^2

S(coef_,intercept_) = 

数学公式

S(m)=mini=1n(mxi+bf(i))2 S(m) = min\sum_{i=1}^{n}(mx_{i}+b - f(i))^2

from sympy import *
coef_ = Symbol('coef_')
intercept_ = Symbol('intercept_')
s = (coef_*1.33997 + intercept_ - 36.21921)**2 + (coef_*0.34423 + intercept_ - (-69.29114))**2 + (coef_*0.23107 + intercept_ - (-20.52909))**2 + (coef_*(-0.84034) + intercept_ - 8.27876)**2 + (coef_*(-0.95766) + intercept_ - 8.45972)**2 + (coef_*(-2.28887) + intercept_ - (-24.92423))**2
print(s.expand())

S(coef,intercept)=8.8296171068coef24.3432coefintercept123.8534451234coef+6.0intercept2+123.57354intercept+7295.8587624607 S(coef,intercept) = 8.8296171068*coef^2 - 4.3432*coef*intercept - 123.8534451234*coef + 6.0*intercept^2 + 123.57354*intercept + 7295.8587624607

# 求偏导数
M = diff(s,coef_)
N = diff(s,intercept_)
print(M)
print(N)

M = 17.6592342136*coef_ - 4.3432*intercept_ - 123.8534451234
N = -4.3432*coef_ + 12.0*intercept_ + 123.57354
result = solve([M,N],[coef_,intercept_])

print(result)
{coef_: 4.91867087002977, intercept_: -8.51756405644056}

多元线性回归

  • 影响房价因素
3.07671-0.07466-0.81435
-0.812810.09361-0.20278
-0.58860-1.30011-0.34815
-1.564890.115050.02547
0.04549-0.054191.13453
-0.66959-0.26893-1.18663
  • 房价
54.76623-29.57975-54.72467-48.7173250.02909-85.62378

数学公式

S(a,b,c)=mini=1n(ax1i+bx2i+cx3i+bf(i))2 S(a,b,c) = min\sum_{i=1}^{n}(ax_{1i}+bx_{2i}+cx_{3i} + b - f(i))^2

数学推导

  • datasets
(x11,x12,x13,...,y11)
(x21,x22,x23,...,y12)
(x31,x32,x33,...,y13)

f(x)=W1x1+W2x2+W3x3+b f(x) = W_1*x_1 + W_2*x_2 + W_3*x_3 + b

f(x)=W1x1+W2x2+W3x3+...+Wnxn+b f(x) = W_1*x_1 + W_2*x_2 + W_3*x_3 + ... + W_n*x_n + b

f(x)=inWixi+b f(x) = \sum_{i}^{n}{W_i*x_i} + b

f(x)=inWixi+W0x0 f(x) = \sum_{i}^{n}{W_i*x_i} + W_0*x_0

f(x)=inWixi f(x) = \sum_{i}^{n}{W_i*x_i}

f(x)=WTx f(x) = \vec W^\mathrm{T} * \vec x

J(W)=minin(f(xi)f^(xi))2 J(W) = min\sum_{i}^{n}{(f(x_i) - \hat f(x_i))^2}

J(W)=min12nin(f(xi)f^(xi))2 J(W) = min\frac {1} {2n}\sum_{i}^{n}{(f(x_i) - \hat f(x_i))^2}

W=(XTX)1XY \vec {W} = (\vec X^{T}\vec X)^{-1}\vec X\vec Y

J(W)=dJ(W)dW J(\vec W) = \frac{\mathrm{d} J(\vec W) }{\mathrm{d} \vec W}

J(W)=d12n(inWixif^(xi))2dW J(\vec W) = \frac{\mathrm{d} \frac {1} {2n}(\sum_{i}^{n}{W_i*x_i - \hat f(x_i))^2} }{\mathrm{d} \vec W}

J(W)=212n(WiXiYi)nXi J(\vec W) = 2*\frac{1 }{2n} * (\vec W_i \vec X_i - Y_i)*n*\vec X_i

J(W)=(WiXiYi)Xi J(\vec W) = (\vec W_i \vec X_i - Y_i)\vec X_i

逻辑回归

上次编辑于:
贡献者: DeeLMind