Machine Learning (Coursera): Part 1/2
232 flashcards · Computer Science · by charlie42
What h stands for?
Hypothesis
What is h? Example of h
Function that maps x to y
How do we represent the training set?
A list of m training examples
What does this hypothesis function looks like plotted?
What does this hypothesis function looks like plotted?
What's a cost function? What do we do with it?
Function that measures the accuracy of the hypothesis function. We want to minimize it.
Reasonable cost function for most linear regression functions?
Mean squared error
Cost function for linear regression formula
What does each symbol stand for?
Equation for slope and what does it mean on the plot
The higher the slope value, the more vertical the line is.
What does a cost function J of one parameter looks like plotted for linear regression?
What does a cost function J for linear regression of 2 parameters look like?
Alternative way to represent the cost function for linear regression of 2 parameters in 2D?
Contour plot:
The values on one contour line of a contour plot of a function of two variables are
constant
Metaphor for gradient descend
Looking around and taking a baby step in the direction that is the most downhill
Gradient descend algorithm
What does α stand for, what does it represent in the gradient descend metaphor
Learning rate, how large is the baby step
Important consideration about the order of calculations in the gradient descend algorithm
Parameters should be updated simultaneously, don't use the updates first parameter for calculating the second one
Two definitions of a derivative
Instantaneous rate of change Slope of the tangent line
Gradient descent formula with one parameter
Why the cost function J converges to its minimal value during gradient descend with one parameter?
When the curve goes down its derivative slope is negative, so the parameter value goes up, where J is lower.
What does the derivative part of the gradient descend function contribute?
It gives the direction of the steepest descend to move towards (the learning rate determines the size of the step)
What happens if we set the learning rate too high?
Parameter may change too much, to a point where the function changed its direction and is further from the minimum
Why does the gradient descend for linear regression always converge to the global optimum?
The cost function for the linear regression is always a convex function (bowl shaped), and doesn't have local optima
What does "batch" gradient descend means
We look at all the training examples to calculate the cost function
Final algorithm for linear regression gradient descend
One drawback of gradient descend
May converge to a local minimum, sensitive to small differences in initial values
What happens if we set the initial parameters at the local minimum of the cost function?
Since the slope of the derivative is 0, the values won't change
What does this stand for
Set of all matrices 4 by 2 (4 rows, 2 columns)
What is this
A four-dimensional vector
"Scalar" means that an object is a...
single value, not a vector or matrix
Matlab: initialize a matrix
A = [1,2,3; 4,5,6]
Matlab: get an element on the first row second column of a matrix
A(1,2)
Matlab: two ways to store dimensions of a vector/matrix
[m,n] = size(v) dims = size(v)
To add or subtract two matrices, their dimensions must be ...
the same
In scalar multiplication, we simply...
multiply every element by the scalar value
Constraint on dimensions when multiplying a matrix by a vect or
Number of columns in the matrix must be equal to number of rows in the vector
Dimensions of a resulting matrix from multiplying a 3x2 matrix and a 2-dimensional vector
3-dimensional vector
How to get the first value of the resulting vector
1*1 + 2*3 + 1*2 + 5*1
How to solve h for every house using matrix operations
What will the code for this look like? Why is it better to use matrices for this operation than a for loop?
It's computationally faster
How to get first two values of the resulting matrix (first row)
1*1 + 3*0 + 2*5 | 1*3 + 3*1 + 2*2
Constraint on dimensions when multiplying two matrices
Number of columns of the first matrix must be equal to the number of rows of the second matrix
Dimensions of a resulting matrix from multiplying a 3x2 matrix and a 2x3 matrix
3x3
Two steps to go from matrix x vector multiplication of matrix x matrix multiplication
Multiply the first matrix by the vectors from the second matrix one by one Write down the results as vectors
How to solve this using matrix operations?
Commutative property of multiplication of real numbers
3x5 = 5x3
Is matrix multiplication commutative?
No
Associative property of multiplication of real numbers
1 x (2 x 3) = (1 x 2) x 3
Is matrix multiplication associative?
Yes
Identity for real numbers
1 (1 x z = z x 1 = z)
Identity matrix
Matlab: Initialize an identity matrix 2x2
eye(2)
Inverse of a real number
i * (i-1) = 1
Inverse of 0
Undefined (0-1 = 1/0)
Equation for a matrix inverse
A * (A-1) = (A-1) * A = I
Constraint on matrix inverse dimensions
Only a square matrix can have an inverse
How to compute a transpose of a matrix
Take each row of a matrix and write it as columns of the resulting matrix
Formal definition of a transpose
Notation: what do m and n stand for?
m - number of example n - number of features
Notation: what does this stand for?
Value of the feature j of the i-th training example
Notation: what does this stand for?
Input vector of the i-th training example
How many dimensions are there in this vector?
n+1
Hypothesis function for multivariate linear regression
Vectorized way to write the hypothesis function for multivariate linear regression
What makes it possible to write the hypothesis function for the multivariate linear regression as a matrix operation?
To match the length of features of the training examples and the length of linear regression parameters, we create a "fake" feature x0 = 1
Full algorithm for gradient descend for multivariate linear regression
Calculate the standard deviation of
Why we need to scale features for gradient descend
If features have very different ranges, the cost function will be unbalanced, the gradient descend can take a long time to converge
Example of perfect range for all features
Two tricks on features to speed up gradient descend
feature scaling mean normalization
Formula to apply both mean normalization and feature scaling, explain each term
μ = mean s = range or standard deviation
How to tell if the gradient descend is working?
For each iteration plot the cost function with the current Θ, see if it decreases
Fix for cost function increasing with iterations instead of decreasing
Smaller α
Fix for cost function decreasing too slowly with iterations
Higher α
Automatic convergence test
Declare convergence if J(θ) decreases by less than E in one iteration, where E is some small value such as 10−3. In practice the value is hard to choose.
Two things we can do to features to create a better linear regression model
Combine two features into one (size = length x width) Create additional features from x to make the hypothesis function polynomial
Important consideration about features in polynomial linear regression
You need to scale the features (if x has range 1 - 1000 then range of x2 becomes 1 - 1000000)
How to minimize a function?
Take it's derivative Set it to 0 Solve the equation
How to minimize a function with multiple parameters?
Take partial derivatives of each parameter Set all of the equations to 0 Solve the equations for every parameter
Alternative to gradient descend to find Θ at the minimum of the cost function
Analytically minimize the cost function
The equation for minimizing the cost function for linear regression analytically and it's name
The normal equation
What does X look like in the normal equation? What is it called?
Design matrix. Matrix where each row is a training example. First column is always 1 (x0)
Do we need feature scaling when using the normal equation?
No
A advantage of the gradient descend over the normal equation?
Gradient descend scales well with high n. In normal equation need to compute (XTX)-1, and the cost of computing inverse of a matrix is O(n3)
Approximate n that is too large for the normal equation (using modern computers)
n > 10'000
Why matrix inversion function in octave is called pinv?
There are two functions to invert matrices in octave: inv and pinv. pinv is pseudo-inversion, it will invert a matrix even if it's non-invertable (singular/degenerate)
Why would XTX be non-invertible?
Redundant features (linearly dependent on each other) Too many features (more features than training examples)
Octave: comment
%
Octave: not equals
~=
Octave: and
&&
Octave: how to suppress output?
End line with a ;
Octave: print a string
disp(string_name)
Octave: elements from 1 to 2 with interval 0.1
(middle value is 1 by default)
Octave: matrix filled with 1s, 3 by 2
ones(3,2)
Octave: rand(1,3)
3x1 matrix of random numbers, uniformly distributed between 0 and 1
Octave: randn(1,3)
Matrix 3x1 of random numbers from the gaussian distribution around 0
Octave: histogram with 50 bins
hist(a, 50)
Octave: documentation for the rand function
help rand
Octave: size(A,2)
number of columns of the matrix A