本小节使用前馈神经网络对上小节的5000个手写体进行识别。
1、神经网络模型
使用的前馈型神经网络有3层:一个输入层、一个隐藏层和一个输出层。
每个手写体的大小为20×20,因此设计输入层单元数为400(除去额外基本单元1个),输出层为10(对应10个数字1-10)。设计隐藏层的单元数为25。
其神经网络的模型如下:

程序已经给定了训练得到的权重参数theta,存储在ex3data1.mat中。
其中theta1表示从第1层到第2层的权重矩阵,其维度为25×401。theta2表示从第2层到第3层的权重矩阵,其维度为10×26。
2、前馈传播和预测
设置神经网络每一层的数量

%% Setup the parameters you will use for this exercise
input_layer_size  = 400;  % 20x20 Input Images of Digits
hidden_layer_size = 25;   % 25 hidden units
num_labels = 10;          % 10 labels, from 1 to 10   % (note that we have mapped "0" to label 10)
load('ex3data1.mat');%导入手写样本数据
m = size(X, 1);%m为样本数量


其中样本数据中X表示为5000个样本,每个样本有400维特征值,y值为每个样本对应的标签值。
导入已经训练好的神经网络权重参数:

% Load the weights into variables Theta1 and Theta2
load('ex3weights.mat');


根据神经网络模型完成预测函数p = predict(Theta1, Theta2, X):

function p = predict(Theta1, Theta2, X)% Useful values
m = size(X, 1);
num_labels = size(Theta2, 1);% You need to return the following variables correctly
p = zeros(size(X, 1), 1);a1 = [ones(m,1) X];
z2 = a1*Theta1';
a2 = [ones(m,1) sigmoid(z2)];
z3 = a2*Theta2';
a3 = sigmoid(z3);A = a3;
[max_A,p] = max(A, [], 2);end

运行程序,得到其训练的准确度为97.52%

Training Set Accuracy: 97.520000
Program paused. Press enter to continue.

继续运行程序,随机选取手写图片进行预测。

Displaying Example ImageNeural Network Prediction: 8 (digit 8)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 8 (digit 8)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 2 (digit 2)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 6 (digit 6)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 10 (digit 0)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 6 (digit 6)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 2 (digit 2)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 10 (digit 0)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 5 (digit 5)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 5 (digit 5)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 9 (digit 9)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 6 (digit 6)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 5 (digit 5)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 6 (digit 6)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 8 (digit 8)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 1 (digit 1)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 2 (digit 2)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 1 (digit 1)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 5 (digit 5)
Paused - press enter to continue, q to exit:Displaying Example ImageNeural Network Prediction: 10 (digit 0)
Paused - press enter to continue, q to exit:

吴恩达机器学习练习3:Logistic regression(Feedforward propagation neural networks)相关推荐

  1. 吴恩达机器学习 -- 逻辑回归(Logistic Regression)

    7.1  分类问题 如果要预测的变量 是离散值,此时我们应用 logistics regression. 在分类问题中,我们对某一事物进行分类,有二分类和多分类问题.此节先讨论二分类问题,即只有两个分 ...

  2. 吴恩达深度学习笔记——卷积神经网络(Convolutional Neural Networks)

    深度学习笔记导航 前言 传送门 卷积神经网络(Convolutional Neural Networks) 卷积神经网络基础(Foundations of Convolutional Neural N ...

  3. 吴恩达机器学习笔记 —— 7 Logistic回归

    http://www.cnblogs.com/xing901022/p/9332529.html 本章主要讲解了逻辑回归相关的问题,比如什么是分类?逻辑回归如何定义损失函数?逻辑回归如何求最优解?如何 ...

  4. 吴恩达机器学习作业5---Regularized Linear Regression and Bias vs. Variance

    Regularized Linear Regression and Bias vs.Variance 文章目录 Regularized Linear Regression and Bias vs.Va ...

  5. 吴恩达深度学习2.1练习_Improving Deep Neural Networks(Initialization_Regularization_Gradientchecking)

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/weixin_42432468 学习心得: 1.每周的视频课程看一到两遍 2.做笔记 3.做每周的作业 ...

  6. 吴恩达机器学习作业Python实现(二):logistic回归

    吴恩达机器学习系列作业目录 1 Logistic regression 在这部分的练习中,你将建立一个逻辑回归模型来预测一个学生是否能进入大学.假设你是一所大学的行政管理人员,你想根据两门考试的结果, ...

  7. 吴恩达机器学习课后作业1——单变量线性回归(Linear regression with one variable)

    1. 问题和数据 假设你是一家连锁餐车店的老板,但是你又和别的土老板不一样,你又刚好是个懂线性回归,还懂编程的老板,正在考虑在不同的城市开一家新店.该连锁店已经在各个城市开设了餐车,你可以获得这些城市 ...

  8. 吴恩达机器学习课后作业1.1——多变量线性回归(Linear regression with multiple variable)

    1. 问题和数据 假设你要卖掉你的房子,你想知道一个好的市场价格是多少.其中一种方法是,首先收集最近出售的房屋的信息.在本部分的练习中,你将使用多元线性回归来预测房屋价格. 数据ex1data2.tx ...

  9. 带你少走弯路:五篇文章学完吴恩达机器学习

    本文是吴恩达老师的机器学习课程[1]的笔记和代码复现部分,这门课是经典,没有之一.但是有个问题,就是内容较多,有些内容确实有点过时. 如何在最短时间学完这门课程?作为课程的主要翻译者和笔记作者,我推荐 ...

最新文章

  1. python向端口发出数据_Python写的简单的端口监听,显示端口上收到的数据,TCP的...
  2. 河北大学工商学院计算机分数线,河北大学工商学院录取分数线()
  3. mysql简单的命令centos版
  4. Thymeleaf前后端传值 页面取值与js取值
  5. 倒置链表(递归方式)
  6. CodeForces 621C Wet Shark and Flowers
  7. 计算机组成原理讲义 微盘,计算机组成原理课件.pdf
  8. 树莓派如何接硬盘_利用树莓派和闲置硬盘,搭建起家中的个人网盘
  9. 电脑连无线无法访问云服务器,小编教你如何解决电脑无法连接无线网络
  10. 使用OpenVINO实现飞桨版PGNet推理程序
  11. 内网渗透-PTHPTTPTK
  12. 电脑键盘出现计算机,技巧:如何恢复计算机键盘上的乱码[设置方法]
  13. 2022红帽RHCSA考题解析
  14. 泰山OFFICE技术讲座:全网首发:中文字体,字号就是中文字符的宽度
  15. 一文看懂Java设计模式
  16. it转正述职报告_IT试用期转正工作总结
  17. 技术小品文(一)字符串放在哪里?
  18. 计算机学家名言 英语,科学家英语名言
  19. renderdoc的使用
  20. 【愚公系列】2022年10月 微信小程序-电商项目-微信支付后端功能实现(node版)

热门文章

  1. android 线程安全
  2. Hibernate缓存-使用Ehcache让实体对象集合对象缓存
  3. 编码 GBK 的不可映射字符
  4. .NET环境下几种不同的邮件发送解决方案
  5. 测开5 - Python(模块、操作数据库、操作Excel、加密)
  6. 广实1592: 1.6-06:校门外的树
  7. RK3288 制作内核开机logo
  8. SSIS [大容量插入任务] 找不到文件错误
  9. 注解描述(持续更新)
  10. Android——继续深造——从安装Android Studio 2.0开始(详)