2014-09-30 86 views

回答

4

在用于二元分类逻辑回归,分类为0或1的新样品x的概率是:

enter image description here

因此,判定边界对应于行,其中P(y=1|x)=P(y=0|x)=sigmoid(theta'*x)=0.5,其对应于theta'*x=0 。 sigmoid函数是sigmoid = @(z) 1.0 ./ (1.0 + exp(-z))

enter image description here

在我们的情况下,该数据具有两个维度加偏压,因此:

enter image description here

例如,在范围与x1决策边界[-1 1]可以可表示为:

theta = [-0.34, -4.5, 0.5]; 
sigmoid = @(z) 1.0 ./ (1.0 + exp(-z)); 

% Random points 
N = 100; 
X1 = 2*rand(N,1)-1; 
X2 = 20*rand(N,1)-10; 
x = [ones(N,1), X1(:), X2(:)]; 
y = sigmoid(theta * x.') > 0.5; 

% Boundary line 
plot_x = [-1 1]; 
plot_y = (-1./theta(3)).*(theta(2).*plot_x + theta(1)); 

% Plot 
figure; 
hold on; 
scatter(X1(y==1),X2(y==1),'bo'); 
scatter(X1(y==0),X2(y==0),'rx'); 
plot(plot_x, plot_y, 'k--'); 
hold off 
xlabel('x1'); ylabel('x2'); 
title('x_{2} = 0.68 + 9 x_{1}'); 
axis([-1 1 -10 10]); 

它生成以下图表:

enter image description here

+1

OP的θ是从逻辑回归中获得的。你提到的文章是关于线性回归的。这里有什么缺失吗? – greeness 2014-09-30 20:52:20

+0

你是完全正确的!我没有意识到我的错误。我纠正了错误。 – tashuhka 2014-09-30 20:58:51

+0

看起来不错。所以实际上在边界上:“斜率= theta(2)/( - theta(3))= 9'和'intercept = theta(1)/( - theta(3))= 0.68'。边界因此是'y = 9x + 0.68'。 – greeness 2014-09-30 21:51:25