当前位置:网站首页>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
边栏推荐
- ArcGIS应用基础4 专题图的制作
- Game push: image / table /cv/nlp, multi-threaded start!
- Installation de la Bibliothèque de processus PDK - csmc
- B站刘二大人-线性回归 Pytorch
- Vulhub vulnerability recurrence 69_ Tiki Wiki
- 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
- Cuda11.1 online installation
- How can large websites choose better virtual machine service providers?
- UCF(2022暑期团队赛一)
- 指针经典笔试题
猜你喜欢

03. 开发博客项目之登录

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

01. 开发博客项目之项目介绍

01. Project introduction of blog development project

应用安全系列之三十七:日志注入

Pix2pix: image to image conversion using conditional countermeasure networks

Unity Vector3. Use and calculation principle of reflect

B站刘二大人-线性回归及梯度下降

大型网站如何选择比较好的云主机服务商?

Vulhub vulnerability recurrence 73_ Webmin
随机推荐
First acquaintance with CDN
Analysis of grammar elements in turtle Library
Yygh-11-timing statistics
Game push: image / table /cv/nlp, multi-threaded start!
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
Graduation design game mall
Self built DNS server, the client opens the web page slowly, the solution
什么是独立IP,独立IP主机怎么样?
【SQL server速成之路】——身份验证及建立和管理用户账户
[QNX hypervisor 2.2 user manual]6.3.3 using shared memory (shmem) virtual devices
How to download GB files from Google cloud hard disk
Safe mode on Windows
[detailed explanation of Huawei machine test] check whether there is a digital combination that meets the conditions
Selective parameters in MATLAB functions
清除浮动的方式
应用安全系列之三十七:日志注入
What impact will frequent job hopping have on your career?
指针经典笔试题
Migrate Infones to stm32
通讯录管理系统链表实现