私は大規模なデータセットで線形SVMを実行しましたが、コンポーネントスコアの一部でSVMを実行した場合(分散の99.5%を説明した最初の650コンポーネント)。今、PCA空間で作成されたSVMからのベータウェイトとバイアスを使って、元の変数空間に決定境界をプロットしたいと思います。しかし、私はどのようにバイアス用語をSVMから元の変数空間に投影するかを理解することはできません。私が説明するためにフィッシャーのアイリスデータを使用してデモを書いた:MatlabのPCAの後に線形SVMから決定境界をプロットする方法はありますか?
clear; clc; close all
% load data
load fisheriris
inds = ~strcmp(species,'setosa');
X = meas(inds,3:4);
Y = species(inds);
mu = mean(X)
% perform the PCA
[eigenvectors, scores] = pca(X);
% train the svm
SVMModel = fitcsvm(scores,Y);
% plot the result
figure(1)
gscatter(scores(:,1),scores(:,2),Y,'rgb','osd')
title('PCA space')
% now plot the decision boundary
betas = SVMModel.Beta;
m = -betas(1)/betas(2); % my gradient
b = -SVMModel.Bias; % my y-intercept
f = @(x) m.*x + b; % my linear equation
hold on
fplot(f,'k')
hold off
axis equal
xlim([-1.5 2.5])
ylim([-2 2])
% inverse transform the PCA
Xhat = scores * eigenvectors';
Xhat = bsxfun(@plus, Xhat, mu);
% plot the result
figure(2)
hold on
gscatter(Xhat(:,1),Xhat(:,2),Y,'rgb','osd')
% and the decision boundary
betaHat = betas' * eigenvectors';
mHat = -betaHat(1)/betaHat(2);
bHat = b * eigenvectors';
bHat = bHat + mu; % I know I have to add mu somewhere...
bHat = bHat/betaHat(2);
bHat = sum(sum(bHat)); % sum to reduce the matrix to a single value
% the correct value of bHat should be 6.3962
f = @(x) mHat.*x + bHat;
fplot(f,'k')
hold off
axis equal
title('Recovered feature space')
xlim([3 7])
ylim([0 4])
私が間違ってBHATを計算しています方法上の任意のガイダンスははるかに高く評価されるだろう。
正しいy切片は 'b = -SVMModel.Bias/betas(2)'です。 –