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

    %% Explore |FeatureSelectionNCARegression| Object
% Load the sample data.
load imports-85

%%
% The first 15 columns contain the continuous predictor variables, whereas
% the 16th column contains the response variable, which is the price of a car. Define
% the variables for the neighborhood component analysis model.
Predictors = X(:,1:15);
Y = X(:,16);

%%
% Fit a neighborhood component analysis (NCA) model for regression to detect
% the relevant features.
mdl = fsrnca(Predictors,Y);

%%
% The returned NCA model, |mdl|, is a
% |FeatureSelectionNCARegression| 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
% |FeatureSelectionNCARegression| 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 |fsrnca| 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 also 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 |fsrnca| .