Main Content

Model Building and Assessment

Feature selection, feature engineering, model selection, hyperparameter optimization, cross-validation, residual diagnostics, and plots

When you build a high-quality regression model, it is important to select the right features (or predictors), tune hyperparameters (model parameters not fit to the data), and assess model assumptions through residual diagnostics.

You can tune hyperparameters by iterating between choosing values for them and cross-validating a model using your choices. This process yields multiple models, and the best model among them might be the one that minimizes the estimated generalization error. For example, to tune an SVM model, choose a set of box constraints and kernel scales, cross-validate a model for each pair of values, and then compare their 10-fold, cross-validated, mean squared error estimates.

To engineer new features before training a regression model, use genrfeatures.

To build and assess regression models interactively, use the Regression Learner app.

To automatically select a model with tuned hyperparameters, use fitrauto. The function tries a selection of regression model types with different hyperparameter values and returns a final model that is expected to perform well. Use fitrauto when you are uncertain which regression model types best suit your data.

Certain nonparametric regression functions in Statistics and Machine Learning Toolbox™ offer automatic hyperparameter tuning through Bayesian optimization, grid search, or random search. bayesopt, the main function for implementing Bayesian optimization, is flexible enough for many other applications as well. For more details, see Bayesian Optimization Workflow.

To interpret a regression model, you can use lime, shapley, and plotPartialDependence.

Apps

Regression LearnerTrain regression models to predict data using supervised machine learning

Functions

expand all

fsrftestUnivariate feature ranking for regression using F-tests (Since R2020a)
fsrmrmrRank features for regression using minimum redundancy maximum relevance (MRMR) algorithm (Since R2022a)
fsrncaFeature selection using neighborhood component analysis for regression
oobPermutedPredictorImportancePredictor importance estimates by permutation of out-of-bag predictor observations for random forest of regression trees
partialDependenceCompute partial dependence (Since R2020b)
plotPartialDependenceCreate partial dependence plot (PDP) and individual conditional expectation (ICE) plots
predictorImportanceEstimates of predictor importance for regression tree
predictorImportanceEstimates of predictor importance for regression ensemble of decision trees
relieffRank importance of predictors using ReliefF or RReliefF algorithm
selectFeaturesSelect important features for NCA classification or regression (Since R2023b)
sequentialfsSequential feature selection using custom criterion
stepwiselmPerform stepwise regression
stepwiseglmCreate generalized linear regression model by stepwise regression
genrfeaturesPerform automated feature engineering for regression (Since R2021b)
describeDescribe generated features (Since R2021a)
transformTransform new data using generated features (Since R2021a)
fitrautoAutomatically select regression model with optimized hyperparameters (Since R2020b)
bayesoptSelect optimal machine learning hyperparameters using Bayesian optimization
hyperparametersVariable descriptions for optimizing a fit function
optimizableVariableVariable description for bayesopt or other optimizers

For Time-Independent Data

crossvalEstimate loss using cross-validation
cvpartitionPartition data for cross-validation
repartitionRepartition data for cross-validation
testTest indices for cross-validation
trainingTraining indices for cross-validation

For Time Series Data

tspartitionPartition time series data for cross-validation (Since R2022b)
testTest indices for time series cross-validation (Since R2022b)
trainingTraining indices for time series cross-validation (Since R2022b)

Local Interpretable Model-Agnostic Explanations (LIME)

limeLocal interpretable model-agnostic explanations (LIME) (Since R2020b)
fitFit simple model of local interpretable model-agnostic explanations (LIME) (Since R2020b)
plotPlot results of local interpretable model-agnostic explanations (LIME) (Since R2020b)

Shapley Values

shapleyShapley values (Since R2021a)
fitCompute Shapley values for query point (Since R2021a)
plotPlot Shapley values (Since R2021a)

Partial Dependence

partialDependenceCompute partial dependence (Since R2020b)
plotPartialDependenceCreate partial dependence plot (PDP) and individual conditional expectation (ICE) plots
coefCIConfidence intervals of coefficient estimates of linear regression model
coefTestLinear hypothesis test on linear regression model coefficients
dwtestDurbin-Watson test with linear regression model object
plotScatter plot or added variable plot of linear regression model
plotAddedAdded variable plot of linear regression model
plotAdjustedResponseAdjusted response plot of linear regression model
plotDiagnosticsPlot observation diagnostics of linear regression model
plotEffectsPlot main effects of predictors in linear regression model
plotInteractionPlot interaction effects of two predictors in linear regression model
plotResidualsPlot residuals of linear regression model
plotSlicePlot of slices through fitted linear regression surface
coefCIConfidence intervals of coefficient estimates of generalized linear regression model
coefTestLinear hypothesis test on generalized linear regression model coefficients
devianceTestAnalysis of deviance for generalized linear regression model
plotDiagnosticsPlot observation diagnostics of generalized linear regression model
plotResidualsPlot residuals of generalized linear regression model
plotSlicePlot of slices through fitted generalized linear regression surface
coefCIConfidence intervals of coefficient estimates of nonlinear regression model
coefTestLinear hypothesis test on nonlinear regression model coefficients
plotDiagnosticsPlot diagnostics of nonlinear regression model
plotSlicePlot of slices through fitted nonlinear regression surface
linhyptestLinear hypothesis test

Objects

expand all

FeatureSelectionNCARegressionFeature selection for regression using neighborhood component analysis (NCA)
FeatureTransformerGenerated feature transformations (Since R2021a)
BayesianOptimizationBayesian optimization results

Topics

Regression Learner App Workflow

Feature Selection

Feature Engineering

  • Automated Feature Engineering for Regression
    Use genrfeatures to engineer new features before training a regression model. Before making predictions on new data, apply the same feature transformations to the new data set.

Automated Model Selection

Hyperparameter Optimization

Model Interpretation

Cross-Validation

Linear Model Diagnostics

  • Interpret Linear Regression Results
    Display and interpret linear regression output statistics.
  • Linear Regression
    Fit a linear regression model and examine the result.
  • Linear Regression with Interaction Effects
    Construct and analyze a linear regression model with interaction effects and interpret the results.
  • Summary of Output and Diagnostic Statistics
    Evaluate a fitted model by using model properties and object functions.
  • F-statistic and t-statistic
    In linear regression, the F-statistic is the test statistic for the analysis of variance (ANOVA) approach to test the significance of the model or the components in the model. The t-statistic is useful for making inferences about the regression coefficients.
  • Coefficient of Determination (R-Squared)
    Coefficient of determination (R-squared) indicates the proportionate amount of variation in the response variable y explained by the independent variables X in the linear regression model.
  • Coefficient Standard Errors and Confidence Intervals
    Estimated coefficient variances and covariances capture the precision of regression coefficient estimates.
  • Residuals
    Residuals are useful for detecting outlying y values and checking the linear regression assumptions with respect to the error term in the regression model.
  • Durbin-Watson Test
    The Durbin-Watson test assesses whether or not there is autocorrelation among the residuals of time series data.
  • Cook’s Distance
    Cook's distance is useful for identifying outliers in the X values (observations for predictor variables).
  • Hat Matrix and Leverage
    The hat matrix provides a measure of leverage.
  • Delete-1 Statistics
    Delete-1 change in covariance (CovRatio) identifies the observations that are influential in the regression fit.

Generalized Linear Model Diagnostics

  • Generalized Linear Models
    Generalized linear models use linear methods to describe a potentially nonlinear relationship between predictor terms and a response variable.

Nonlinear Model Diagnostics

  • Nonlinear Regression
    Parametric nonlinear models represent the relationship between a continuous response variable and one or more continuous predictor variables.