当前位置:网站首页>Station B Liu Erden - linear regression and gradient descent
Station B Liu Erden - linear regression and gradient descent
2022-07-06 05:42:00 【Ning Ranye】
List of articles
《PyTorch Deep learning practice 》 Complete the collection -B Stand up, Mr. Liu er
Pytorch Details of code attention , Easy to hit the wrong place
B Stand up, Mr. Liu er - Back propagation Lecture 3
B Stand up, Mr. Liu er - Linear regression Pytorch Lecture 4
List of articles
Preface
Lecture 3
The graph of self written code is a straight line , reason : Learning rate alpha Set too large , from 0.1 Set to 0.005 It will become a curve
One 、 Code
import matplotlib.pyplot as plt
import torch
import numpy as np
import csv
import os
x_data = [1.0, 2.0, 3.0]
y_data = [2.0, 4.0, 6.0]
def forward(x,w):
return x*w
def gradient(xs, ys,w):
grad = 0
for(x,y) in zip(xs,ys):
grad += (x*w-y)*x
grad = 2*grad/len(xs)
return grad
def loss(xs, ys, w):
los = 0
for(x,y) in zip(xs,ys):
los += (x*w-y)*(x*w-y)
los = los/len(xs)
return los
w_list = []
mse_list = []
alpha = 0.1
w = 1.0
ite = 100
for i in range(ite):
los = loss(x_data, y_data, w)
mse_list.append(los / 3.0)
w_list.append(w)
w = w - alpha*gradient(x_data, y_data, w)
plt.plot(w_list,mse_list)
plt.xlabel("w")
plt.ylabel("mse")
plt.show()
Above learning rate 0.1
Upper figure : Learning rate 0.005
边栏推荐
- (column 22) typical column questions of C language: delete the specified letters in the string.
- Vulhub vulnerability recurrence 68_ ThinkPHP
- Fluent implements a loadingbutton with loading animation
- PDK工艺库安装-CSMC
- Algorithm -- climbing stairs (kotlin)
- Yygh-11-timing statistics
- 网站进行服务器迁移前应做好哪些准备?
- 02. Develop data storage of blog project
- C进阶-数据的存储(上)
- Selective parameters in MATLAB functions
猜你喜欢
Sword finger offer II 039 Maximum rectangular area of histogram
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
[force buckle]43 String multiplication
02. 开发博客项目之数据存储
什么是独立IP,独立IP主机怎么样?
Cuda11.1 online installation
数字经济破浪而来 ,LTD是权益独立的Web3.0网站?
Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
01. Project introduction of blog development project
A master in the field of software architecture -- Reading Notes of the beauty of Architecture
随机推荐
SQLite queries the maximum value and returns the whole row of data
Unity Vector3. Use and calculation principle of reflect
A master in the field of software architecture -- Reading Notes of the beauty of Architecture
UCF(暑期团队赛二)
js Array 列表 实战使用总结
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
毕业设计游戏商城
[JVM] [Chapter 17] [garbage collector]
B站刘二大人-数据集及数据加载 Lecture 8
2022 half year summary
剑指 Offer II 039. 直方图最大矩形面积
Figure database ongdb release v-1.0.3
【华为机试真题详解】统计射击比赛成绩
大型网站如何选择比较好的云主机服务商?
P2802 回家
05. Security of blog project
嵌入式面试题(一:进程与线程)
Cuda11.1 online installation
Sword finger offer II 039 Maximum rectangular area of histogram
Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist