当前位置:网站首页>2022吴恩达机器学习specialization Week 2 practice lab: Linear regression
2022吴恩达机器学习specialization Week 2 practice lab: Linear regression
2022-06-28 09:57:00 【wuuucj】
Exercise 1
# UNQ_C1
# GRADED FUNCTION: compute_cost
def compute_cost(x, y, w, b):
""" Computes the cost function for linear regression. Args: x (ndarray): Shape (m,) Input to the model (Population of cities) y (ndarray): Shape (m,) Label (Actual profits for the cities) w, b (scalar): Parameters of the model Returns total_cost (float): The cost of using w,b as the parameters for linear regression to fit the data points in x and y """
# number of training examples
m = x.shape[0]
# You need to return this variable correctly
total_cost = 0
### START CODE HERE ###
total_cost = sum(pow((y-(x*w+b)),2))/(2*m)
### END CODE HERE ###
return total_cost
Exercise 2
# UNQ_C2
# GRADED FUNCTION: compute_gradient
def compute_gradient(x, y, w, b):
""" Computes the gradient for linear regression Args: x (ndarray): Shape (m,) Input to the model (Population of cities) y (ndarray): Shape (m,) Label (Actual profits for the cities) w, b (scalar): Parameters of the model Returns dj_dw (scalar): The gradient of the cost w.r.t. the parameters w dj_db (scalar): The gradient of the cost w.r.t. the parameter b """
# Number of training examples
m = x.shape[0]
# You need to return the following variables correctly
dj_dw = 0
dj_db = 0
### START CODE HERE ###
dj_dw = sum(x*(x*w+b-y))/m
dj_db = sum((x*w+b)-y)/m
### END CODE HERE ###
return dj_dw, dj_db
视频链接:https://www.bilibili.com/video/BV19B4y1W76i
边栏推荐
- 最小栈<难度系数>
- Generate token
- Is it safe to open an account with the QR code of CICC securities? Tell me what you know
- Idea failed to connect to SQL Sever
- Wechat applet development log
- To enhance the function of jupyter notebook, here are four tips
- ECS MySQL query is slow
- Unity loads AssetBundle resources from the server and writes them to local memory, and loads the downloaded and saved AB resources from local memory to the scene
- Caffeine cache, the king of cache, has stronger performance than guava
- 六月集训(第28天) —— 动态规划
猜你喜欢

Looking at jBPM from jbm3 to jbm5 and activiti

To enhance the function of jupyter notebook, here are four tips

我大抵是卷上瘾了,横竖睡不着!竟让一个Bug,搞我两次!

【NLP】今年高考英语AI得分134,复旦武大校友这项研究有点意思

Caffeine cache, the king of cache, has stronger performance than guava

Function sub file writing

Decorator

丢弃 Tkinter!简单配置快速生成超酷炫 GUI!

满电出发加速品牌焕新,长安电动电气化产品吹响“集结号”

Starting from full power to accelerate brand renewal, Chang'an electric and electrification products sound the "assembly number"
随机推荐
大纲笔记软件 Workflowy 综合评测:优点、缺点和评价
JVM family (2) - garbage collection
Unity AssetBundle asset packaging and asset loading
Global exception handlers and unified return results
How to view the web password saved by Google browser
Correct conversion between JSON data and list collection
Explain final, finally, and finalize
SQL中的DQL、DML、DDL和DCL是怎么区分和定义的
Abnormal occurrence and solution
Django database operation and problem solving
Summary of MySQL basic knowledge points
Huawei OSPF single region
Cisco * VRF (virtual route forwarding table)
解决表单action属性传参时值为null的问题
接口自动化框架脚手架-参数化工具的实现
Idea failed to connect to SQL Sever
Missed the golden three silver four, found a job for 4 months, interviewed 15 companies, and finally got 3 offers, ranking P7+
使用 ABAP 操作 Excel 的几种方法
读取pdf图片并识别内容
Dear leaders, ask me if MySQL does not support early_ Offset mode? Unsupported star