rank features for unsupervised learning using laplacian scores -凯发k8网页登录
rank features for unsupervised learning using laplacian scores
since r2019b
description
ranks features (variables) in idx
= fsulaplacian(x
)x
using the laplacian scores. the
function returns idx
, which contains the indices of features ordered by
feature importance. you can use idx
to select important features for
unsupervised learning.
specifies additional options using one or more name-value pair arguments. for example, you
can specify idx
= fsulaplacian(x
,name,value
)'numneighbors',10
to create a similarity graph using 10 nearest neighbors.
examples
rank features by importance
load the sample data.
load ionosphere
rank the features based on importance.
[idx,scores] = fsulaplacian(x);
create a bar plot of the feature importance scores.
bar(scores(idx)) xlabel('feature rank') ylabel('feature importance score')
select the top five most important features. find the columns of these features in x
.
idx(1:5)
ans = 1×5
15 13 17 21 19
the 15th column of x
is the most important feature.
rank features using specified similarity matrix
compute a similarity matrix from fisher's iris data set and rank the features using the similarity matrix.
load fisher's iris data set.
load fisheriris
find the distance between each pair of observations in meas
by using the and functions with the default euclidean distance metric.
d = pdist(meas); z = squareform(d);
construct the similarity matrix and confirm that it is symmetric.
s = exp(-z.^2); issymmetric(s)
ans = logical
1
rank the features.
idx = fsulaplacian(meas,'similarity',s)
idx = 1×4
3 4 1 2
ranking using the similarity matrix s
is the same as ranking by specifying 'numneighbors'
as size(meas,1)
.
idx2 = fsulaplacian(meas,'numneighbors',size(meas,1))
idx2 = 1×4
3 4 1 2
input arguments
x
— input data
numeric matrix
input data, specified as an n-by-p numeric
matrix. the rows of x
correspond to observations (or points), and the
columns correspond to features.
the software treats nan
s in x
as missing
data and ignores any row of x
containing at least one
nan
.
data types: single
| double
name-value arguments
specify optional pairs of arguments as
name1=value1,...,namen=valuen
, where name
is
the argument name and value
is the corresponding value.
name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
before r2021a, use commas to separate each name and value, and enclose
name
in quotes.
example: 'numneighbors',10,'kernelscale','auto'
specifies the number
of nearest neighbors as 10 and the kernel scale factor as
'auto'
.
similarity
— similarity matrix
[]
(empty matrix) (default) | symmetric matrix
similarity matrix, specified as the comma-separated pair consisting of
'similarity'
and an
n-by-n symmetric matrix, where
n is the number of observations. the similarity matrix (or
adjacency matrix) represents the input data by modeling local neighborhood
relationships among the data points. the values in a similarity matrix represent the
edges (or connections) between nodes (data points) that are connected in a similarity graph. for more information,
see similarity matrix.
if you specify the 'similarity'
value, then you cannot
specify any other name-value pair argument. if you do not specify the
'similarity'
value, then the software computes a similarity
matrix using the options specified by the other name-value pair arguments.
data types: single
| double
distance
— distance metric
character vector | string scalar | function handle
distance metric, specified as the comma-separated pair consisting of
'distance'
and a character vector, string scalar, or function
handle, as described in this table.
value | description |
---|---|
'euclidean' | euclidean distance (default) |
'seuclidean' | standardized euclidean distance. each coordinate difference between
observations is scaled by dividing by the corresponding element of the
standard deviation computed from |
'mahalanobis' | mahalanobis distance using the sample covariance of
|
'cityblock' | city block distance |
'minkowski' | minkowski distance. the default exponent is 2. use the
|
'chebychev' | chebychev distance (maximum coordinate difference) |
'cosine' | one minus the cosine of the included angle between observations (treated as vectors) |
'correlation' | one minus the sample correlation between observations (treated as sequences of values) |
'hamming' | hamming distance, which is the percentage of coordinates that differ |
'jaccard' | one minus the jaccard coefficient, which is the percentage of nonzero coordinates that differ |
'spearman' | one minus the sample spearman's rank correlation between observations (treated as sequences of values) |
@ | custom distance function handle. a distance function has the form function d2 = distfun(zi,zj) % calculation of distance ...
if your data is not sparse, you can generally compute distance more quickly by using a built-in distance instead of a function handle. |
for more information, see .
when you use the 'seuclidean'
, 'minkowski'
,
or 'mahalanobis'
distance metric, you can specify the additional
name-value pair argument 'scale'
, 'p'
, or
'cov'
, respectively, to control the distance metrics.
example: 'distance','minkowski','p',3
specifies to use the
minkowski distance metric with an exponent of 3
.
p
— exponent for minkowski distance metric
2
(default) | positive scalar
exponent for the minkowski distance metric, specified as the comma-separated pair consisting of 'p'
and a positive scalar.
this argument is valid only if 'distance'
is 'minkowski'
.
example: 'p',3
data types: single
| double
cov
— covariance matrix for mahalanobis distance metric
cov(x,'omitrows')
(default) | positive definite matrix
covariance matrix for the mahalanobis distance metric, specified as the comma-separated pair
consisting of 'cov'
and a positive definite matrix.
this argument is valid only if 'distance'
is 'mahalanobis'
.
example: 'cov',eye(4)
data types: single
| double
scale
— scaling factors for standardized euclidean distance metric
std(x,'omitnan')
(default) | numeric vector of nonnegative values
scaling factors for the standardized euclidean distance metric, specified as the
comma-separated pair consisting of 'scale'
and a numeric vector of
nonnegative values.
scale
has length p (the number of columns in
x
), because each dimension (column) of x
has a
corresponding value in scale
. for each dimension of
x
, fsulaplacian
uses the corresponding value
in scale
to standardize the difference between observations.
this argument is valid only if 'distance'
is 'seuclidean'
.
data types: single
| double
numneighbors
— number of nearest neighbors
log(size(x,1))
(default) | positive integer
number of nearest neighbors used to construct the similarity
graph, specified as the comma-separated pair consisting of 'numneighbors'
and a positive integer.
example: 'numneighbors',10
data types: single
| double
kernelscale
— scale factor
1
(default) | 'auto'
| positive scalar
scale factor for the kernel, specified as the comma-separated pair consisting of 'kernelscale'
and 'auto'
or a positive scalar. the software uses the scale factor to transform distances to similarity measures. for more information, see similarity graph.
the
'auto'
option is supported only for the'euclidean'
and'seuclidean'
distance metrics.if you specify
'auto'
, then the software selects an appropriate scale factor using a heuristic procedure. this heuristic procedure uses subsampling, so estimates can vary from one call to another. to reproduce results, set a random number seed using before callingfsulaplacian
.
example: 'kernelscale','auto'
output arguments
idx
— indices of features ordered by feature importance
numeric vector
indices of the features in x
ordered by feature importance,
returned as a numeric vector. for example, if idx(3)
is
5
, then the third most important feature is the fifth column in
x
.
scores
— feature scores
numeric vector
feature scores, returned as a numeric vector. a large score value in
scores
indicates that the corresponding feature is important. the
values in scores
have the same order as the features in
x
.
more about
similarity graph
a similarity graph models the local neighborhood relationships between data points in x
as an undirected graph. the nodes in the graph represent data points, and the edges, which are directionless, represent the connections between the data points.
if the pairwise distance disti,j between any two nodes i and j is positive (or larger than a certain threshold), then the similarity graph connects the two nodes using an edge [2]. the edge between the two nodes is weighted by the pairwise similarity si,j, where , for a specified kernel scale σ value.
fsulaplacian
constructs a similarity graph using the nearest
neighbor method. the function connects points in x
that are nearest
neighbors. use 'numneighbors'
to specify the number of nearest
neighbors.
similarity matrix
a similarity matrix is a matrix representation of a similarity graph. the n-by-n matrix contains pairwise similarity values between connected nodes in the similarity graph. the similarity matrix of a graph is also called an adjacency matrix.
the similarity matrix is symmetric because the edges of the similarity graph are
directionless. a value of si,j =
0
means that nodes i and j of the
similarity graph are not connected.
degree matrix
a degree matrix dg is an n-by-n diagonal matrix obtained by summing the rows of the similarity matrix s. that is, the ith diagonal element of dg is
laplacian matrix
a laplacian matrix, which is one way of representing a similarity graph, is defined as the difference between the degree matrix dg and the similarity matrix s.
algorithms
laplacian score
the fsulaplacian
function ranks features using laplacian
scores[1] obtained from a nearest
neighbor similarity graph.
fsulaplacian
computes the values in scores
as follows:
for each data point in
x
, define a local neighborhood using the nearest neighbor method, and find pairwise distances for all points i and j in the neighborhood.convert the distances to the similarity matrix s using the kernel transformation , where σ is the scale factor for the kernel as specified by the
'kernelscale'
name-value pair argument.center each feature by removing its mean.
where xr is the rth feature, dg is the degree matrix, and .
compute the score sr for each feature.
note that [1] defines the laplacian score as
where l is the laplacian matrix, defined as
the difference between dg and
s. the fsulaplacian
function uses only the second
term of this equation for the score value of scores
so that a large
score value indicates an important feature.
selecting features using the laplacian score is consistent with minimizing the value
where xir represents the ith observation of the rth feature. minimizing this value implies that the algorithm prefers features with large variance. also, the algorithm assumes that two data points of an important feature are close if and only if the similarity graph has an edge between the two data points.
references
[1] he, x., d. cai, and p. niyogi. "laplacian score for feature selection." nips proceedings. 2005.
[2] von luxburg, u. “a tutorial on spectral clustering.” statistics and computing journal. vol.17, number 4, 2007, pp. 395–416.
version history
introduced in r2019b
打开示例
您曾对此示例进行过修改。是否要打开带有您的编辑的示例?
matlab 命令
您点击的链接对应于以下 matlab 命令:
请在 matlab 命令行窗口中直接输入以执行命令。web 浏览器不支持 matlab 命令。
select a web site
choose a web site to get translated content where available and see local events and offers. based on your location, we recommend that you select: .
you can also select a web site from the following list:
how to get best site performance
select the china site (in chinese or english) for best site performance. other mathworks country sites are not optimized for visits from your location.
americas
- (español)
- (english)
- (english)
europe
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
asia pacific
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)