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

腾冲做兼职的网站网页制作和网页制作技术

腾冲做兼职的网站,网页制作和网页制作技术,ssc网站建设,开发购物平台网站费用摘要#xff1a; 本文以Python代码完成整个鸾尾花图像分类任务#xff0c;没有调用任何的数据包#xff0c;适合新手阅读理解#xff0c;并动手实践体验下机器学习方法的大致流程。 尝试使用过各大公司推出的植物识别APP吗#xff1f;比如微软识花、花伴侣等这些APP。当你…摘要 本文以Python代码完成整个鸾尾花图像分类任务没有调用任何的数据包适合新手阅读理解并动手实践体验下机器学习方法的大致流程。 尝试使用过各大公司推出的植物识别APP吗比如微软识花、花伴侣等这些APP。当你看到一朵不知道学名的花时只需要打开植物识别APP拍摄一张你所想辨认的植物照片并上传APP会自动识别出该花的品种及详细介绍感觉手机中装了一个知识渊博的生物学家是不是很神奇其实背后的原理很简单是一个图像分类的过程将上传的图像与手机中预存的数据集或联网数据进行匹配将其分类到对应的类别即可。随着深度学习方法的应用图像分类的精度越来越高在部分数据集上已经超越了人眼的能力。        相对于传统神经网络的方法而言深度学习方法一般对数据集规模、硬件平台有着比较高的要求如果只是单纯的想尝试了解图像分类任务的基本流程建议采用小数据集样本及传统的神经网络方法实现。本文将带领读者采用鸢尾属植物数据集Iris Data Set来实现一个分类任务整个鸢尾属植物数据集是机器学习中历史悠久的数据集比现在常用的数字手写体数据集Mnist Data Set数据集还要早得多该数据集来源于英国著名的统计学家、生物学家Ronald Fiser。本文在不使用相关软件库的情况下从头开始构建针对鸢尾属植物数据的神经网络模型对其进行训练并获得好的结果。 鸢尾属植物数据集是用于测试机器学习算法的最常用数据集。该数据包含四种特征萼片长度、萼片宽度、花瓣长度和花瓣宽度用于鸢尾属植物的不同物种versicolor, virginica和setosa。此外每个物种有50个实例数据行下面让我们看看样本数据分布情况。 我们将在这个数据集上使用神经网络构建分类模型。为了简单起见使用花瓣长度和花瓣宽度作为特征且只有两类物种versicolor和virginica。下面就让我们在Python中逐步训练针对该样本数据集的神经网络 步骤1准备鸢尾属植物数据集 将Iris数据集导入python并对数据进行子集划分以保留行之间的相关性 #import libraries import os import pandas as pd #Set working directory and load data os.chdir(C:\\Users\\rohan\\Documents\\Analytics\\Data) iris pd.read_csv(iris.csv) #Create numeric classes for species (0,1,2) iris.loc[iris[Name]virginica,species]0 iris.loc[iris[Name]versicolor,species]1 iris.loc[iris[Name]setosa,species] 2 iris iris[iris[species]!2] #Create Input and Output columns X iris[[PetalLength, PetalWidth]].values.T Y iris[[species]].values.T Y Y.astype(uint8) #Make a scatter plot plt.scatter(X[0, :], X[1, :], cY[0,:], s40, cmapplt.cm.Spectral); plt.title(IRIS DATA | Blue - Versicolor, Red - Virginica ) plt.xlabel(Petal Length) plt.ylabel(Petal Width) plt.show() 蓝色点代表Versicolor物种红色点代表Virginica物种。本文构建的神经网络将在这些数据上进行训练以期最后能正确地分类物种。 步骤2初始化参数权重和偏置 下面构建一个具有单个隐藏层的神经网络。此外将隐藏图层的大小设置为6 def initialize_parameters(n_x, n_h, n_y):np.random.seed(2) # we set up a seed so that our output matches ours although the initialization is random.W1 np.random.randn(n_h, n_x) * 0.01 #weight matrix of shape (n_h, n_x)b1 np.zeros(shape(n_h, 1)) #bias vector of shape (n_h, 1)W2 np.random.randn(n_y, n_h) * 0.01 #weight matrix of shape (n_y, n_h)b2 np.zeros(shape(n_y, 1)) #bias vector of shape (n_y, 1)#store parameters into a dictionary parameters {W1: W1,b1: b1,W2: W2,b2: b2}return parameters 步骤3前向传播forward propagation 在前向传播过程中使用tanh激活函数作为第一层的激活函数使用sigmoid激活函数作为第二层的激活函数 def forward_propagation(X, parameters): #retrieve intialized parameters from dictionary W1 parameters[W1]b1 parameters[b1]W2 parameters[W2]b2 parameters[b2]# Implement Forward Propagation to calculate A2 (probability)Z1 np.dot(W1, X) b1A1 np.tanh(Z1) #tanh activation functionZ2 np.dot(W2, A1) b2A2 1/(1np.exp(-Z2)) #sigmoid activation functioncache {Z1: Z1,A1: A1,Z2: Z2,A2: A2}return A2, cache 步骤4计算代价函数cost function 目标是使得计算的代价函数小化本文采用交叉熵cross-entropy作为代价函数 def compute_cost(A2, Y, parameters):m Y.shape[1] # number of training examples# Retrieve W1 and W2 from parametersW1 parameters[W1]W2 parameters[W2]# Compute the cross-entropy costlogprobs np.multiply(np.log(A2), Y) np.multiply((1 - Y), np.log(1 - A2))cost - np.sum(logprobs) / mreturn cost 步骤5反向传播back propagation 计算反向传播过程主要是计算代价函数的导数 def backward_propagation(parameters, cache, X, Y): # Number of training examplesm X.shape[1]# First, retrieve W1 and W2 from the dictionary parameters. W1 parameters[W1]W2 parameters[W2]### END CODE HERE #### Retrieve A1 and A2 from dictionary cache.A1 cache[A1]A2 cache[A2]# Backward propagation: calculate dW1, db1, dW2, db2. dZ2 A2 - YdW2 (1 / m) * np.dot(dZ2, A1.T)db2 (1 / m) * np.sum(dZ2, axis1, keepdimsTrue)dZ1 np.multiply(np.dot(W2.T, dZ2), 1 - np.power(A1, 2))dW1 (1 / m) * np.dot(dZ1, X.T)db1 (1 / m) * np.sum(dZ1, axis1, keepdimsTrue) grads {dW1: dW1,db1: db1,dW2: dW2,db2: db2}return grads步骤6更新参数 使用反向传播过程中计算的梯度来更新权重和偏置 def update_parameters(parameters, grads, learning_rate1.2): # Retrieve each parameter from the dictionary parameters W1 parameters[W1]b1 parameters[b1]W2 parameters[W2]b2 parameters[b2]# Retrieve each gradient from the dictionary gradsdW1 grads[dW1]db1 grads[db1]dW2 grads[dW2]db2 grads[db2]# Update rule for each parameterW1 W1 - learning_rate * dW1b1 b1 - learning_rate * db1W2 W2 - learning_rate * dW2b2 b2 - learning_rate * db2parameters {W1: W1,b1: b1,W2: W2,b2: b2}return parameters 步骤7建立神经网络 将以上所有函数组合起来以创建设计的神经网络模型。总而言之下面是模型函数的整体顺序 初始化参数前向传播计算代价函数反向传播更新参数 def nn_model(X, Y, n_h, num_iterations10000, print_costFalse): np.random.seed(3)n_x layer_sizes(X, Y)[0]n_y layer_sizes(X, Y)[2]# Initialize parameters, then retrieve W1, b1, W2, b2. Inputs: n_x, n_h, n_y. Outputs W1, b1, W2, b2, parameters. parameters initialize_parameters(n_x, n_h, n_y)W1 parameters[W1]b1 parameters[b1]W2 parameters[W2]b2 parameters[b2]# Loop (gradient descent) for i in range(0, num_iterations):# Forward propagation. Inputs: X, parameters. Outputs: A2, cache.A2, cache forward_propagation(X, parameters)# Cost function. Inputs: A2, Y, parameters. Outputs: cost.cost compute_cost(A2, Y, parameters)# Backpropagation. Inputs: parameters, cache, X, Y. Outputs: grads.grads backward_propagation(parameters, cache, X, Y)# Gradient descent parameter update. Inputs: parameters, grads. Outputs: parameters.parameters update_parameters(parameters, grads)### END CODE HERE #### Print the cost every 1000 iterationsif print_cost and i % 1000 0:print (Cost after iteration %i: %f % (i, cost)) return parameters,n_h 步骤8跑动模型 将隐藏层节点设置为6最大迭代次数设置为10,000次并每隔1000次打印出训练的结果 parameters nn_model(X,Y , n_h 6, num_iterations10000, print_costTrue) 步骤9画出分类边界 def plot_decision_boundary(model, X, y):# Set min and max values and give it some paddingx_min, x_max X[0, :].min() - 0.25, X[0, :].max() 0.25y_min, y_max X[1, :].min() - 0.25, X[1, :].max() 0.25h 0.01# Generate a grid of points with distance h between themxx, yy np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))# Predict the function value for the whole gridZ model(np.c_[xx.ravel(), yy.ravel()])Z Z.reshape(xx.shape)# Plot the contour and training examplesplt.contourf(xx, yy, Z, cmapplt.cm.Spectral)plt.ylabel(x2)plt.xlabel(x1)plt.scatter(X[0, :], X[1, :], cy, cmapplt.cm.Spectral) plot_decision_boundary(lambda x: predict(parameters, x.T), X, Y[0,:]) plt.title(Decision Boundary for hidden layer size str(6)) plt.xlabel(Petal Length) plt.ylabel(Petal Width) 从图中可以观察到只有四个点被错误分类。虽然我们可以调整模型来进一步地提高模型训练精度但该些操作显然会导致过拟合现象的出现。 资源 https://www.coursera.org/specializations/deep-learning 数十款阿里云产品限时折扣中赶紧点击领劵开始云上实践吧 作者信息 Rohan Joseph数据科学家 个人主页https://www.linkedin.com/in/rohan-joseph-b39a86aa/ 本文由阿里云云栖社区组织翻译。 文章原标题《Neural network on iris data》译者海棠审校Uncle_LLD。 文章为简译更为详细的内容请查看原文。 原文链接
http://www.huolong8.cn/news/153534/

