当前位置:网站首页>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
边栏推荐
- 27io stream, byte output stream, OutputStream writes data to file
- 改善Jpopup以实现动态控制disable
- 03. Login of development blog project
- [Jiudu OJ 08] simple search x
- 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
- 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
- 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
- Vulhub vulnerability recurrence 67_ Supervisor
- LeetCode_字符串反转_简单_557. 反转字符串中的单词 III
- A master in the field of software architecture -- Reading Notes of the beauty of Architecture
猜你喜欢
【SQL server速成之路】——身份驗證及建立和管理用戶賬戶
Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
ArcGIS应用基础4 专题图的制作
04. 项目博客之日志
Game push image / table /cv/nlp, multi-threaded start
Analysis of grammar elements in turtle Library
Safe mode on Windows
Application Security Series 37: log injection
[Tang Laoshi] C -- encapsulation: classes and objects
ARTS Week 25
随机推荐
Closure, decorator
HAC cluster modifying administrator user password
算法-- 爬楼梯(Kotlin)
jdbc使用call调用存储过程报错
Vulhub vulnerability recurrence 68_ ThinkPHP
Vulhub vulnerability recurrence 72_ uWSGI
【华为机试真题详解】统计射击比赛成绩
Selective parameters in MATLAB functions
Zoom and pan image in Photoshop 2022
Safe mode on Windows
Web Security (VI) the use of session and the difference between session and cookie
[SQL Server Express Way] - authentification et création et gestion de comptes utilisateurs
通讯录管理系统链表实现
[machine learning notes] univariate linear regression principle, formula and code implementation
2022半年总结
B站刘二大人-数据集及数据加载 Lecture 8
Easy to understand IIC protocol explanation
Rustdesk builds its own remote desktop relay server
AUTOSAR从入门到精通番外篇(十)-嵌入式S19文件解析
嵌入式面试题(一:进程与线程)