Exercise:Softmax Regression 代码示例

练习参考Softmax Regression

 

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,运行。

相关文章:

  • 2022-01-19
  • 2021-11-30
  • 2022-02-11
  • 2022-03-05
  • 2021-10-15
  • 2021-06-19
  • 2021-11-13
  • 2022-01-10
猜你喜欢
  • 2021-08-31
  • 2021-07-15
  • 2021-04-05
  • 2022-01-15
  • 2021-04-25
  • 2021-07-15
相关资源
相似解决方案