在Matlab中配置Biplot以区分散点图 [英] Configuring biplot in Matlab to distinguish in scatter
问题描述
我的原始data
是195x22
记录集,其中包含对患有或未患有帕金森氏病的人的声音测量.在向量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.
这是使用biplot
的ObsLabels
选项的解决方法. 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屋!