This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

relieff

Rank importance of predictors using ReliefF or RReliefF algorithm

Syntax

[ranks,weights] = relieff(X,y,k)
[ranks,weights] = relieff(X,y,k,Name,Value)

Description

example

[ranks,weights] = relieff(X,y,k) returns the ranks and weights of predictors for the input data matrix X and response vector y, using either the ReliefF or RReliefF algorithm with k nearest neighbors.

If y is numeric, relieff performs RReliefF analysis for regression by default. Otherwise, relieff performs ReliefF analysis for classification using k nearest neighbors per class. For more information on ReliefF and RReliefF, see Algorithms.

example

[ranks,weights] = relieff(X,y,k,Name,Value) specifies additional options using one or more name-value pair arguments. For example, 'updates',10 sets the number of observations randomly selected for computing weights to 10.

Examples

collapse all

Load the sample data.

load fisheriris

Find the important predictors using 10 nearest neighbors.

[ranks,weights] = relieff(meas,species,10)
ranks = 1×4

     4     3     1     2

weights = 1×4

    0.1399    0.1226    0.3590    0.3754

ranks shows the predictor numbers listed according to their ranking. The fourth predictor is the most important, and the second predictor is the least important. weights gives the weight values in the same order as the predictors. The first predictor has a weight of 0.1399, and the fourth predictor has a weight of 0.3754.

Load the sample data.

load ionosphere

Rank the predictors based on importance using 10 nearest neighbors.

[ranks,weights] = relieff(X,Y,10);

Create a bar plot of predictor importance weights.

bar(weights(ranks))
xlabel('Predictor rank')
ylabel('Predictor importance weight')

Select the top 5 most important predictors. Find the columns of these predictors in X.

ranks(1:5)
ans = 1×5

    24     3     8     5    14

The 24th column of X is the most important predictor of Y.

Rank categorical predictors using relieff.

Load the sample data.

load carbig

Convert the categorical predictor variables Mfg, Model, and Origin to numerical values, and combine them into an input matrix. Specify the response variable MPG.

X = [grp2idx(Mfg) grp2idx(Model) grp2idx(Origin)];
y = MPG;

Find the ranks and weights of the predictor variables using 10 nearest neighbors and treating the data in X as categorical.

[ranks,weights] = relieff(X,y,10,'categoricalx','on')
ranks = 1×3

     2     3     1

weights = 1×3

   -0.0019    0.0501    0.0114

The Model predictor is the most important in predicting MPG. The Mfg variable has a negative weight, indicating it is not a good predictor of MPG.

Input Arguments

collapse all

Predictor data, specified as a numeric matrix. Each row of X corresponds to one observation, and each column corresponds to one variable.

Data Types: single | double

Response data, specified as a numeric vector, categorical vector, logical vector, character array, string array, or cell array of character vectors.

Data Types: single | double | categorical | logical | char | string | cell

Number of nearest neighbors, specified as a positive integer scalar.

Data Types: single | double

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: relieff(X,y,5,'method','classification','categoricalx','on') specifies 5 nearest neighbors and treats the response variable and predictor data as categorical.

Method for computing weights, specified as the comma-separated pair consisting of 'method' and either 'regression' or 'classification'. If y is numeric, 'regression' is the default method. Otherwise, 'classification' is the default.

Example: 'method','classification'

Prior probabilities for each class, specified as the comma-separated pair consisting of 'prior' and a value in this table.

ValueDescription
'empirical'The class probabilities are determined from class frequencies in y.
'uniform'All class probabilities are equal.
numeric vectorOne value exists for each distinct group name.
structure

A structure S with two fields:

  • S.group contains the group names as a variable of the same type as y.

  • S.prob contains a vector of corresponding probabilities.

Example: 'prior','uniform'

Data Types: single | double | char | string | struct

Number of observations to select at random for computing weights, specified as the comma-separated pair consisting of 'updates' and either 'all' or a positive integer scalar. By default, relieff uses all observations.

Example: 'updates',25

Data Types: single | double | char | string

Categorical predictors flag, specified as the comma-separated pair consisting of 'categoricalx' and either 'on' or 'off'. If you specify 'on', then relieff treats all predictors in X as categorical. Otherwise, it treats all predictors in X as numeric. You cannot mix numeric and categorical predictors.

Example: 'categoricalx','on'

Distance scaling factor, specified as the comma-separated pair consisting of 'sigma' and a numeric positive scalar. For observation i, influence on the predictor weight from its nearest neighbor j is multiplied by e(rank(i,j)/sigma)2. rank(i,j) is the position of the jth observation among the nearest neighbors of the ith observation, sorted by distance. The default is Inf for classification (all nearest neighbors have the same influence) and 50 for regression.

