Cost Function

Cost Function

Given a training set (set of sizes and selling prices), hypothesis: h(x) = a0 + a1x, how to choose a0 and a1? Choose a0 and a1 so that h(x) is close to y for our training examples (x, y).

There are many ways to make sure h(x) is as close to y as possible. Minimize Square error function (or Mean squared error) works well with regression problems:

Important:

  • h(x) for fixed a0 and a1 is a function of x, a0 and a1 are constants
  • J(a0, a1) is a function of a0 and a1, x is constant
Below is the graph of h(x) vs. graph of J(a1) (let a0 = 0 for simplicity). Each color of h(x) line corresponds to a point of J(a1) graph

Since our objective is to minimize cost function J, from the graph above, we can achieve our goal by setting a1 = 1

Resource:

https://www.coursera.org/learn/machine-learning/supplement/nhzyF/cost-function
https://www.coursera.org/learn/machine-learning/supplement/u3qF5/cost-function-intuition-i

Comments