在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的更多相关文章

  1. 《Learning scikit-learn Machine Learning in Python》chapter1

    前言 由于实验原因,准备入坑 python 机器学习,而 python 机器学习常用的包就是 scikit-learn ,准备先了解一下这个工具.在这里搜了有 scikit-learn 关键字的书,找 ...

  2. Coursera, Machine Learning, notes

      Basic theory (i) Supervised learning (parametric/non-parametric algorithms, support vector machine ...

  3. 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 ...

  4. Machine Learning - XI. Machine Learning System Design机器学习系统的设计(Week 6)

    http://blog.csdn.net/pipisorry/article/details/44119187 机器学习Machine Learning - Andrew NG courses学习笔记 ...

  5. Coursera machine learning 第二周 编程作业 Linear Regression

    必做: [*] warmUpExercise.m - Simple example function in Octave/MATLAB[*] plotData.m - Function to disp ...

  6. Coursera Machine Learning 作业答案脚本 分享在github上

    Github地址:https://github.com/edward0130/Coursera-ML

  7. Coursera machine learning 第二周 quiz 答案 Linear Regression with Multiple Variables

    https://www.coursera.org/learn/machine-learning/exam/7pytE/linear-regression-with-multiple-variables ...

  8. 【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/ ...

  9. Coursera, Machine Learning, Anomoly Detection & Recommender system

      Algorithm:     When to select Anonaly detection or Supervised learning? 总的来说guideline是如果positive e ...

随机推荐

  1. 全排列算法之Perm算法实现

    题目描述:   给定一个由不同的小写字母组成的字符串,输出这个字符串的所有全排列.   我们假设对于小写字母有'a' < 'b' < … < 'y' < 'z',而且给定的字符 ...

  2. django初探

    如果是自己建站耍的话,还是用Php方便,毕竟Php服务器便宜又到处都是. 但是python毕竟是一个新鲜的东西,特别是django,以前一直东python的语法,而且是我最早学习的语言之一,但是一直停 ...

  3. 转:Durandal快速入门

    Durandal是一个轻量级的JavaScript框架,其目标是单页面应用(SPAs)的开发变得简单而优雅.它支持MVC.MVP和MVVM等模式,因此不论你采用哪种类型的前端架构,Durandal都能 ...

  4. Android 自定义View 画圆 画线

    自定义一个DrawCircle继承View 实现构造方法: public DrawCircle(Context context) { super(context); this.mContext = c ...

  5. 防止ajax非正常访问

    http://www.cnblogs.com/yagzh2000/archive/2013/06/09/3128042.html http://www.cnblogs.com/henw/archive ...

  6. ural 1020 Rope

    #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> # ...

  7. Powershell调用静态方法

    Powershell将信息存储在对象中,每个对象都会有一个具体的类型,简单的文本会以System.String类型存储,日期会以System.DateTime类型存储.任何.NET对象都可以通过Get ...

  8. 8.2.1.5 Engine Condition Pushdown Optimization 引擎条件下推优化

    8.2.1.5 Engine Condition Pushdown Optimization 引擎条件下推优化 这种优化改善了直接比较在一个非索引列和一个常量比较的效率. 在这种情况下, 条件是 下推 ...

  9. jsp中pageEncoding、charset=UTF -8

    jsp中pageEncoding.charset=UTF -8" 在JSP/Servlet  中主要有以下几个地方可以设置编码,pageEncoding="UTF-8". ...

  10. NCPC 2015 - Problem A - Adjoin the Networks

    题目链接 : http://codeforces.com/gym/100781/attachments 题意 : 有n个编号为0-n-1的点, 给出目前已经有的边(最多n-1条), 问如何添加最少的边 ...