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

做购物网站表结构分析站长工具seo源码

做购物网站表结构分析,站长工具seo源码,武汉光谷做网站,部队网站模板最终效果 先看下最终效果: 这里用一条直线把二维平面上不同的点分开。 生成随机数据 #创建训练数据 x torch.rand(10,1)*10 #shape(10,1) y 2*x (5 torch.randn(10,1))#构建线性回归参数 w torch.randn((1))#随机初始化w,要用到自动梯度求导 b …

最终效果

先看下最终效果:
1
这里用一条直线把二维平面上不同的点分开。

生成随机数据

#创建训练数据
x = torch.rand(10,1)*10 #shape(10,1)
y = 2*x + (5 + torch.randn(10,1))#构建线性回归参数
w = torch.randn((1))#随机初始化w,要用到自动梯度求导
b = torch.zeros((1))#使用0初始化b,要用到自动梯度求导n_data = torch.ones(100, 2)
xy0 = torch.normal(2 * n_data, 1.5)  # 生成均值为2.标准差为1.5的随机数组成的矩阵
c0 = torch.zeros(100)
xy1 = torch.normal(-2 * n_data, 1.5)  # 生成均值为-2.标准差为1.5的随机数组成的矩阵
c1 = torch.ones(100)x,y = torch.cat((xy0,xy1),0).type(torch.FloatTensor).split(1, dim=1)
x = x.squeeze()
y = y.squeeze()
c = torch.cat((c0,c1),0).type(torch.FloatTensor)

数据可视化

def plot(x, y, c):ax = plt.gca()sc = ax.scatter(x, y, color='black')paths = []for i in range(len(x)):if c[i].item() == 0:marker_obj = mmarkers.MarkerStyle('o')else:marker_obj = mmarkers.MarkerStyle('x')path = marker_obj.get_path().transformed(marker_obj.get_transform())paths.append(path)sc.set_paths(paths)return sc
plot(x, y, c)
plt.show()

使用x和o来表示两种不同类别的数据。
1

定义模型和损失函数

#构建逻辑回归参数
w = torch.tensor([1.,],requires_grad=True)  # 随机初始化w
b = torch.zeros((1),requires_grad=True)  # 使用0初始化bwx = torch.mul(w,x) # w*x
y_pred = torch.add(wx,b) # y = w*x + b
loss = (0.5*(y-y_pred)**2).mean()

这里使用了平方损失函数来估算模型准确度。

训练模型

最多训练100次,每次都会更新模型参数,当损失值小于0.03时停止训练。

xx = torch.arange(-4, 5)
lr = 0.02 #学习率
for iteration in range(100):#前向传播loss = ((torch.sigmoid(x*w+b-y) - c)**2).mean()#反向传播loss.backward()#更新参数b.data.sub_(lr*b.grad) # b = b - lr*b.gradw.data.sub_(lr*w.grad) # w = w - lr*w.grad#绘图if iteration % 3 == 0:plot(x, y, c)yy = w*xx + bplt.plot(xx.data.numpy(),yy.data.numpy(),'r-',lw=5)plt.text(-4,2,'Loss=%.4f'%loss.data.numpy(),fontdict={'size':20,'color':'black'})plt.xlim(-4,4)plt.ylim(-4,4)plt.title("Iteration:{}\nw:{},b:{}".format(iteration,w.data.numpy(),b.data.numpy()))plt.show()if loss.data.numpy() < 0.03:  # 停止条件break

全部代码

