Exercise:Softmax Regression 代码示例
Exercise:Softmax Regression 代码示例
softmaxCost.m 中加入代码:
M = theta*data;
M = exp(bsxfun(@minus, M, max(M, [], 1)));
P = bsxfun(@rdivide, M, sum(M));
M = log(P);
WD = lambda / 2 * sum(sum(theta.^2));
cost = -sum(sum(groundTruth.*M)) / size(M,2) + WD;
thetagrad = -(groundTruth - P) * data' ./ size(data,2) + lambda.*theta;
softmaxPredict.m中加入代码:
m = theta * data;
[~,pred] = max(m);
softmaxExercise.m中设置DEBUG为false,运行。