Machine Learning
Week 1 - Intro
What is Machine Learning
- Checkers playing computer (Arthur Samuel)
Supervised Learning
Right answer is provided. Types of problems
- Regression
- Classification
Unsupervised Learning
The data has no "correct answer"
Cocktail party algorithm
Week 1 - Linear Regression with One variable
Model Representation
Working with housing prices in Portland as our dataset.
Symbols used
- m - number of training examples
- x - input variables
- y - output variable
- h - hypothesis (function h(x) = y)
Univariate linear regression
Cost Function
hΘ(x) = Θ0 + Θ1x
sum of square error as our cost function. He's using 1/2m rather than 1/m, I'm not sure why.
Cost Function - Intuition : 1
Demo of technique.
Cost Function - Intuition : 2
Contour plots.
Gradient Descent
Θj = Θj - α (d/dΘj) * J(Θ0, Θ1)
Gradient Descent Intuition
Explaining gradient descent.
Gradient Descent for Linear Regression
- Θ0 = Θ0 - α(1/m) Σm (hΘ(xi) - yi)
- Θ1 = Θ1 - α(1/m) Σm (hΘ(xi) - yi) * xi
Linear Regression with Multiple Variables - Week 2
Multiple Features
Gradient Descent for Multiple Variables
- Parameters: Θ0,Θ1,...,Θn
- Cost Function: J( Θ0,Θ1,...,Θn ) or simply J(Θ)
Much like before, gradient descent is calculated for all Θs before being applied. To make the formula more uniform we set x0,i = 1 for all i then the formula becomes
Θj = Θj - (α/m) * Σi=1m (h(Θ, xi) - yi) * xi,j
Note: I may have my notation for rows and columns mixed up in the formula - double check before using.
Gradient Descent in Practice 1 - Feature Scaling
Try to make features on a similar scale. In the house example, if our features are size 0-2000ft2 and bedrooms (1-5), it will take a long time to converge, because the first feature is three orders of magnitude larger. Either scale bedrooms up or the ft2 down. A simple way to do this is scale all features filling the range (-1, 1). If future data lies outside this range, it is not a problem. If future data falls way outside this range, you'll have bigger problems.
Try and set the mean to 0. This is "mean normalization".
Of course, none of this applies to x0 = 1.
Gradient Descent in Practice 2 - Learning Rate
The correct α should cause J to decrease continuously. There is not a good automatic way to choose α at this time, but by looking at the iterations graph you can see that the slope is decreasing quickly enough, but not increasing.
Features and Polynomial Regression
You are free to make new features from the features you are given. This includes taking the root, log or square of a feature. Continue to use scaling.
Normal Equation
Using matrices to solve the equation. Feature scaling is not necessary using the normal method.
Gradient descent does not work as well as the number of features becomes very large (because it has an N^2 component). Somewhere around 10K features is a good point to cross over and start using gradient descent.
Normal Equation Noninvertibility
Some matrices are non-invertible.
Octave Tutorial - Week 2
Basic Operations
- ~= Not equal
Semi-colon suppresses echo
To define a matrix
A = [1 2; 3 4; 5 6]
so the delimiter between cols is just a space and the delimiter between rows is semi-colon.
A vector range can be defined with
V = start:step:stop
such as
V = 1:1:5
Giving us the same as
V = [1 2 3 4 5]
note the inclusivity.
We can generate a matrix of all ones with
M = ones(h,w)
with w be width and h being height. Also works with zeros, rand (uniform distribution), randn (normal distribution).
Similarly we can do
eye(x)
producing a square identity matrix.
Print a histogram (bar graph) with
hist(v[, d])
where v is a vector and the optional d is the number of divisions (bars).
Finally,
help command