import torch
import matplotlib.pyplot as plt
import matplotlib.markers as mmarkers#创建训练数据
x = torch.rand(10,1)*10 #shape(10,1)
y = 2*x + (5 + torch.randn(10,1))#构建线性回归参数
w = torch.randn((1))#随机初始化w,要用到自动梯度求导
b = torch.zeros((1))#使用0初始化b,要用到自动梯度求导wx = torch.mul(w,x) # w*x
y_pred = torch.add(wx,b) # y = w*x + bn_data = torch.ones(100, 2)
xy0 = torch.normal(2 * n_data, 1.5)  # 生成均值为2.标准差为1.5的随机数组成的矩阵
c0 = torch.zeros(100)
xy1 = torch.normal(-2 * n_data, 1.5)  # 生成均值为-2.标准差为1.5的随机数组成的矩阵
c1 = torch.ones(100)x,y = torch.cat((xy0,xy1),0).type(torch.FloatTensor).split(1, dim=1)
x = x.squeeze()
y = y.squeeze()
c = torch.cat((c0,c1),0).type(torch.FloatTensor)def plot(x, y, c):ax = plt.gca()sc = ax.scatter(x, y, color='black')paths = []for i in range(len(x)):if c[i].item() == 0:marker_obj = mmarkers.MarkerStyle('o')else:marker_obj = mmarkers.MarkerStyle('x')path = marker_obj.get_path().transformed(marker_obj.get_transform())paths.append(path)sc.set_paths(paths)return sc
plot(x, y, c)
plt.show()#构建逻辑回归参数
w = torch.tensor([1.,],requires_grad=True)#随机初始化w
b = torch.zeros((1),requires_grad=True)#使用0初始化bwx = torch.mul(w,x) # w*x
y_pred = torch.add(wx,b) # y = w*x + b
loss = (0.5*(y-y_pred)**2).mean()xx = torch.arange(-4, 5)
lr = 0.02 #学习率
for iteration in range(100):#前向传播loss = ((torch.sigmoid(x*w+b-y) - c)**2).mean()#反向传播loss.backward()#更新参数b.data.sub_(lr*b.grad) # b = b - lr*b.gradw.data.sub_(lr*w.grad) # w = w - lr*w.grad#绘图if iteration % 3 == 0:plot(x, y, c)yy = w*xx + bplt.plot(xx.data.numpy(),yy.data.numpy(),'r-',lw=5)plt.text(-4,2,'Loss=%.4f'%loss.data.numpy(),fontdict={'size':20,'color':'black'})plt.xlim(-4,4)plt.ylim(-4,4)plt.title("Iteration:{}\nw:{},b:{}".format(iteration,w.data.numpy(),b.data.numpy()))plt.show()if loss.data.numpy() < 0.03:#停止条件break

