Machine Learning 第三波编程作业 – Multi-class Classification and Neural Networks
2013-05-20 14:56
459 查看
仅列出核心代码:
1.lrCostFunction.m
课程地址:https://www.coursera.org/course/ml
1.lrCostFunction.m
h = sigmoid(X * theta); % h_theta(X) : m*1
% Cost func
J = (-log(h.')*y - log(ones(1, m) - h.')*(ones(m, 1) - y)) / m ...
+(lambda/(2*m)) * sum(theta(2:end).^2);
% Gradient
grad(1) = (X(:, 1).' * (h - y)) /m;
grad(2:end) = (X(:, 2:end).' * (h - y)) /m ...
+ (lambda/m) * theta(2:end);
2.oneVsAll.m% Cost func
J = (-log(h.')*y - log(ones(1, m) - h.')*(ones(m, 1) - y)) / m ...
+(lambda/(2*m)) * sum(theta(2:end).^2);
% Gradient
grad(1) = (X(:, 1).' * (h - y)) /m;
grad(2:end) = (X(:, 2:end).' * (h - y)) /m ...
+ (lambda/m) * theta(2:end);
options = optimset('GradObj', 'on', 'MaxIter', 50);
initial_theta = zeros(size(X, 2), 1);
for c = 1:num_labels
[all_theta(c, :)] = fmincg (@(t)(lrCostFunction(t, X, (y == c), lambda)),...
initial_theta, options);
end
3.predictOneVsAll.minitial_theta = zeros(size(X, 2), 1);
for c = 1:num_labels
[all_theta(c, :)] = fmincg (@(t)(lrCostFunction(t, X, (y == c), lambda)),...
initial_theta, options);
end
[~, p] = max(X * all_theta.', [], 2);
4.predict.m X = [ones(size(X), 1), X]; % Add ones to the X data matrix
X1 = sigmoid(X * Theta1.');
X1 = [ones(size(X1), 1), X1]; % Add ones to the X1 data matrix
[~, p] = max(X1 * Theta2.', [], 2);
X1 = sigmoid(X * Theta1.');
X1 = [ones(size(X1), 1), X1]; % Add ones to the X1 data matrix
[~, p] = max(X1 * Theta2.', [], 2);
课程地址:https://www.coursera.org/course/ml
相关文章推荐
- Andrew Ng机器学习编程作业:Multi-class Classification and Neural Networks
- [机器学习]week4编程作业:Multi-class Classification and Neural Networks
- Stanford 机器学习 Week4 作业 Multi-class Classification and Neural Networks
- 斯坦福机器学习实验之3-多分类和神经网络(Multi-class Classification and Neural Networks)
- Andrew NG 机器学习 练习3-Multiclass Classification and Neural Networks
- Stanford ex3: Multi-class Classification and Neural Networks
- Machine Learning week 4 quiz: programming assignment-Multi-class Classification and Neural Networks
- Andrew Ng 的 Machine Learning 课程学习 (week4) Multi-class Classification and Neural Networks
- Coursera Machine Learning 第四周 quiz Programming Exercise 3 Multi-class Classification and Neural
- Coursera Machine Learning 第四周week4编程 ex3Multi-class Classication and Neural Networks编程全套满分题目+注释
- Coursera-吴恩达-机器学习-(编程练习3)Neural Networks & Multi-class(对应第4周课程)
- Coursera 吴恩达 Deep Learning 第二课 改善神经网络 Improving Deep Neural Networks 第三周 编程作业代码 Tensorflow Tutorial
- 吴恩达deeplearning.ai课堂作业:Class 1 week4-Deep Neural Network for Image Classification
- 第四周编程作业(二)-Deep Neural Network for Image Classification: Application
- Coursera 吴恩达 Deep Learning 第2课 Improving Deep Neural Networks 第一周 编程作业代码 Gradient Checking
- CheeseZH: Stanford University: Machine Learning Ex3: Multiclass Logistic Regression and Neural Network Prediction
- Ranking with Recursive Neural Networks and Its Application to Multi-document Summarization
- Coursera 吴恩达 Deep Learning 第二课 改善神经网络 Improving Deep Neural Networks 第二周 编程作业代码Optimization methods
- Age and Gender Classification using Convolutional Neural Networks
- Multi-column deep neural networks for image classification阅读