Example: 'sigma',20

Data Types: single | double

Output Arguments

collapse all

Indices of the most important predictors, returned as a numeric vector. ranks are the indices of the columns in X ordered by predictor importance. For example, if ranks(3) is 5, then the third most important predictor is the fifth column in X.

Data Types: double

Weights of the predictors, returned as a numeric vector. weights range from -1 to 1 with large positive weights assigned to important predictors.

Data Types: double

Tips

  • Predictor ranks and weights usually depend on k. If you set k to 1, then the estimates can be unreliable for noisy data. If you set k to a value comparable with the number of observations (rows) in X, relieff can fail to find important predictors. You can start with k = 10 and investigate the stability and reliability of relieff ranks and weights for various values of k.

  • relieff removes observations with NaN values.

Algorithms

collapse all

ReliefF

ReliefF finds the weights of predictors in the case where y is a multiclass categorical variable. The algorithm penalizes the predictors that give different values to neighbors of the same class, and rewards predictors that give different values to neighbors of different classes.

ReliefF first sets all predictor weights Wj to 0. Then, the algorithm iteratively selects a random observation xr, finds the k-nearest observations to xr for each class, and updates, for each nearest neighbor xq, all the weights for the predictors Fj as follows:

If xr and xq are in the same class,

Wji=Wji1Δj(xr,xq)mdrq.

If xr and xq are in different classes,

Wji=Wji1+pyq1pyrΔj(xr,xq)mdrq.

  • Wji is the weight of the predictor Fj at the ith iteration step.

  • pyr is the prior probability of the class to which xr belongs, and pyq is the prior probability of the class to which xq belongs.

  • m is the number of iterations specified by 'updates'.

  • Δj(xr,xq) is the difference in the value of the predictor Fj between observations xr and xq. Let xrj denote the value of the jth predictor for observation xr, and let xqj denote the value of the jth predictor for observation xq.

    • For discrete Fj,

      Δj(xr,xq)={0,xrj=xqj1,xrjxqj.

    • For continuous Fj,

      Δj(xr,xq)=|xrjxqj|max(Fj)min(Fj).

  • drq is a distance function of the form

    drq=d˜rql=1kd˜rl.

    The distance is subject to the scaling

    d˜rq=e(rank(r,q)/sigma)2

    where rank(r,q) is the position of the qth observation among the nearest neighbors of the rth observation, sorted by distance. k is the number of nearest neighbors, specified by k. You can change the scaling by specifying 'sigma'.

RReliefF

RReliefF works with continuous y. Similar to ReliefF, RReliefF also penalizes the predictors that give different values to neighbors with the same response values, and rewards predictors that give different values to neighbors with different response values. However, RReliefF uses intermediate weights to compute the final predictor weights.

Given two nearest neighbors, assume the following:

  • Wdy is the weight of having different values for the response y.

  • Wdj is the weight of having different values for the predictor Fj.

  • Wdydj is the weight of having different response values and different values for the predictor Fj.

RReliefF first sets the weights Wdy, Wdj, Wdydj, and Wj equal to 0. Then, the algorithm iteratively selects a random observation xr, finds the k-nearest observations to xr, and updates, for each nearest neighbor xq, all the intermediate weights as follows:

Wdyi=Wdyi1+Δy(xr,xq)drq.

Wdji=Wdji1+Δj(xr,xq)drq.

Wdydji=Wdydji1+Δy(xr,xq)Δj(xr,xq)drq.

  • The i and i-1 superscripts denote the iteration step number. m is the number of iterations specified by 'updates'.

  • Δy(xr,xq) is the difference in the value of the continuous response y between observations xr and xq. Let yr denote the value of the response for observation xr, and let yq denote the value of the response for observation xq.

    Δy(xr,xq)=|yryq|max(y)min(y).

  • The Δj(xr,xq) and drq functions are the same as for ReliefF.

RReliefF calculates the predictor weights Wj after fully updating all the intermediate weights.

Wj=WdydjWdyWdjWdydjmWdy.

For more information, see [2].

References

[1] Kononenko, I., E. Simec, and M. Robnik-Sikonja. (1997). “Overcoming the myopia of inductive learning algorithms with RELIEFF.” Retrieved from CiteSeerX: https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.56.4740

[2] Robnik-Sikonja, M., and I. Kononenko. (1997). “An adaptation of Relief for attribute estimation in regression.” Retrieved from CiteSeerX: https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.34.8381

[3] Robnik-Sikonja, M., and I. Kononenko. (2003). “Theoretical and empirical analysis of ReliefF and RReliefF.” Machine Learning, 53, 23–69.

Introduced in R2010b