在Matlab中配置Biplot以区分散点图 [英] Configuring biplot in Matlab to distinguish in scatter

查看:251
本文介绍了在Matlab中配置Biplot以区分散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的原始data195x22记录集,其中包含对患有或未患有帕金森氏病的人的声音测量.在向量195x1中,我有一个status,它是1/0.

My original data is a 195x22 record set containing vocal measurements of people having Parkinson's disease or not. In a vector, 195x1, I have a status which is either 1/0.

现在,我已经执行了一次PCA,并且执行了biplot,结果很好.问题是,我无法从散点图中分辨出是健康人还是健康人的点(我无法将其与status链接).我希望散点图在健康的情况下(状态= 0)有一个红色的点,在生病的情况下(状态= 1)有一个绿色的点.

Now, I have performed a PCA and I do a biplot, which turns out well. The problem is that I can't tell which dots from my scatter plot origin of a sick or a healthy person (I can't link it with status). I would like for my scatter plot to have a red dot if healthy (status=0) and green if sick (status=1).

我该怎么做?我的双标代码是:

How would I do that? My biplot code is:

biplot(coeff(:,1:2), ...
    'Scores', score(:,1:2), ...
    'VarLabels', Labels, ...
    'markersize', 15 ...
);
xlabel('Bi-Plot: Standardized Data');
xlabel('PCA1');
ylabel('PCA2');

单击以查看图像

更新(解决方案):

解决方案的灵感来自@Magla,可在此处查看代码: http://pastebin.com/KHUj3DnA

Solution is inspired by @Magla and code can be seen here: http://pastebin.com/KHUj3DnA

有了这个漂亮的图:

推荐答案

biplot中的主成分分数(红点)不是pca函数返回的分数.如帮助所述,

The principal component scores (red points) in a biplot are not the ones returned by the pca function. As the help states,

biplot缩放分数,使它们适合该图:它将每个分数除以所有分数的最大绝对值,然后相乘 由系数的最大系数长度.然后biplot更改 得分坐标的符号根据符号约定 骨.

biplot scales the scores so that they fit on the plot: It divides each score by the maximum absolute value of all scores, and multiplies by the maximum coefficient length of coefs. Then biplot changes the sign of score coordinates according to the sign convention for the coefs.

因此,您不能轻松地使用(X,Y)信息来找出哪个点属于类别.

You therefore can't easily use the (X,Y) information to find out which point belong to a category.

这是使用biplotObsLabels选项的解决方法. ObsLabels为每个观察值分配一些用户定义的数据:对于每个点,我们将分配与status变量(一个简单的增量值)相对应的索引.这样,您可以轻松地修改biplot的红色点-在这里marker设置为正方形和红色/绿色.

Here is a workaround using the ObsLabels option of biplot. ObsLabels assigns some user-defined data to each observation: for each point, we will assign the index corresponding to a status variable (a simple incrementing value). With this, you can easily modify the red points of a biplot - here marker set to square and red/green color.

下图

是由此代码产生的

%some data
load carsmall
x = [Acceleration Displacement Horsepower MPG Weight]; x = x(all(~isnan(x),2),:);
[coefs,score] = pca(zscore(x));

%the status vector (here zero or one)
class_pt = round(rand(size(score,1),1));

vbls = {'Accel','Disp','HP','MPG','Wgt'};

figure('Color', 'w');
hbi = biplot(coefs(:,1:2),'scores',score(:,1:2),'varlabels',vbls,...
    'ObsLabels',num2str((1:size(score,1))'));

for ii = 1:length(hbi)
    userdata = get(hbi(ii), 'UserData');
    if ~isempty(userdata)
        if class_pt(userdata) == 0
            set(hbi(ii), 'Color', 'g', 'Marker', 's');

        elseif class_pt(userdata) == 1
            set(hbi(ii), 'Color', 'r', 'Marker', 's');
        end

    end
end

这篇关于在Matlab中配置Biplot以区分散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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