Gradient Descent for Multiple Variables

2019/04/22 Machine_Learning

Hypothesis

$h_{\theta}(x)=\theta^{T} x=\theta_{0} x_{0}+\theta_{1} x_{1}+\theta_{2} x_{2}+\cdots+\theta_{n} x_{n}$, $x_{0}=1$

Parameters

$\theta={\theta_{0}, \theta_{1}, \ldots, \theta_{n}}$

Cost function

$J(\theta)=J\left(\theta_{0}, \theta_{1}, \ldots, \theta_{n}\right)=\frac{1}{2 m} \sum_{i=1}^{m}\left(h_{\theta}\left(x^{(i)}\right)-y^{(i)}\right)^{2}$

Gradient descent

  • Previously ($n=1$)
  • New algorithm ($n \geq 1$)

Python code

def computeCost(X, y, theta):
  inner = np.power(((X * theta.T) - y), 2) 
  return np.sum(inner) / (2 * len(X))

Reference

Search

    Table of Contents