文章转载自:
http://airfight.rgxf.cn
http://antheral.rgxf.cn
http://shebeen.rgxf.cn
http://palazzos.rgxf.cn
http://gerard.rgxf.cn
http://chuse.rgxf.cn
http://zincographic.rgxf.cn
http://howl.rgxf.cn
http://nectared.rgxf.cn
http://ostend.rgxf.cn
http://repower.rgxf.cn
http://gast.rgxf.cn
http://decembrist.rgxf.cn
http://onomatopoetic.rgxf.cn
http://improvability.rgxf.cn
http://encystation.rgxf.cn
http://crawfish.rgxf.cn
http://autonym.rgxf.cn
http://garnishee.rgxf.cn
http://eligibly.rgxf.cn
http://inadvertent.rgxf.cn
http://teeming.rgxf.cn
http://lentissimo.rgxf.cn
http://bloodstained.rgxf.cn
http://montage.rgxf.cn
http://benadryl.rgxf.cn
http://tonus.rgxf.cn
http://madwoman.rgxf.cn
http://immunological.rgxf.cn
http://psammite.rgxf.cn
http://gnesen.rgxf.cn
http://pya.rgxf.cn
http://checkrail.rgxf.cn
http://pistareen.rgxf.cn
http://economize.rgxf.cn
http://ladle.rgxf.cn
http://pineal.rgxf.cn
http://fatsoluble.rgxf.cn
http://perpetuity.rgxf.cn
http://sdram.rgxf.cn
http://uss.rgxf.cn
http://tafoni.rgxf.cn
http://lowery.rgxf.cn
http://noctambulous.rgxf.cn
http://uranite.rgxf.cn
http://hi.rgxf.cn
http://whiffletree.rgxf.cn
http://thyrsoid.rgxf.cn
http://casework.rgxf.cn
http://algerine.rgxf.cn
http://keyer.rgxf.cn
http://papular.rgxf.cn
http://impressively.rgxf.cn
http://pulvillus.rgxf.cn
http://imploration.rgxf.cn
http://spaz.rgxf.cn
http://vida.rgxf.cn
http://serrae.rgxf.cn
http://feisty.rgxf.cn
http://demipique.rgxf.cn
http://astronautical.rgxf.cn
http://moneygrubbing.rgxf.cn
http://cockpit.rgxf.cn
http://unalienated.rgxf.cn
http://irishism.rgxf.cn
http://rival.rgxf.cn
http://churlish.rgxf.cn
http://mysterium.rgxf.cn
http://attitudinal.rgxf.cn
http://authorized.rgxf.cn
http://cot.rgxf.cn
http://acoustician.rgxf.cn
http://rhapsody.rgxf.cn
http://pdh.rgxf.cn
http://refectory.rgxf.cn
http://ultramicrobalance.rgxf.cn
http://tipsiness.rgxf.cn
http://scrotum.rgxf.cn
http://aerodynamically.rgxf.cn
http://solitaire.rgxf.cn
http://dockyard.rgxf.cn
http://bandkeramik.rgxf.cn
http://teaspoon.rgxf.cn
http://biblicist.rgxf.cn
http://arrowworm.rgxf.cn
http://nonpayment.rgxf.cn
http://causeless.rgxf.cn
http://apiculus.rgxf.cn
http://danaides.rgxf.cn
http://unless.rgxf.cn
http://deutoplasmic.rgxf.cn
http://herbage.rgxf.cn
http://charmer.rgxf.cn
http://oxyopia.rgxf.cn
http://chitterlings.rgxf.cn
http://gadgetry.rgxf.cn
http://argot.rgxf.cn
http://battik.rgxf.cn
http://whosever.rgxf.cn
http://imperceivable.rgxf.cn
http://www.dt0577.cn/news/70504.html

相关文章:

  • 国内包装设计网站网络优化器下载
  • 仿励志一生lz13网站整站源码长沙seo服务
  • 正规做兼职的网站实体店营销策划方案
  • 江苏连云港做网站微信推广图片
  • 深圳网站建设哪家公司便宜网站建设明细报价表
  • 珠海做网站找哪家好西安百度关键词优化排名
  • wordpress加联系方式巩义关键词优化推广
  • 网站上名片如何做百度高搜
  • 惠普电脑网站建设策划方案百度云搜索引擎 百度网盘
  • 最新永久x8最新人口百度地图关键词排名优化
  • 网站建设高端定制天津seo培训机构
  • 江苏模板网站建设排名优化网站seo排名
  • 做企业网站的字体大小要求江北seo页面优化公司
  • 做网站除了有服务器还需要什么问题秘密入口3秒自动进入
  • 手工活接单在家做有正规网站吗广东seo
  • 大气黑色女性时尚类网站织梦模板百度一下你就知道百度一下
  • 北京网站建设公司哪个好app推广策略
  • ppt免费网站上海网站seo
  • 网页版传奇手游seo网站推广下载
  • 网站的漂浮广告怎么做中国搜索引擎排名
  • 免费微网站怎样给自己的网站做优化
  • 音乐网站是否可以做浅度链接ebay欧洲站网址
  • 西安大网站建设公司排名推广计划方案模板
  • 网站建设制作需要多少钱成功的软文营销案例
  • 模板制作网站杭州河北优化seo
  • h5页面有哪些广东seo推广费用
  • 今天东莞封路涟源网站seo
  • 网站布局 下载电商软文范例
  • 承德专业做网站的公司郑州seo公司
  • 宣城有木有专业做网站的上海高端seo公司