当前位置:网站首页>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
边栏推荐
- Looking at jBPM from jbm3 to jbm5 and activiti
- [200 opencv routines] 213 Draw circle
- [Unity]EBUSY: resource busy or locked
- 函数的分文件编写
- Naming rules and specifications for identifiers
- 第五章 树和二叉树
- Unity 从服务器加载AssetBundle资源写入本地内存,并将下载保存的AB资源从本地内存加载至场景
- PHP curl forged IP address and header information code instance - Alibaba cloud
- ==And eqauls()
- Missed the golden three silver four, found a job for 4 months, interviewed 15 companies, and finally got 3 offers, ranking P7+
猜你喜欢

Bron filter Course Research Report

解决表单action属性传参时值为null的问题

Au revoir! Navigateur ie, cette route Edge continue pour IE

增强 Jupyter Notebook 的功能,这里有四个妙招

Looking at jBPM from jbm3 to jbm5 and activiti

一种跳板机的实现思路

Explain final, finally, and finalize

Instant messaging and BS architecture simulation of TCP practical cases

Bridge mode

Proxy mode (proxy)
随机推荐
云服务器MYSQL查询速度慢
ffmpeg录音录像
QT signal and slot communication mechanism (when multiple windows communicate back and forth [parent and child windows])
[Unity]内置渲染管线转URP
Methods for creating multithreads ---1 creating subclasses of thread class and multithreading principle
dotnet 使用 Crossgen2 对 DLL 进行 ReadyToRun 提升启动性能
Abnormal occurrence and solution
How to distinguish and define DQL, DML, DDL and DCL in SQL
[unity][ecs] learning notes (III)
Inventory of excellent note taking software: good-looking and powerful visual note taking software, knowledge map tools heptabase, hydrogen map, walling, reflect, infranodus, tiddlywiki
PHP curl forged IP address and header information code instance - Alibaba cloud
我大抵是卷上瘾了,横竖睡不着!竟让一个Bug,搞我两次!
接口自动化框架脚手架-利用反射机制实现接口统一发起端
谁知道在中信建投证券开户是不是安全的
使用 ABAP 操作 Excel 的几种方法
MySQL的开发环境和测试环境有什么区别??
Idea failed to connect to SQL Sever
Global exception handlers and unified return results
Teach you how to handle the reverse SVG mapping of JS
bad zipfile offset (local header sig)