http://sbp810050504.blog.51cto.com/2799422/1608064/

http://blog.csdn.net/dongtingzhizi/article/details/15962797

http://blog.csdn.net/llp1992/article/details/45114421

https://www.qcloud.com/community/article/180954?fromSource=gwzcw.107192.107192.107192

梯度上升法求函数极值

 

来源: 运筹学第3版 胡运权 第3 节无约束极值问题的解法

梯度下降算法到logistic回归

 

 

logistic回归进行二分类

 梯度下降算法到logistic回归

 

 

梯度下降算法到logistic回归

 

 

梯度下降算法到logistic回归

 

 

function weight = gradAscent
clc
% close all
clear
%%

data = load('testSet.txt');
[row , col] = size(data);
dataMat = data(:,1:col-1);
dataMat = [ones(row,1) dataMat] ;
labelMat = data(:,col);
alpha = 0.001;
maxCycle = 500;
weight = ones(col,1);
for i = 1:maxCycle
    h = sigmoid(dataMat * weight);
    error = (labelMat - h);
    weight = weight + alpha * dataMat' * error;
end

figure
scatter(dataMat(find(labelMat(:) == 0),2),dataMat(find(labelMat(:) == 0),3),3);
hold on
scatter(dataMat(find(labelMat(:) == 1),2),dataMat(find(labelMat(:) == 1),3),5);
hold on
x = -3:0.1:3;
y = (-weight(1)-weight(2)*x)/weight(3);
plot(x,y)
hold off

end

function returnVals = sigmoid(inX)
    returnVals = 1.0./(1.0+exp(-inX));
end

 

相关文章:

  • 2021-11-27
  • 2021-05-31
  • 2021-08-21
  • 2021-07-22
  • 2021-08-21
  • 2021-11-27
  • 2021-07-20
猜你喜欢
  • 2022-12-23
  • 2021-05-24
  • 2021-05-23
  • 2021-10-22
  • 2021-11-27
  • 2021-11-06
  • 2022-01-05
相关资源
相似解决方案