Load the sample data.
Download the housing data [1], from the UCI Machine Learning Repository [2]. The dataset has 506 observations. The first 13 columns contain the predictor values and the last column contains the response values. The goal is to predict the median value of owner-occupied homes in suburban Boston as a function of 13 predictors.
Load the data and define the response vector and the predictor matrix.
Divide the data into training and test sets using the 4th predictor as the grouping variable for a stratified partitioning. This ensures that each partition includes similar amount of observations from each group.
cvpartition
randomly assigns 56 observations into a test set and the rest of the data into a training set.
Perform Feature Selection Using Default Settings
Perform feature selection using NCA model for regression. Standardize the predictor values.
Plot the feature weights.
The weights of irrelevant features are expected to approach zero. fsrnca
identifies two features as irrelevant.
Compute the regression loss.
Compute the predicted response values for the test set and plot them versus the actual response.
A perfect fit versus the actual values forms a 45 degree straight line. In this plot, the predicted and actual response values seem to be scattered around this line. Tuning (regularization parameter) value usually helps improve the performance.
Tune the regularization parameter using 10-fold cross-validation
Tuning means finding the value that will produce the minimum regression loss. Here are the steps for tuning using 10-fold cross-validation:
1. First partition the data into 10 folds. For each fold, cvpartition
assigns 1/10th of the data as a training set, and 9/10th of the data as a test set.
Assign the values for the search. Create an array to store the loss values.
2. Train the neighborhood component analysis (nca) model for each value using the training set in each fold.
3. Fit a Gaussian process regression (gpr) model using the selected features. Next, compute the regression loss for the corresponding test set in the fold using the gpr model. Record the loss value.
4. Repeat this for each value and each fold.
Compute the average loss obtained from the folds for each value. Plot the mean loss versus the values.
Find the value that produces the minimum loss value.
Perform feature selection for regression using the best value. Standardize the predictor values.
Plot the feature weights.
Compute the loss using the new nca model on the test data, which is not used to select the features.
Tuning the regularization parameter helps identify the relevant features and reduces the loss.
Plot the predicted versus the actual response values in the test set.
The predicted response values seem to be closer to the actual values as well.
References
[1] Harrison, D. and D.L., Rubinfeld. "Hedonic prices and the demand for clean air." J. Environ. Economics & Management. Vol.5, 1978, pp. 81-102.
[2] Lichman, M. UCI Machine Learning Repository, Irvine, CA: University of California, School of Information and Computer Science, 2013. https://archive.ics.uci.edu/ml.