当前位置:网站首页>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
边栏推荐
- Abnormal occurrence and solution
- Key summary V of PMP examination - execution process group
- 使用 ABAP 操作 Excel 的几种方法
- Please consult me. I run the MYSQL to MySQL full synchronization of flykcdc in my local ide. This is in my local ide
- 增量快照 必须要求mysql表有主键的吗?
- Resolution: overview of decentralized hosting solution
- 为什么 Istio 要使用 SPIRE 做身份认证?
- Teach you how to handle the reverse SVG mapping of JS
- 纵观jBPM从jBPM3到jBPM5以及Activiti
- Install using snap in opencloudos NET 6
猜你喜欢
增强 Jupyter Notebook 的功能,这里有四个妙招
错过金三银四,找工作4个月,面试15家,终于拿到3个offer,定级P7+
卸载oracle报错
Starting from full power to accelerate brand renewal, Chang'an electric and electrification products sound the "assembly number"
如图 用sql行转列 图一原表,图二希望转换后
To enhance the function of jupyter notebook, here are four tips
再見!IE瀏覽器,這條路由Edge替IE繼續走下去
Unity AssetBundle asset packaging and asset loading
idea连接sql sever失败
The boss asked me to write an app automation -- yaml file reading -- with the whole framework source code attached
随机推荐
老板叫我写个APP自动化--Yaml文件读取--内附整个框架源码
Redis sentinel cluster main database failure data recovery ideas # yyds dry goods inventory #
用 Compose 实现个空调,为你的夏日带去清凉
丢弃 Tkinter!简单配置快速生成超酷炫 GUI!
I'm almost addicted to it. I can't sleep! Let a bug fuck me twice!
Google开源依赖注入框架-Guice指南
Install using snap in opencloudos NET 6
爬虫小操作
Composite pattern
What is the difference between MySQL development environment and test environment??
Comprehensive evaluation of outline note taking software workflow: advantages, disadvantages and evaluation
Key summary VII of PMP examination - monitoring process group (1)
SQL中的DQL、DML、DDL和DCL是怎么区分和定义的
Why does istio use spirit for identity authentication?
栈的弹出压入序列<难度系数>
如图 用sql行转列 图一原表,图二希望转换后
fastposter v2.8.4 发布 电商海报生成器
Matplotlib attribute and annotation
R语言plotly可视化:plotly可视化互相重叠的直方图(histogram)、在直方图的底部边缘使用geom_rug函数添加边缘轴须图Marginal rug plots
Cisco * VRF (virtual route forwarding table)