2017-02-26 54 views
0

plotted two different dataset如何在MATLAB

繪製線性決策邊界我有2個不同的數據集具有不同的mu和sigma,和X載體如[1.8; 1.8。而且我也知道每個類的概率P(ω1)= P(ω2)= 1/2 我想繪製這兩個數據集之間的線性決策邊界,但我沒有任何想法必須做。我的代碼是下面,這裏

X = [1.8; 1.8]; 
u1 = [1;1]; u2 = [3;3]; 
s1 = [1 0;0 1]; s2 = [1 0;0 1]; 
Pr1 = 1/2; 
Pr2 = 1/2; 

r = mvnrnd(u1,s1,500); 
plot(r(:,1), r(:,2), '+r'); 
hold on 

r = mvnrnd(u2,s2,500); 
plot(r(:,1), r(:,2), '+b'); 
hold on 
grid on 

W1 = (u1')/(s1(1,1))^2; 
W10 = (u1'*u1)/(-2*s1(1,1)) + log(Pr1); 
g1 = W1'.*X + W10; 

W2 = (u2')/(s2(1,1))^2; 
W20 = (u2'*u2)/(-2*s2(1,1)) + log(Pr2); 
g2 = W2'.*X + W20; 

有沒有人可以給我任何想法給我?

回答

0

我解決決策問題,在詳細

首先,我到繪圖決策邊界定義的參數x1和x2參數函數,以便如

g = @(x1,x2) 

然後意識到,G1-G2 = 0方程這樣作爲

e = @(x1,x2) (W1*[x1;x2] + w10 - W2*[x1;x2] - w20) 
ezplot(g, [-xlim xlim -ylim ylim]) 

,做

0

訣竅是計算你想繪製的兩個決定邊界點。

W1_W2 = W2 - W1; % vector from W1 to W2 
W1_W2_average = (W2 + W1)/2; % point in the middle between W1 and W2 
W1_W2_orthogonal = [-W1_W2(2) W1_W2(1)]; % vector orthogonal to W1_W2 
points = [W1_W2_average - 2*W1_W2_orthogonal; W1_W2_average + 2*W1_W2_orthogonal]; % Two points on the line you want to plot 
plot(points(:, 1), points(:, 2)); %plot the line 

請注意,我不是很熟悉分類問題。我可能在計算決策邊界時忘記了一些術語。