当前位置:网站首页>B站刘二大人-线性回归及梯度下降
B站刘二大人-线性回归及梯度下降
2022-07-06 05:33:00 【宁然也】
系列文章目录
前言
Lecture 3
自己写的代码跑出来的图是直线,原因:学习率alpha设置的太大,由0.1设置为0.005就会变成曲线
一、代码
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()
上图学习率0.1
上图:学习率0.005
边栏推荐
- 算法-- 爬楼梯(Kotlin)
- Yyds dry inventory SSH Remote Connection introduction
- Easy to understand I2C protocol
- HAC cluster modifying administrator user password
- Selective parameters in MATLAB functions
- SQLite queries the maximum value and returns the whole row of data
- UCF(2022暑期团队赛一)
- Cuda11.1 online installation
- Please wait while Jenkins is getting ready to work
- B站刘二大人-数据集及数据加载 Lecture 8
猜你喜欢
Configuration file converted from Excel to Lua
应用安全系列之三十七:日志注入
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
Modbus协议通信异常
27io stream, byte output stream, OutputStream writes data to file
Nacos - TC Construction of High available seata (02)
[Tang Laoshi] C -- encapsulation: classes and objects
【云原生】3.1 Kubernetes平台安装KubeSpher
Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
Please wait while Jenkins is getting ready to work
随机推荐
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
Selective parameters in MATLAB functions
Codeforces Round #804 (Div. 2) Editorial(A-B)
RustDesk 搭建一个自己的远程桌面中继服务器
In 2022, we must enter the big factory as soon as possible
Vulhub vulnerability recurrence 71_ Unomi
Vulhub vulnerability recurrence 72_ uWSGI
Promotion hung up! The leader said it wasn't my poor skills
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
Unity gets the width and height of Sprite
Force buckle 1189 Maximum number of "balloons"
ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
[machine learning notes] univariate linear regression principle, formula and code implementation
Using stopwatch to count code time
jdbc使用call调用存储过程报错
[leetcode16] the sum of the nearest three numbers (double pointer)
UCF (2022 summer team competition I)
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
注释、接续、转义等符号
图数据库ONgDB Release v-1.0.3