神经网络作业: NN LEARNING Coursera Machine Learning(Andrew Ng) WEEK 5
在WEEK 5中,作业要求完成通过神经网络(NN)实现多分类的逻辑回归(MULTI-CLASS LOGISTIC REGRESSION)的监督学习(SUOERVISED LEARNING)来识别阿拉伯数字。作业主要目的是感受如何在NN中求代价函数(COST FUNCTION)和其假设函数中各个参量(THETA)的求导值(GRADIENT DERIVATIVE)(利用BACKPROPAGGATION)。
难度不高,但问题是你要习惯使用MATLAB的矩阵QAQ,作为一名蒟蒻,我已经狗带了。以下代核心部分的代码希望给被作业卡住的同学一些帮助。但请不要照搬代码哦~不要~不要~
ty = zeros(m, num_labels); for i=:m
for j=:num_labels
if y(i)==j
ty(i,j) = ;
end
end
end a1 = X;
a1 = [ones(size(a1,),) a1];
z2 = a1 * Theta1';
a2 = sigmoid(z2);
a2 = [ones(size(a2,),) a2];
z3 = a2 * Theta2';
a3 = sigmoid(z3); for i=:m
for j=:num_labels
J = J - log(-a3(i,j))*(-ty(i,j))/m-log(a3(i,j))*ty(i,j)/m;
end
end %size(J,)
%size(J,) d3 = a3 - ty;
d2 = (d3 * Theta2(:,:end)).*sigmoidGradient(z2);
Theta1_grad = Theta1_grad + d2'*a1/m;
Theta2_grad = Theta2_grad + d3'*a2/m; % -------------------------------------------------------------
JJ=; for i=:size(Theta1,)
for j=:size(Theta1,)
JJ = JJ + Theta1(i,j)*Theta1(i,j)*lambda/(m*);
end
end
size(Theta1,);
size(Theta1,); for i=:size(Theta2,)
for j=:size(Theta2,)
JJ = JJ + Theta2(i,j)*Theta2(i,j)*lambda/(*m);
end
end
size(Theta2,);
size(Theta2,);
%J = J + (lambda/(*m)) * (Theta1(:,:end).*Theta1(:,:end)+Theta2(:end,:).*Theta2(:end,:));
J =J+JJ; Theta1_gradd = zeros(size(Theta1));
Theta2_gradd = zeros(size(Theta2)); for i=:size(Theta1,)
for j=:size(Theta1,)
Theta1_gradd(j,i) = Theta1(j,i)*lambda/m;
end
end for i=:size(Theta2,)
for j=:size(Theta2,)
Theta2_gradd(j,i) = Theta2(j,i)*lambda/m;
end
end Theta1_grad = Theta1_gradd+Theta1_grad;
Theta2_grad = Theta2_gradd+Theta2_grad;
PS:博主蒟蒻强迫自己下次要写矩阵运算,不能再套循环啦!!!
神经网络作业: NN LEARNING Coursera Machine Learning(Andrew Ng) WEEK 5的更多相关文章
- 《Learning scikit-learn Machine Learning in Python》chapter1
前言 由于实验原因,准备入坑 python 机器学习,而 python 机器学习常用的包就是 scikit-learn ,准备先了解一下这个工具.在这里搜了有 scikit-learn 关键字的书,找 ...
- Coursera, Machine Learning, notes
Basic theory (i) Supervised learning (parametric/non-parametric algorithms, support vector machine ...
- Machine Learning - 第6周(Advice for Applying Machine Learning、Machine Learning System Design)
In Week 6, you will be learning about systematically improving your learning algorithm. The videos f ...
- Machine Learning - XI. Machine Learning System Design机器学习系统的设计(Week 6)
http://blog.csdn.net/pipisorry/article/details/44119187 机器学习Machine Learning - Andrew NG courses学习笔记 ...
- Coursera machine learning 第二周 编程作业 Linear Regression
必做: [*] warmUpExercise.m - Simple example function in Octave/MATLAB[*] plotData.m - Function to disp ...
- Coursera Machine Learning 作业答案脚本 分享在github上
Github地址:https://github.com/edward0130/Coursera-ML
- Coursera machine learning 第二周 quiz 答案 Linear Regression with Multiple Variables
https://www.coursera.org/learn/machine-learning/exam/7pytE/linear-regression-with-multiple-variables ...
- 【Coursera - machine learning】 Linear regression with one variable-quiz
Question 1 Consider the problem of predicting how well a student does in her second year of college/ ...
- Coursera, Machine Learning, Anomoly Detection & Recommender system
Algorithm: When to select Anonaly detection or Supervised learning? 总的来说guideline是如果positive e ...
随机推荐
- Purpose of requirePermission attribute (web.config)
requirePermission 属性的含义 https://msdn.microsoft.com/en-us/library/system.configuration.sectioninforma ...
- express源码剖析--Router模块
1.加载模块执行代码: methods.forEach(function(method){ //method是http协议的各种请求方法,如:get,put,headee,post Route.pro ...
- Qt中如何固定窗口的大小?
这个是从网上转载过来的,我第一次看到的在如下网页:http://blog.csdn.net/cgb0210/article/details/5712980 这里我记录一下,留以后查阅. 一种方法是设 ...
- Entity Framewor 学习笔记 (include + where)
如果我们想在子查询做过滤的话应该怎样写呢? IEnumerable<Product> products = db.products.Include(p => p.colors.Whe ...
- 51单片机C语言学习笔记8:单片机C51编程规范
1.单片机C51编程规范- 前言 为了提高源程序的质量和可维护性,从而最终提高软件产品生产力,特编写此规范. 2.单片机C51编程规范-范围 本标准规定了程序设计人员进行程序设计时必须遵循的规范.本 ...
- Qt入门(6)——Qt的界面布局
Qt提供四种布局: VBoxLayout:垂直布局 HBoxLayout:水平布局 GridLayout:二维布局. FormLayout: 窗体布局
- 深入 JavaScript(6) - 一静一动
这里是JavaScript核心的内容了. 挺多的JavaScript测试题也是围绕这个出的. 这里的一静一动指的是: 静, 词法作用域 - Lexical scoping 动, 动态绑定this的值 ...
- Java---设计模块(值对象)
★ 场景和问题 在Java开发时,需要来回交换大量的数据,比如要为方法传入参数,也要获取方法的返回值,该如何能更好的进行数据的交互? ★ 基本的编写步骤 ◎第1步:写一个类,实现可序列化(如果以后数据 ...
- Android中程序包的相关操作
//获取系统中已经安装的应用程序 List<PackageInfo> packageinfos=this.getPackageManager().getInstalledPackages( ...
- Function对象
Function对象是js中很重要的一个元素,js中所有自定义的函数都是Function对象,所以String,Number,Boolean,function等都是Function对象.所以,在使用t ...