1.Situation
1.Watching bilibili video from Week 1 3.3 to 4.6.
2.Reading and understanding relative quiz from Course 1 week1 Label 4.
2.Video Important Content
3.3 Cost Function
1.definition
Function J is a algorithm to judge the good and bad of parameter w and b.
2.formulation
3.Understand
mean square deviation 均方偏差
why multiply 1/2?
Answer: easy to derivation, to cover the 2.
4.1 Gradient Descent
1.definition
It is a way to get the best W and B.
2.formulation
4.5 Gradient Descent for Linear Regression
1.Understand
we know the linear regression model and cost function.
we can use partial derivative to get local minimum (Linear regression like a soup bowl, so we can get the global minimum).
2.formulation
3.Homework Important Content
3.1Course 1 week1 Label 4
1.Understand
It is a program about cost function, using Visualization- 3D to display it.
The best way to learn is to run the official code, which is in an ipynb document.
what I do is to add some annotation and transform ipynb into py document, and can’t adjust and rotate the image.
transform method: jupyter nbconvert --to script *.ipynb
web link: https://blog.csdn.net/qq_40986693/article/details/115215726
"""
1.Cost Function
2.Goals
implement and explore the cost function for linear regression with one variable.
3.Tools
NumPy, a popular library for scientific computing
Matplotlib, a popular library for plotting data
local plotting routines in the lab_utils_uni.py file in the local directory
lab_utils_uni.py: routines used in Course 1, Week1, labs1-3 dealing with single variables (univariate)
"""
import numpy as np
import matplotlib.pyplot as plt
from lab_utils_uni import plt_intuition, plt_stationary, plt_update_onclick, soup_bowl
# Sets the style of all Matplotlib plots to match a predefined style stored in 'deeplearning.mplstyle'.
# This makes the plots consistent in appearance.
plt.style.use('./deeplearning.mplstyle')
x_train = np.array([1.0, 2.0]) #(size in 1000 square feet)
y_train = np.array([300.0, 500.0]) #(price in 1000s of dollars)
# mean squared error between predicted outputs and actual outputs,
# based on the parameters w (weight) and b (bias).
def compute_cost(x, y, w, b):
# number of training examples
m = x.shape[0] # gives the dimensions of the array
cost_sum = 0
for i in range(m):
f_wb = w * x[i] + b
cost = (f_wb - y[i]) ** 2
cost_sum = cost_sum + cost
total_cost = (1 / (2 * m)) * cost_sum
return total_cost
# calls a custom function to plot initial intuition about the dataset
plt_intuition(x_train,y_train)
# Updates the training data arrays with more points.
x_train = np.array([1.0, 1.7, 2.0, 2.5, 3.0, 3.2])
y_train = np.array([250, 300, 480, 430, 630, 730,])
# Closes all existing Matplotlib plots to clear the figure.
plt.close('all')
# Creates a stationary plot, likely setting up a base for dynamic updates
fig, ax, dyn_items = plt_stationary(x_train, y_train)
# interactive update mechanism where clicking on the plot may trigger updates
updater = plt_update_onclick(fig, ax, x_train, y_train, dyn_items)
# visualize the cost function landscape as a "soup bowl"
soup_bowl()