TechGita

Machine Learning Basics

machine learningneural networkslinear regression
July 1, 2017 2 min read

Machine Learning is the field of study that gives computer the ability to learn without being explicitly programmed. A computer program is said to learn from experience E with respect ot some task T and some performance measure P, if its performance on T , as measured by P, improves with experience E.
Machine Learning Algorithms:

  1. Supervised Learning
    • Regression (continuous output)
    • Classification (discrete valued output)
  2. Unsupervised Learning

Linear Regression

Linear Regression with one variable

Hypothesis:hθ(x)=θ0+θ1xHypothesis : h_{\theta}(x) = \theta_{0} + \theta_{1}x
Parameters:θ0,θ1Parameters : \theta_{0}, \theta_{1}
Costfunction:J(θ0,θ1)=12mi=1m(hθ(xi)yi)2Cost function : J(\theta_{0}, \theta_{1}) = \frac{1}{2m}\sum\limits_{i=1}^{m}(h_{\theta}(x^{i}) - y^{i})^2
Goal:Minimize:J(θ0,θ1)Goal : Minimize : J(\theta_{0},\theta_{1})

Gradient descent
Repeat until covergence
θj:=θjαθjJ(θ0,θ1)\theta_{j} := \theta_{j} - \alpha\frac{\partial}{\partial\theta_{j}}J(\theta_{0}, \theta_{1}) (for j=0 and 1)

θ0:=θ0α1mi=1m(hθ(xi)yi)\theta_{0} := \theta_{0} - \alpha\frac{1}{m}\sum\limits_{i=1}^{m}(h_{\theta}(x^{i}) - y^{i})

θ1:=θ1α1mi=1m(hθ(xi)yi)xi\theta_{1} := \theta_{1} - \alpha\frac{1}{m}\sum\limits_{i=1}^{m}(h_{\theta}(x^{i}) - y^{i})x^{i}

Linear Regression with multiple variable

Hypothesis:hθ=θTx=θ0x0+θ1x1+...θnxnHypothesis : h_{\theta} = \theta^{T}x = \theta_{0}x_{0} + \theta_{1}x_{1} + . . . \theta_{n}x_{n}

Parameters:θ=[θ0,θ1,θ2,..θn]TParameters : \theta = [ \theta_{0}, \theta_{1}, \theta_{2}, . . \theta_{n} ]^T

Costfunction:J(θ)=12mi=1m(hθ(xi)yi)2Cost function : J(\theta) = \frac{1}{2m}\sum\limits_{i=1}^{m}(h_{\theta}(x^{i}) - y^{i})^2

Gradient descent
Repeat until convergence
θj:=θjαθjJ(θ)\theta_{j} := \theta_{j} - \alpha\frac{\partial}{\partial\theta_{j}}J(\theta) (simultaneously update for every j=0,1,2...n)

θj:=θjα1mi=1m(hθ(xi)yi)xj\theta_{j} := \theta_{j} - \alpha\frac{1}{m}\sum\limits_{i=1}^{m}(h_{\theta}(x^{i}) - y^{i})x^{j}

Method to solve of θ\theta analytically : Normal Equation

Let hθ=θTx=θ0x0+θ1x1+...θnxnh_{\theta} = \theta^{T}x = \theta_{0}x_{0} + \theta_{1}x_{1} + . . . \theta_{n}x_{n}

    (θTx)T=Y\implies (\theta^Tx)^T = Y

    xθT=Y\implies x\theta^T = Y

    xTxθT=xTY\implies x^Tx\theta^T = x^TY

    θT=(xTx)1xTY\implies \theta^T = (x^Tx)^{-1}x^TY

Logistic Regression

In Logistic regression, 0h(θ)10 \le h(\theta) \le 1
In Linear regression, h(θ)=θTx(R)h(\theta) = \theta^Tx \in (R)
In Logistic regression, h(θ)=g(θTx)h(\theta) = g(\theta^Tx)
where,
       g(z)=11+ez=sigmoid/logisticfunction\ \ \ \ \ \ \ g(z) = \frac{1}{1 + e^{-z}} = sigmoid/logistic function

    hθ(x)=11+eθTx\implies h_{\theta}(x) = \frac{1}{1 + e^{-\theta^Tx}}

hθ(x)h_{\theta}(x) = estimated probability that y=1 on input x. i.e., hθ(x)=P(y=1x;θ)h_{\theta}(x) = P(y=1|x;\theta) = prob. that y=1, given x, parametrized by θ\theta. Now; hθ(x)=0.5h_{\theta}(x) = 0.5

    11+eθTx=0.5\implies \frac{1}{1 + e^{-\theta^Tx}} = 0.5

    θTx=0\implies \theta^Tx = 0

so, hθ(x)0.5    θTx0h_{\theta}(x) \ge 0.5 \implies \theta^Tx \ge 0 and, hθ(x)0.5    θTx0h_{\theta}(x) \le 0.5 \implies \theta^Tx \le 0

Sigmoid function

Ex. Let hθ(x)=g(θ0+θ1x1+θ2x2)=g(θTx)h_{\theta}(x) = g(\theta_{0} + \theta_{1}x_{1} + \theta_{2}x_{2}) = g(\theta^Tx) (at θ=[3,1,1]\theta=[-3,1,1])
    Predict yif 3+x1+x20\implies Predict \ y if \ -3 + x_1 + x_2 \ge 0
    x1+x23\implies x_1 + x_2 \ge 3 (Linear decision boundary)

Cost function for logistic regression
J(θ)=1mi=1m[yilog(h(xi,θ))+(1yi)log(1h(xi,θ))]J(\theta) = -\frac{1}{m}\sum\limits_{i=1}^{m}[y^{i}log(h(x^{i},\theta)) + (1-y^{i})log(1-h(x^{i},\theta))]

Following to to be completed . . .

Multi-class Classification

Neural Networks

Machine Learning Diagnostics