相关文章:

  • 企业做自己的网站要注意什么国外贸易平台
  • 网站收录不好unity游戏制作软件
  • sdcms网站建设模板建设电子商务网站需要什么
  • 网站首页建设建议泰州做兼职的网站
  • 做网站模板的海报尺寸多少找外贸客户的联系方式软件
  • 群推广网站简要说明网站建设的步骤
  • 做网站利润安徽建设信息网站
  • 沈阳做网站一诚金网络专业给个网站你们会感谢我的
  • 购物网站功能设计郑州seo询搜点网络效果佳
  • 做php网站时如何建立数据库广州建设网站的公司简介
  • 德阳建设厅官方网站找百度公司做网站怎么样
  • 南京市城乡建设局网站沈阳网站制作网页
  • 网站建设如何定位石家庄营销网站建设多少钱
  • 如何关闭网站国内主要的o2o电商平台
  • 怎么寻找做有意做网站的客户国模 wordpress
  • 免费建网站的作用深圳定制衣柜厂家
  • 温州快建网站建设网站优化外链
  • 曲靖做网站建设的公司爬闪数媒 网站建设
  • 理财平台网站建设wordpress直达链接404
  • 深圳网站建设小江物流相关网站
  • 免费做网页的网站网站系统问题解决措施
  • 生鲜农产品网站建设温州网站优化指导
  • 横峰县建设局网站网站后台 批量上传
  • 织梦添加网站名称添加新变量wordpress如何配置前端用户中心
  • 用html5做的网站源码杭州哪些做网站公司好
  • 遵义网站制作一般多少钱网站seo新手
  • 宁波外贸网站制作公司wordpress dux搜索无法使用
  • wordpress网站360搜索收录安徽六安有哪些区县
  • 旅游网站建设多少钱做监控的有哪些网站
  • 濮阳网站怎么做seo做海报一般都去什么网站看