Introduction to Machine Learning Coursera - Andrew Ng
A recap of Course 1 Week 1
Introduction to Machine Learning
A recap of Andrew Ng course (Machine Learning Specialization) on Coursera
Course 1 Week 1

Photo by Lesli Whitecotton on Unsplash
Week 1
What is machine learning?
Supervised Leaning
- Algorithm maps input to output by learning from examples with correct output labels. Email -> Spam or Not, Audio Clip -> Text transcripts (speech recognition), English -> Spanish (machine translation), online ad, my user info -> click ad or not (online advertising), image, radar info -> position of other cars (self-driving), image of phone -> defect (visual inspection)
Unsupervised Learning
- input with no corresponding labels, learn to predict label by observing the features from the input, find pattern or structures from the data. For example, Google News cluster news into groups with similar words, grouping customers
- Anomaly detection: find unusual data points maybe with the help of dimensionality reduction
Regression Model
- x: features, y: targets, f: function (historically called hypothesis), y-hat: prediction. What is the math formula for f to solve linear regression? f(x) = wx+b, a straight line, with one variable, this is a univariable linear regression
- Constructing cost function to help define w and b for the straight line: Model: f(x) = wx+b, w and b are parameters/coefficients/weights we can adjust to improve model

how to find w and b so y-hat is closest to all y? cost function

compare y-hat against y, we get the difference (error) and we take the square of the error, and sum this up across all dataset, but we don’t want to get very large cost as the dataset grows larger so we divide the cost by the data size to get the average squared error not the total squared error, this is a good cost function for regression task.
Why is J(w,b) affected only by w and b, not like f(x) also affected by x? Because our goal is to tweak the w and b to get the lowest cost, but we cannot tweak x and y because they are the dataset. The short answer is a matter of what is changing versus what is fixed when you are training a machine learning model.
In mathematics, a function’s arguments (the letters inside the parentheses) tell you what the function is actively changing or searching across. Because you are optimizing only over w and b, the cost function is written as J(w,b).
- Cost function intuition: the goal is to minimize j(w,b), to understand this better we can reduce the number of parameter in J. We assume b = 0


how to choose w so that J(w) is as small as possible? w=1 general case: minimize J(w,b)

when we visualize J(w,b), it is a 3D curve, and every single point on the net actually represents a solution/model.
Another visualization to help understand the model performances using contour plot, the lines in the contour plot each represent a height, so the three dots/solutions below have same J(w,b), although they were using different Ws and Bs, and these three solutions performed poor as shown in top left plot, they are far away from the data points, just as they are far away from the minimum of the contour plot.

But how to find the best solution automatically? we need gradient descent
Gradient Descent
- is an algorithm used to minimize any function, with even more than 2 parameters. the common initial step is to set w and b as 0 as initial guess, and keep changing until J settles at a minimum, it is possible that J may not be a bowl shape, it is possible that J has multiple minima

imagine that we stand on the mountain top, and every time we execute gradient descent we look 360 degree around to find the steepest way down to valley
- Algorithm
for each execution of a gradient descent algorithm, we simultaneously update both w and b using the current values, instead of update w first then update b. though sequential updates may give you similar results somehow, the implementation is wrong

- Gradient Descent Intuition / Derivative
it is important to know that we don’t need to know everything about calculus to implement and apply machine learning, what we will need will be covered in the course
we explain this using the one parameter version of J as example. The J(w) function looks like a bowl, and gradient descent randomly picks an initial value of w (e.g. the furthest right of w)to start find the minimum J(w). we then draw a tangent line, a straight line that touches the point on j(w), the slope of the straight line is the derivative of the function J(w) at this point. the slope is a positive number and learning rate is always a positive number, so the new w ends up being smaller than the current w. the gradient descent algorithm is moving towards the minimum.

dJ(w) = y * dx how to calculate y? will be covered in section 5
- Learning rate: how to make a good choice of alpha

if we look at a different cost function which is not squared root, there would be more than one local minima, if we initiated w right at the local minimum, the slope equals to 0 so no matter how many times we execute gradient descent algorithm, we won’t move out of it. we are stocked inside a local minima

this explains why gradient descent can reach local minimum even with fixed learning rate. we can apply this for any cost function
- Gradient descent for linear regression

the derivatives for w and b were derived using calculus

the squared error cost is a bowl shape function, convex function, which always have only one global minimum, so gradient descent will always converge to the global minimum. for example we initiated w and b as the blue one and it gradually moves toward the global minimum

this is batch gradient descent, we look at 360 degree around to find the minimum. there are other gradient descent that don’t look at the full dataset for each execution

메타데이터
- post_id
- 4a2e11afc6a7
- slug
- introduction-to-machine-learning-coursera-andrew-ng-4a2e11afc6a7
- url
- https://medium.com/@aimyo/introduction-to-machine-learning-coursera-andrew-ng-4a2e11afc6a7
- canonical_url
- https://medium.com/@aimyo/introduction-to-machine-learning-coursera-andrew-ng-4a2e11afc6a7
- author_url
- https://medium.com/@aimyo
- status
- ok
- fetched_at
- 2026-07-17 22:01:38