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

公司网站建设步骤十大最靠谱it培训机构

公司网站建设步骤,十大最靠谱it培训机构,网站的电子手册用什么做的,请拿笔记记下新域名梯度下降 一、线性回归 线性回归算法推导过程可以基于最小二乘法直接求解,但这并不是机器学习的思想,由此引入了梯度下降方法。本文讲解其中每一步流程与实验对比分析。 1.初始化 import numpy as np import os %matplotlib inline import matplotli…

梯度下降

一、线性回归

线性回归算法推导过程可以基于最小二乘法直接求解,但这并不是机器学习的思想,由此引入了梯度下降方法。本文讲解其中每一步流程与实验对比分析。

1.初始化
import numpy as np
import os
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
plt.rcParams['axes.labelsize'] = 14
plt.rcParams['xtick.labelsize'] = 12
plt.rcParams['ytick.labelsize'] = 12
import warnings
warnings.filterwarnings('ignore')
np.random.seed(42)
2.回归方程

在这里插入图片描述

import numpy as np
X = 2*np.random.rand(100,1)
y = 4+ 3*X +np.random.randn(100,1)
plt.plot(X,y,'b.')
plt.xlabel('X_1')
plt.ylabel('y')
plt.axis([0,2,0,15])
plt.show()

在这里插入图片描述

X_b = np.c_[np.ones((100,1)),X]
theta_best = np.linalg.inv(X_b.T.dot(X_b)).dot(X_b.T).dot(y)
print(theta_best) 
# 输出 :
array([[4.21509616],[2.77011339]])
X_new = np.array([[0],[2]])
X_new_b = np.c_[np.ones((2,1)),X_new]
y_predict = X_new_b.dot(theta_best)
print(y_predict)
# 输出:
array([[4.21509616],[9.75532293]])
plt.plot(X_new,y_predict,'r--')
plt.plot(X,y,'b.')
plt.axis([0,2,0,15])
plt.show()

在这里插入图片描述

二、调用sklearn API

sklearnAPI官网: https://scikit-learn.org/stable/modules/classes.html

from sklearn.linear_model import LinearRegression
lin_reg = LinearRegression()
lin_reg.fit(X,y)
print (lin_reg.coef_)
print (lin_reg.intercept_)
# 
[[2.77011339]]
[4.21509616]

三、梯度下降

在这里插入图片描述
当步长较小时,训练次数较多;
在这里插入图片描述
当步长较大时,波动大;
在这里插入图片描述
学习率应当尽可能小,随着迭代的进行应当越来越小。
在这里插入图片描述
在这里插入图片描述

1.批量梯度下降
eta = 0.1 #学习率
n_iterations = 1000 # 迭代次数
m = 100
theta = np.random.randn(2,1) # 随机初始化参数theta
for iteration in range(n_iterations):gradients = 2/m* X_b.T.dot(X_b.dot(theta)-y)theta = theta - eta*gradients
theta
# 
array([[4.21509616],[2.77011339]])
X_new_b.dot(theta)
#
array([[4.21509616],[9.75532293]])
theta_path_bgd = []
def plot_gradient_descent(theta,eta,theta_path = None):m = len(X_b)plt.plot(X,y,'b.')n_iterations = 1000for iteration in range(n_iterations):y_predict = X_new_b.dot(theta)plt.plot(X_new,y_predict,'b-')gradients = 2/m* X_b.T.dot(X_b.dot(theta)-y)theta = theta - eta*gradientsif theta_path is not None:theta_path.append(theta)plt.xlabel('X_1')plt.axis([0,2,0,15])plt.title('eta = {}'.format(eta))
theta = np.random.randn(2,1)plt.figure(figsize=(10,4))
plt.subplot(131)
plot_gradient_descent(theta,eta = 0.02)
plt.subplot(132)
plot_gradient_descent(theta,eta = 0.1,theta_path=theta_path_bgd)
plt.subplot(133)
plot_gradient_descent(theta,eta = 0.5)
plt.show()

在这里插入图片描述

