Feature selection for classification using neighborhood component analysis (NCA)
contains the data, fitting information, feature weights, and other
parameters of a neighborhood component analysis (NCA) model.
fscnca learns the feature weights using
a diagonal adaptation of NCA and returns an instance of a
The function achieves feature selection by regularizing the feature
FeatureSelectionNCAClassification object using
FitMethod— Name of fitting method
Name of the fitting method used to fit this model, stored as one of the following:
'exact' — Perform fitting
using all of the data.
'none' — No fitting. Use
this option to evaluate the generalization error of the NCA model
using the initial feature weights supplied in the call to
'average' — Divide the data
into partitions (subsets), fit each partition using the
and return the average of the feature weights. You can specify the
number of partitions using the
InitialLearningRate— Initial learning rate
Initial learning rate for the
stored as a positive real scalar. The
learning rate decays over iterations starting at the value specified
pair arguments to control the automatic tuning of initial learning
rate in the call to
FeatureWeights— Feature weights
Feature weights, stored as a p-by-1 vector
of real scalars, where p is the number of predictors
FeatureWeights is a p-by-m matrix. m is
the number of partitions specified via the
pair argument in the call to
The absolute value of
a measure of the importance of predictor
that is close to 0 indicates that predictor
not influence the response in
|loss||Evaluate accuracy of learned feature weights on test data|
|predict||Predict responses using neighborhood component analysis (NCA) classifier|
|refit||Refit neighborhood component analysis (NCA) model for classification|
Load the sample data.
The data set has 34 continuous predictors. The response variable is the radar returns, labeled as b (bad) or g (good).
Fit a neighborhood component analysis (NCA) model for classification to detect the relevant features.
mdl = fscnca(X,Y);
The returned NCA model,
mdl, is a
FeatureSelectionNCAClassification object. This object stores information about the training data, model, and optimization. You can access the object properties, such as the feature weights, using dot notation.
Plot the feature weights.
figure() plot(mdl.FeatureWeights,'ro') xlabel('Feature Index') ylabel('Feature Weight') grid on
The weights of the irrelevant features are zero. The
'Verbose',1 option in the call to
fscnca displays the optimization information on the command line. You can also visualize the optimization process by plotting the objective function versus the iteration number.
figure plot(mdl.FitInfo.Iteration,mdl.FitInfo.Objective,'ro-') grid on xlabel('Iteration Number') ylabel('Objective')
ModelParameters property is a
struct that contains more information about the model. You can access the fields of this property using dot notation. For example, see if the data was standardized or not.
ans = logical 0
0 means that the data was not standardized before fitting the NCA model. You can standardize the predictors when they are on very different scales using the
'Standardize',1 name-value pair argument in the call to
Value. To learn how value classes affect copy operations, see Copying Objects (MATLAB).