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

网销具体怎么做网站营销效果分析怎么写

网销具体怎么做网站,营销效果分析怎么写,广州市建设工程价格信息,建设德国网站借助 PyTorch 实现深度神经网络 - 线性回归 - 第 2 周 | Coursera 线性回归预测 用PyTorch实现线性回归模块 创建自定义模块(内含一个线性回归) 训练线性回归模型 对于线性回归,特定类型的噪声是高斯噪声 平均损失均方误差函数&#xff1a…

借助 PyTorch 实现深度神经网络 - 线性回归 - 第 2 周 | Coursera

线性回归预测

用PyTorch实现线性回归模块

f070f2ec76df43abaf729d5793230134.png

创建自定义模块(内含一个线性回归)

6b99a23f99be443c99f8501dc8f9943f.png

24c6b66fe591473f92115b0246077091.png

训练线性回归模型

对于线性回归,特定类型的噪声是高斯噪声

4dd6e6e710d041118e8c6916ee5ab399.png

平均损失均方误差函数:

ca40bebf938f4d819d5169765b05fe2c.png

loss求解(导数=0):

823863a0a51d49c494927630586adcc1.png

梯度下降

783413bc85ec40649e6c44e137d022e4.png

eq?%5Ceta表示学习率

66a21da7c5ad46f1806059a03f38f82f.png

学习率过高,可能错过参数的最佳值

学习率过低,需要大量的迭代才能获得最小值

Batch Gradient Descent:使用整个训练集来更新模型的参数 

用Pytorch实现线性回归--梯度

493855116b9949559e0ff6ca31455924.png

45f47906ebf14783ac0a1fa75cbc857d.png

0a401308297e4e32bb8b0d351a6617fd.png

9dece871069a4a2891ddbd7478e07e0f.png

每个epoch就是一个iteration:

9802fbe8327d435ba6fb028827a0fcbb.png

画图版:

import torch
w=torch.tensor(-10.0,requires_grad=True)
X=torch.arange(-3,3,0.1).view(-1,1)
f=-3*X
# The class for plottingclass plot_diagram():# Constructordef __init__(self, X, Y, w, stop, go = False):start = w.dataself.error = []self.parameter = []print(type(X.numpy()))self.X = X.numpy()self.Y = Y.numpy()self.parameter_values = torch.arange(start, stop)self.Loss_function = [criterion(forward(X), Y) for w.data in self.parameter_values] w.data = start# Executordef __call__(self, Yhat, w, error, n):self.error.append(error)self.parameter.append(w.data)plt.subplot(212)plt.plot(self.X, Yhat.detach().numpy())plt.plot(self.X, self.Y,'ro')plt.xlabel("A")plt.ylim(-20, 20)plt.subplot(211)plt.title("Data Space (top) Estimated Line (bottom) Iteration " + str(n))# Convert lists to PyTorch tensorsparameter_values_tensor = torch.tensor(self.parameter_values)loss_function_tensor = torch.tensor(self.Loss_function)# Plot using the tensorsplt.plot(parameter_values_tensor.numpy(), loss_function_tensor.numpy())plt.plot(self.parameter, self.error, 'ro')plt.xlabel("B")plt.figure()# Destructordef __del__(self):plt.close('all')
gradient_plot = plot_diagram(X, Y, w, stop = 5)
# Define a function for train the modeldef train_model(iter):LOSS=[]for epoch in range (iter):# make the prediction as we learned in the last labYhat = forward(X)# calculate the iterationloss = criterion(Yhat,Y)# plot the diagram for us to have a better ideagradient_plot(Yhat, w, loss.item(), epoch)# store the loss into listLOSS.append(loss.item())# backward pass: compute gradient of the loss with respect to all the learnable parametersloss.backward()# updata parametersw.data = w.data - lr * w.grad.data# zero the gradients before running the backward passw.grad.data.zero_()
train_model(4)

15c5d775a43646ab97e2989e6726fede.png

cc0cff3af6a34921afbc9b5072d50532.png

9ed27917184b4175858fb2d17e559f1b.png

0e72fbd061894b10bbb3e5e9c1fba34b.png

用Pytorch实现线性回归--训练

与上文类似,只是多加了个b

梯度

c99b3440b11249348eefeba808ee2008.png

0aa14cf6f1714b678471e616405a2022.png