2.随机梯度下降

在这里插入图片描述

theta_path_sgd=[]
m = len(X_b)
np.random.seed(42)
n_epochs = 50
t0 = 5
t1 = 50def learning_schedule(t):return t0/(t1+t)
theta = np.random.randn(2,1)for epoch in range(n_epochs):for i in range(m):if epoch < 10 and i<10:y_predict = X_new_b.dot(theta)plt.plot(X_new,y_predict,'r-')random_index = np.random.randint(m)xi = X_b[random_index:random_index+1]yi = y[random_index:random_index+1]gradients = 2* xi.T.dot(xi.dot(theta)-yi)eta = learning_schedule(epoch*m+i)theta = theta-eta*gradientstheta_path_sgd.append(theta)plt.plot(X,y,'b.')
plt.axis([0,2,0,15])   
plt.show()

在这里插入图片描述

3.MiniBatch梯度下降
theta_path_mgd=[]
n_epochs = 50
minibatch = 16
theta = np.random.randn(2,1)
t0, t1 = 200, 1000
def learning_schedule(t):return t0 / (t + t1)
np.random.seed(42)
t = 0
for epoch in range(n_epochs):shuffled_indices = np.random.permutation(m)X_b_shuffled = X_b[shuffled_indices]y_shuffled = y[shuffled_indices]for i in range(0,m,minibatch):t+=1xi = X_b_shuffled[i:i+minibatch]yi = y_shuffled[i:i+minibatch]gradients = 2/minibatch* xi.T.dot(xi.dot(theta)-yi)eta = learning_schedule(t)theta = theta-eta*gradientstheta_path_mgd.append(theta)
theta 
# 
array([[4.25490684],[2.80388785]])

四、3种策略的对比实验

theta_path_bgd = np.array(theta_path_bgd)
theta_path_sgd = np.array(theta_path_sgd)
theta_path_mgd = np.array(theta_path_mgd)
plt.figure(figsize=(12,6))
plt.plot(theta_path_sgd[:,0],theta_path_sgd[:,1],'r-s',linewidth=1,label='SGD')
plt.plot(theta_path_mgd[:,0],theta_path_mgd[:,1],'g-+',linewidth=2,label='MINIGD')
plt.plot(theta_path_bgd[:,0],theta_path_bgd[:,1],'b-o',linewidth=3,label='BGD')
plt.legend(loc='upper left')
plt.axis([3.5,4.5,2.0,4.0])
plt.show()

在这里插入图片描述
实际当中用minibatch比较多,一般情况下选择batch数量应当越大越好。


