【Matlab开发】matlab中bar绘图设置与各种距离度量
标签(空格分隔): 【Matlab开发】 【机器学习】
Matlab Bar图如何为每个bar设置不同颜色
data = [3, 7, 5, 2;4, 3, 2, 9;6, 6, 1, 4];
b = bar(data);
使用bar绘制非常直观简单,但有时需要突出显示某一个bar,比如该bar是一个标杆,用来衡量其bar的高度,所以可以用醒目的红色来显示它。那么如何设置呢?
参看下面的代码:
data = [3, 7, 5, 2;4, 3, 2, 9;6, 6, 1, 4];
b = bar(data);
ch = get(b,‘children‘);
set(ch{1},‘FaceVertexCData‘,[1;1;1;1;2;2;2;2;3;3;3;3;4;4;4;4])
set(ch{2},‘FaceVertexCData‘,[1;1;1;1;2;2;2;2;3;3;3;3;4;4;4;4])
set(ch{3},‘FaceVertexCData‘,[1;1;1;1;2;2;2;2;3;3;3;3;4;4;4;4])
set(ch{4},‘FaceVertexCData‘,[1;1;1;1;2;2;2;2;3;3;3;3;4;4;4;4])
data = [3, 7, 5, 2];
b = bar(data);
ch = get(b,‘children‘);
set(ch,‘FaceVertexCData‘,[0 0 1;0 1 1;1 1 1;1 0 1;])
matlab中用于求取各种距离的函数pdist方法的使用
引言说明
在机器学习和数据挖掘中,我们经常需要知道个体间差异的大小,进而评价个体的相似性和类别。最常见的是数据分析中的相关分析,数据挖掘中的分类和聚 类算法,如 K 最近邻(KNN)和 K 均值(K-Means)等等。根据数据特性的不同,可以采用不同的度量方法。一般而言,定义一个距离函数 d(x,y), 需要满足下面几个准则:
(1) d(x,x) = 0 // 到自己的距离为0
(2) d(x,y) >= 0 // 距离非负
(3) d(x,y) = d(y,x) // 对称性: 如果 A 到 B 距离是a,那么 B 到 A 的距离也应该是 a
(4) d(x,k)+ d(k,y) >= d(x,y) // 三角形法则:(两边之和大于第三边)
本节首先介绍一下matlab中用于求取各种距离的函数pdist方法的使用
matlab中用于求取各种距离的函数pdist方法的使用
下面是help出来的帮助信息:
help pdist
pdist Pairwise distance between observations.
D = pdist(X) returns a vector D containing the Euclidean distances
between each pair of observations in the M-by-N data matrix X. Rows of
X correspond to observations, columns correspond to variables. D is a
1-by-(M*(M-1)/2) row vector, corresponding to the M*(M-1)/2 pairs of
observations in X.
D = pdist(X, DISTANCE) computes D using DISTANCE. Choices are:
‘euclidean‘ - Euclidean distance (default)
‘seuclidean‘ - Standardized Euclidean distance. Each coordinate
difference between rows in X is scaled by dividing
by the corresponding element of the standard
deviation S=NANSTD(X). To specify another value for
S, use D=pdist(X,‘seuclidean‘,S).
‘cityblock‘ - City Block distance
‘minkowski‘ - Minkowski distance. The default exponent is 2. To
specify a different exponent, use
D = pdist(X,‘minkowski‘,P), where the exponent P is
a scalar positive value.
‘chebychev‘ - Chebychev distance (maximum coordinate difference)
<