当前位置:网站首页>2022 Wu Enda machine learning specialization week 2 practice lab: linear expression
2022 Wu Enda machine learning specialization week 2 practice lab: linear expression
2022-06-28 10:13: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
Video link :https://www.bilibili.com/video/BV19B4y1W76i
边栏推荐
- 生成token
- 满电出发加速品牌焕新,长安电动电气化产品吹响“集结号”
- TCP实战案例之即时通信、BS架构模拟
- Chapter 5 trees and binary trees
- [Unity][ECS]学习笔记(三)
- 如图 用sql行转列 图一原表,图二希望转换后
- 我大抵是卷上瘾了,横竖睡不着!竟让一个Bug,搞我两次!
- 为什么 Istio 要使用 SPIRE 做身份认证?
- Inventory of excellent note taking software: good-looking and powerful visual note taking software, knowledge map tools heptabase, hydrogen map, walling, reflect, infranodus, tiddlywiki
- [Unity]EBUSY: resource busy or locked
猜你喜欢

JVM family (2) - garbage collection

Installing redis under Linux and windows (ultra detailed graphic tutorial)

用 Compose 实现个空调,为你的夏日带去清凉

Xiaomi's payment company was fined 120000 yuan, involving the illegal opening of payment accounts, etc.: Lei Jun is the legal representative, and the products include MIUI wallet app

Numpy array: join, flatten, and add dimensions

一种跳板机的实现思路
![[unity][ecs] learning notes (II)](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[unity][ecs] learning notes (II)

理想中的接口自动化项目

PMP Exam key summary VI - chart arrangement

为什么 Istio 要使用 SPIRE 做身份认证?
随机推荐
用 Compose 实现个空调,为你的夏日带去清凉
Proxy mode (proxy)
abnormal
Read PDF Text and write excel operation
Discard Tkinter! Simple configuration to quickly generate cool GUI!
QT signal and slot communication mechanism (when multiple windows communicate back and forth [parent and child windows])
SQL中的DQL、DML、DDL和DCL是怎么区分和定义的
[unity][ecs] learning notes (II)
How to distinguish and define DQL, DML, DDL and DCL in SQL
为什么 Istio 要使用 SPIRE 做身份认证?
bad zipfile offset (local header sig)
Explain final, finally, and finalize
fastposter v2.8.4 发布 电商海报生成器
Idea failed to connect to SQL Sever
[unity][ecs] learning notes (I)
Key summary V of PMP examination - execution process group
Abnormal occurrence and solution
Methods for creating multithreads ---1 creating subclasses of thread class and multithreading principle
爬虫小操作
Django数据库操作以及问题解决