当前位置: 首页 > news >正文

百度一直不收录网站网站推广策略

百度一直不收录网站,网站推广策略,一对一直播软件开发,Wordpress 订阅 插件注:书中对代码的讲解并不详细,本文对很多细节做了详细注释。另外,书上的源代码是在Jupyter Notebook上运行的,较为分散,本文将代码集中起来,并加以完善,全部用vscode在python 3.9.18下测试通过。…

注:书中对代码的讲解并不详细,本文对很多细节做了详细注释。另外,书上的源代码是在Jupyter Notebook上运行的,较为分散,本文将代码集中起来,并加以完善,全部用vscode在python 3.9.18下测试通过。

Chapter3 Linear Neural Networks

3.3 Concise Implementations of Linear Regression

import numpy as np
import torch
from torch.utils import data
from d2l import torch as d2ltrue_w=torch.tensor([2,-3.4])
true_b=4.2
features,labels=d2l.synthetic_data(true_w,true_b,1000)#构造一个pytorch数据迭代器
def load_array(data_arrays,batch_size,is_train=True): #@savedataset=data.TensorDataset(*data_arrays)#"TensorDataset" is a class provided by the torch.utils.data module which is a dataset wrapper that allows you to create a dataset from a sequence of tensors. #"*data_arrays" is used to unpack the tuple into individual tensors.#The '*' operator is used for iterable unpacking.#Here, data_arrays is expected to be a tuple containing the input features and corresponding labels. The "*data_arrays" syntax is used to unpack the elements of the tuple and pass them as separate arguments.return data.DataLoader(dataset,batch_size,shuffle=is_train)#Constructs a PyTorch DataLoader object which is an iterator that provides batches of data during training or testing.
batch_size=10
data_iter=load_array([features,labels],batch_size)
print(next(iter(data_iter)))#调用next()函数时会返回迭代器的下一个项目,并更新迭代器的内部状态以便下次调用#定义模型变量,nn是神经网络的缩写
from torch import nn
net=nn.Sequential(nn.Linear(2,1))
#Creates a sequential neural network with one linear layer.
#Input size (in_features) is 2, indicating the network expects input with 2 features.
#Output size (out_features) is 1, indicating the network produces 1 output.#初始化模型参数
net[0].weight.data.normal_(0,0.01)#The underscore at the end (normal_) indicates that this operation is performed in-place, modifying the existing tensor in memory.
net[0].bias.data.fill_(0)#定义均方误差损失函数,也称平方L2范数,返回所有样本损失的平均值
loss=nn.MSELoss()#MSE:mean squared error #定义优化算法(仍是小批量随机梯度下降)
#update the parameters of the neural network (net.parameters()) using gradients computed during backpropagation. 
trainer=torch.optim.SGD(net.parameters(),lr=0.03)#SGD:stochastic gradient descent(随机梯度下降)#训练
num_epochs=3
for epoch in range(num_epochs):for X,y in data_iter:l=loss(net(X),y)trainer.zero_grad()l.backward()trainer.step()#Updates the model parameters using the computed gradients and the optimization algorithm.l=loss(net(features),labels)print(f'epoch {epoch+1},loss {l:.6f}')#{l:.f}表示将变量l格式化为小数点后有6位的浮点数。w=net[0].weight.data
print('w的估计误差:',true_w-w.reshape(true_w.shape))
b=net[0].bias.data
print('b的估计误差:',true_b-b)
http://www.zhongyajixie.com/news/210.html

相关文章:

  • 免费聊天网站模板和源码少儿培训
  • 番禺网站建设外包免费seo工具
  • 绵阳的网站建设公司百度移动排名优化软件
  • 网站跳转是什么意思2022小说排行榜百度风云榜
  • 网站建设发展现状淘宝补流量平台
  • 办公空间设计布局如何进行网站性能优化
  • 本地拖拽网站建设百度快速收录seo工具软件
  • 暴雪国服官网入口seo云优化软件
  • 广州网站建设类岗位seo百度seo排名优化软件
  • 男科医院网站建设网店运营工资一般多少
  • 高端网站建设公司排行2020国内十大小说网站排名
  • 技术支持 东莞网站建设机械加工湖南疫情最新消息
  • 网站静态化怎么做永久免费国外域名注册
  • 来年做哪些网站能致富百度推广排名怎么做的
  • 建设网站跟服务器得关系数字营销服务商seo
  • 网站建设 中企动力中山最知名的网站推广公司
  • 投资建设个什么网站好seo关键词推广优化
  • 大鹏新区网站建设成都seo优化外包公司
  • 做网站前途如何百度地图排名可以优化吗
  • 长沙做网站最好的公司百度知道登录
  • 今日香港头条新闻推广seo优化公司
  • 刚成立公司如何做网站长春网站优化指导
  • 上行30m可以做网站吗整站优化加盟
  • 公司汇报网站建设方案如何快速推广一个新产品
  • 网站建设经费劳动局免费培训项目
  • 如何做公司建网站方案给公司百度营销推广登录平台
  • 金泉网站建设开发网络营销策划方案书范文
  • 西安千叶网站建设百度商务合作电话
  • 淘宝导购网站源码完美动力培训价格表
  • wordpress 消耗 资源湖南优化电商服务有限公司