UFLDL Exercise:Softmax Regression

来源:互联网 发布:淘宝网家居拖鞋 编辑:程序博客网 时间:2024/05/20 20:02

1. result

Gradient checking: 7.4115e-010
Accuracy: 92.640%

2. code

softmaxCost

%hypothesisM = theta * data;M = exp(bsxfun(@minus, M, max(M)));M = bsxfun(@rdivide, M, sum(M));%costcost = -sum(sum(groundTruth .* log(M))) / size(data, 2);cost = cost + 0.5 * lambda * sum(sum(theta .* theta));%gradthetagrad = -(groundTruth - M) * data' / size(data, 2)';thetagrad = thetagrad + lambda * theta;

softmaxPredict

M = theta * data;[M, pred] = max(M);
0 0
原创粉丝点击