神经网络作业: 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 ...
随机推荐
- PHP防止SQL注入的方法
[一.在服务器端配置] 安全,PHP代码编写是一方面,PHP的配置更是非常关键. 我们php手手工安装的,php的默认配置文件在 /usr/local/apache2/conf/php.ini,我们最 ...
- 修改浏览器的User-Agent来伪装你的浏览器和操作系统
近期很多文章都提到了User-Agent (UA) 字符串,但大部分网友都不知道这个东西有什么用处.其实简单的说User-Agent就是客户端浏览器等应用程序使用的一种特殊的网络协议,在每次浏览器(邮 ...
- WinForm------DateTime获取月第一天和最后一天取法
转载: http://blog.csdn.net/livening/article/details/6049341/ 代码: /// <summary> /// 取得某月的第一天 /// ...
- IDEA启动自动进入最后一个项目
每次打开IDEA的时候总会加载上级最后打开的工程,可能这个工程并不是我需要的,我就得重新去打开我需要的工程,感觉这一点非常鸡肋. 使用如下方法可以在启动的时候,选择启动哪个工程,而不是直接进入. Fi ...
- DbUtility-第一次接触
DbUtility这个以前就知道,可是由于底层是4.5的框架,我就一直没有仔细看过,最近自己的开发框架升级到了4.5,就开始学习这个组件. 总体来说,这个组件用起来非常简单.举例说明: await d ...
- 在VC中检测内存泄漏
声明:checkleaks.h和checkleaks.cpp这两个文件中的代码是在网上COPY的,但原来那个网站现在却找不到了 所以,这篇文章不算完全原创,呵呵. 就当作是一个存档吧 先上代码: // ...
- 强大疯狂的qttools
就是有点疑惑,为什么不整合到QT主项目中呢? 有空好好看看: https://github.com/qtproject/qttools/tree/dev/src ------------------- ...
- How to make vcredist_x86 reinstall only if not yet installed
Since you don't want to tell what minimal version of Visual C++ redistributable package you require, ...
- iOS 操作系统架构
Mac OS 和 iOS 操作系统架构 做iOS开发已经半年多了,但是感觉对iOS开发的理解却还只停留在表面,昨天刚把两个项目结了,今天打算学了一下iOS系统的架构,以便于更好的理解和开发. 首先看一 ...
- VS2010发布、打包安装程序
1. 在vs2010 选择“新建项目”→“ 其他项目类型”→“ Visual Studio Installer→“安装项目”: 命名为:Setup1 . 这是在VS2010中将有三个文件夹, 1.“应 ...