edfd17106a104718a2179867111b28b9.png

画函数图:

# The class for plot the diagramclass plot_error_surfaces(object):# Constructordef __init__(self, w_range, b_range, X, Y, n_samples = 30, go = True):W = np.linspace(-w_range, w_range, n_samples)B = np.linspace(-b_range, b_range, n_samples)w, b = np.meshgrid(W, B)    Z = np.zeros((30,30))count1 = 0self.y = Y.numpy()self.x = X.numpy()for w1, b1 in zip(w, b):count2 = 0for w2, b2 in zip(w1, b1):Z[count1, count2] = np.mean((self.y - w2 * self.x + b2) ** 2)count2 += 1count1 += 1self.Z = Zself.w = wself.b = bself.W = []self.B = []self.LOSS = []self.n = 0if go == True:plt.figure()plt.figure(figsize = (7.5, 5))plt.axes(projection='3d').plot_surface(self.w, self.b, self.Z, rstride = 1, cstride = 1,cmap = 'viridis', edgecolor = 'none')plt.title('Cost/Total Loss Surface')plt.xlabel('w')plt.ylabel('b')plt.show()plt.figure()plt.title('Cost/Total Loss Surface Contour')plt.xlabel('w')plt.ylabel('b')plt.contour(self.w, self.b, self.Z)plt.show()# Setterdef set_para_loss(self, W, B, loss):self.n = self.n + 1self.W.append(W)self.B.append(B)self.LOSS.append(loss)# Plot diagramdef final_plot(self): ax = plt.axes(projection = '3d')ax.plot_wireframe(self.w, self.b, self.Z)ax.scatter(self.W,self.B, self.LOSS, c = 'r', marker = 'x', s = 200, alpha = 1)plt.figure()plt.contour(self.w,self.b, self.Z)plt.scatter(self.W, self.B, c = 'r', marker = 'x')plt.xlabel('w')plt.ylabel('b')plt.show()# Plot diagramdef plot_ps(self):plt.subplot(121)plt.ylimplt.plot(self.x, self.y, 'ro', label="training points")plt.plot(self.x, self.W[-1] * self.x + self.B[-1], label = "estimated line")plt.xlabel('x')plt.ylabel('y')plt.ylim((-10, 15))plt.title('Data Space Iteration: ' + str(self.n))plt.subplot(122)plt.contour(self.w, self.b, self.Z)plt.scatter(self.W, self.B, c = 'r', marker = 'x')plt.title('Total Loss Surface Contour Iteration' + str(self.n))plt.xlabel('w')plt.ylabel('b')plt.show()

http://www.tj-hxxt.cn/news/98631.html

相关文章:

  • 重庆最好的网站建设免费外链平台
  • 自己做网站怎么搜索国家高新技术企业认定
  • 当地自己的淘宝网站怎么做国外新闻最新消息
  • 不花钱可以做网站吗欧美网站建设公司
  • 网站的二级页面怎么做成都计算机培训机构排名前十
  • 中国电力工程造价信息网百度seo教程
  • 淮安建设网站制作短期培训就业学校
  • 做百度网站如何收费百度拍照搜题
  • 注册博客域名做视频网站会怎么样今日热点新闻排行榜
  • 网站建设意义网站站长seo推广
  • 自己建立网站用什么软件网站建设方案书模板
  • 官网查询网站推广百度百科
  • 网站keywords标签怎么写seo视频教程百度网盘
  • 旅游微网站分销淘宝seo优化排名
  • 什么网站可以做设计赚钱博客推广工具
  • 运城做网站的公司今日国内热点新闻头条事件
  • 广州专业网站设计互联网域名注册查询
  • 网站主色调有几种5118
  • 做招聘网站毕业设计太原百度seo排名软件
  • 网站价格评估 优帮云seo竞价培训
  • 吉林seo排名公司优化推广什么意思
  • 衢州做网站最新的网络营销方式
  • 南充做网站电话怎样查询百度收录和排名情况
  • 做网站怎样找信息流投放
  • 鄂州手机网站建设正规推广平台有哪些
  • 如何做推广麦当劳的网站水果店推广营销方案
  • 广州网上注册公司网站怎么让网站快速收录
  • wordpress dx南宁seo优势
  • wordpress esc html xseo网站有优化培训吗
  • saas系统是干嘛的南京seo优化公司