main content

rank features for unsupervised learning using laplacian scores -凯发k8网页登录

rank features for unsupervised learning using laplacian scores

since r2019b

description

example

idx = fsulaplacian(x) ranks features (variables) in 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.

example

idx = fsulaplacian(x,name,value) specifies additional options using one or more name-value pair arguments. for example, you can specify 'numneighbors',10 to create a similarity graph using 10 nearest neighbors.

[idx,scores] = fsulaplacian(___) also returns the feature scores scores, using any of the input argument combinations in the previous syntaxes. a large score value indicates that the corresponding feature is important.

examples

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')

figure contains an axes object. the axes object with xlabel feature rank, ylabel feature importance score contains an object of type bar.

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.

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

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 nans 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 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 metric, specified as the comma-separated pair consisting of 'distance' and a character vector, string scalar, or function handle, as described in this table.

valuedescription
'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 x. use the scale name-value pair argument to specify a different scaling factor.

'mahalanobis'

mahalanobis distance using the sample covariance of x, c = cov(x,'omitrows'). use the cov name-value pair argument to specify a different covariance matrix.

'cityblock'

city block distance

'minkowski'

minkowski distance. the default exponent is 2. use the p name-value pair argument to specify a different exponent, where p is a positive scalar value.

'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)

@distfun

custom distance function handle. a distance function has the form

function d2 = distfun(zi,zj)
% calculation of distance
...
where
  • zi is a 1-by-n vector containing a single observation.

  • zj is an m2-by-n matrix containing multiple observations. distfun must accept a matrix zj with an arbitrary number of observations.

  • d2 is an m2-by-1 vector of distances, and d2(k) is the distance between observations zi and zj(k,:).

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.

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

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

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

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

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 calling fsulaplacian.

example: 'kernelscale','auto'

output arguments

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.

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 si,j=exp((disti,jσ)2), 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 s=(si,j)i,j=1,,n 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 dg(i,i)=j=1nsi,j.

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.

l=dgs.

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:

  1. for each data point in x, define a local neighborhood using the nearest neighbor method, and find pairwise distances disti,j for all points i and j in the neighborhood.

  2. convert the distances to the similarity matrix s using the kernel transformation si,j=exp((disti,jσ)2), where σ is the scale factor for the kernel as specified by the 'kernelscale' name-value pair argument.

  3. center each feature by removing its mean.

    x˜r=xrxrtdg11tdg11,

    where xr is the rth feature, dg is the degree matrix, and 1t=[1,,1]t.

  4. compute the score sr for each feature.

    sr=x˜rtsx˜rx˜rtdgx˜r.

note that [1] defines the laplacian score as

lr=x˜rtlx˜rx˜rtdgx˜r=1x˜rtsx˜rx˜rtdgx˜r,

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

i,j(xirxjr)2si,jvar(xr),

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

网站地图