www.gusucode.com > stats 源码程序 matlab案例代码 > stats/ExploreFeatureSelectionNCAClassificationObjectExample.m

    %% Explore |FeatureSelectionNCAClassification| Object
% Load the sample data.
load ionosphere

%%
% The data set has 34 continuous predictors. The response variable is the
% radar returns, labelled 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 properties of this object using dot notation. For example, you
% can access the feature weights stored in a
% |FeatureSelectionNCAClassification| object. 

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

%%
% The |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.
mdl.ModelParameters.Standardize

%%
% |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 |fscnca| .