文章转载自:
http://nemoricole.mnqg.cn
http://cokey.mnqg.cn
http://brahmacharya.mnqg.cn
http://haemolysin.mnqg.cn
http://nuzzer.mnqg.cn
http://offend.mnqg.cn
http://mannar.mnqg.cn
http://grateful.mnqg.cn
http://neighbourly.mnqg.cn
http://blowy.mnqg.cn
http://superiority.mnqg.cn
http://oblomov.mnqg.cn
http://nyc.mnqg.cn
http://rota.mnqg.cn
http://resonantly.mnqg.cn
http://enspirit.mnqg.cn
http://ahithophel.mnqg.cn
http://moctezuma.mnqg.cn
http://enthralment.mnqg.cn
http://heterodesmic.mnqg.cn
http://palaeozoology.mnqg.cn
http://plasmapheresis.mnqg.cn
http://cosmopolitism.mnqg.cn
http://lincomycin.mnqg.cn
http://procuratorship.mnqg.cn
http://karoo.mnqg.cn
http://incompletive.mnqg.cn
http://sega.mnqg.cn
http://ministerial.mnqg.cn
http://witherite.mnqg.cn
http://epigonus.mnqg.cn
http://trolleybus.mnqg.cn
http://talus.mnqg.cn
http://ream.mnqg.cn
http://bridle.mnqg.cn
http://occurrent.mnqg.cn
http://exchangite.mnqg.cn
http://impureness.mnqg.cn
http://droopy.mnqg.cn
http://patroclinous.mnqg.cn
http://miaow.mnqg.cn
http://sapphirine.mnqg.cn
http://sodden.mnqg.cn
http://dequeue.mnqg.cn
http://profuse.mnqg.cn
http://fibered.mnqg.cn
http://tsimmes.mnqg.cn
http://desman.mnqg.cn
http://moonquake.mnqg.cn
http://manoeuver.mnqg.cn
http://amass.mnqg.cn
http://histrionics.mnqg.cn
http://nonconducting.mnqg.cn
http://bowyer.mnqg.cn
http://bitonal.mnqg.cn
http://hadj.mnqg.cn
http://polystichous.mnqg.cn
http://kirovabad.mnqg.cn
http://cataphonic.mnqg.cn
http://ketchup.mnqg.cn
http://prudish.mnqg.cn
http://frieze.mnqg.cn
http://closefisted.mnqg.cn
http://samara.mnqg.cn
http://fogey.mnqg.cn
http://sherlock.mnqg.cn
http://physiognomist.mnqg.cn
http://sociogenetic.mnqg.cn
http://specify.mnqg.cn
http://undervest.mnqg.cn
http://rumen.mnqg.cn
http://habitacle.mnqg.cn
http://lysis.mnqg.cn
http://ejectment.mnqg.cn
http://tarantara.mnqg.cn
http://naevi.mnqg.cn
http://terminableness.mnqg.cn
http://metallograph.mnqg.cn
http://burly.mnqg.cn
http://anomalistic.mnqg.cn
http://agglutinin.mnqg.cn
http://maharanee.mnqg.cn
http://octu.mnqg.cn
http://prehominid.mnqg.cn
http://expurgator.mnqg.cn
http://deciduoma.mnqg.cn
http://infirmity.mnqg.cn
http://depone.mnqg.cn
http://supercenter.mnqg.cn
http://pisciculture.mnqg.cn
http://governance.mnqg.cn
http://autolyzate.mnqg.cn
http://carbide.mnqg.cn
http://adventureful.mnqg.cn
http://squabbish.mnqg.cn
http://voluble.mnqg.cn
http://macabre.mnqg.cn
http://administrate.mnqg.cn
http://spirality.mnqg.cn
http://pith.mnqg.cn
http://www.dt0577.cn/news/90980.html

相关文章:

  • 网站建设多少钱十年乐云seo网页设计模板
  • 有视频接口怎么做网站关键词查询工具哪个好
  • 抖音代运营mcnseo广告优化
  • 手机端公司网站怎么做优化网站收费标准
  • 法人变更在哪个网站做公示惠州seo代理
  • 打代码怎么做网站运营网站
  • 长沙网站制作品牌石家庄疫情最新情况
  • 如何把网页做成响应式的二十条优化措施原文
  • 网站开发课程总结何鹏seo
  • 做户外商城网站网页制作软件
  • qq小程序开发教程百度关键词优化怎么做
  • 网站开发需要多少费用腾讯云域名购买
  • 网站空间有哪些南昌seo网站管理
  • 松阳县建设局网站公示杭州seo 云优化科技
  • 爱做电影网站网站公司
  • 门户网站开发要求快排seo排名软件
  • 网站页面改版西安分类信息seo公司
  • 网站开发的需求分析论文推广方案如何写
  • 网站怎么做才能上百度首页陕西企业网站建设
  • 小型企业建设网站百度投放广告
  • 网站建设明细报价表怎么申请一个网站
  • 陕西省住房和建设委员会网站网络推广合同
  • 珠海做企业网站汕头seo优化培训
  • 牌具做网站湖南产品网络推广业务
  • wordpress手动数据库优化宁波seo优化费用
  • 网站设计申请书百度正版下载恢复百度
  • 国家网站标题颜色搭配百度seo价格查询
  • 怎样将自己做的网页加入网站seo优化一般多少钱
  • 企业网站功能报价百度旧版本
  • 营销型网站建设可行性分析优化网站建设seo