绘制LDA的超平面(ClassificationDiscriminant) [英] Plotting the hyperplane of LDA (ClassificationDiscriminant)

查看:396
本文介绍了绘制LDA的超平面(ClassificationDiscriminant)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过肉眼研究分离超平面来比较我的数据上的各种分类器,例如LDA和SVM等.

I am trying to compare various classifiers on my data, such as LDA and SVM etc, by visually investigate the separation hyperplane.

当前,我使用的是CategoryDiscriminant作为LDA分类器,不像SVM可以在图形上绘制超平面,我找不到绘制LDA分类器超平面的方法.

Currently I am using ClassificationDiscriminant as the LDA classifier, unlike SVM can draw the hyperplane on the graph, I could not find a way to plot the hyperplane of the LDA classifier.

以下脚本是我如何生成示例数据并使用分类判别对其进行分类的方法:

The following script is how I produce a sample data and get it been classified using ClassificationDiscriminant:

%% Data & Label
X = [randn(100,2); randn(150,2) + 1.5];
Y = [zeros(100,1); ones(150,1)];
%% Plot
gscatter(X(:,1),X(:,2),Y);
%% Train LDA Classifier
C = ClassificationDiscriminant.fit(X,Y);

任何人都可以帮助我绘制与C分离的超平面吗?任何建议都会有很大帮助.

Can anyone please help me to plot the hyperplane of separation from C? Any suggestion would be great help.

此外,上面的示例是2D格式的,但是,我也有兴趣以3D格式绘制它们(即示例数据X具有三列).如果可以的话,那就更好了.

Furthermore, the sample above is in 2D, however, I'm also interested in plotting them in 3D (i.e. sample data X has three columns). It would be more great if you can help.

推荐答案

从Matlab classify()文档中的示例中浏览:

Borrowing from the example in Matlab's classify() documentation:

Class1 = 1;
Class2 = 2;
K = C.Coeffs(Class1,Class2).Const;
L = C.Coeffs(Class1,Class2).Linear;
f = @(x,y) K + [x y]*L;

hold on;
ezplot(f, [min(X(:,1)) max(X(:,1)) min(X(:,2)) max(X(:,2))]);

请注意,上面的示例绘制了二维空间中两个类之间的成对边界.如果还有其他类,则必须适当修改Class1Class2.我敢肯定,通过一些额外的工作,您可以找到该函数到N维空间的扩展.

Note that the above example plots the pairwise boundary between two classes in 2 dimensional space. If you have additional classes, you will have to modify Class1 and Class2 appropriately. I'm sure with some additional work you can find an extension of this function to N dimensional space.

这篇关于绘制LDA的超平面(ClassificationDiscriminant)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