Main Content

fitrauto

Automatically select regression model with optimized hyperparameters

Description

Given predictor and response data, fitrauto automatically tries a selection of regression model types with different hyperparameter values. By default, the function uses Bayesian optimization to select models and their hyperparameter values, and computes the following for each model: log(1 + valLoss), where valLoss is the cross-validation mean squared error (MSE). After the optimization is complete, fitrauto returns the model, trained on the entire data set, that is expected to best predict the responses for new data. You can use the predict and loss object functions of the returned model to predict on new data and compute the test set MSE, respectively.

Use fitrauto when you are uncertain which model types best suit your data. For information on alternative methods for tuning hyperparameters of regression models, see Alternative Functionality.

If your data contains over 10,000 observations, consider using an asynchronous successive halving algorithm (ASHA) instead of Bayesian optimization when you run fitrauto. ASHA optimization often finds good solutions faster than Bayesian optimization for data sets with many observations.

example

Mdl = fitrauto(Tbl,ResponseVarName) returns a regression model Mdl with tuned hyperparameters. The table Tbl contains the predictor variables and the response variable, where ResponseVarName is the name of the response variable.

Mdl = fitrauto(Tbl,formula) uses formula to specify the response variable and the predictor variables to consider among the variables in Tbl.

Mdl = fitrauto(Tbl,Y) uses the predictor variables in table Tbl and the response values in vector Y.

example

Mdl = fitrauto(X,Y) uses the predictor variables in matrix X and the response values in vector Y.

example

Mdl = fitrauto(___,Name,Value) specifies options using one or more name-value arguments in addition to any of the input argument combinations in previous syntaxes. For example, use the HyperparameterOptimizationOptions name-value argument to specify whether to use Bayesian optimization (default) or an asynchronous successive halving algorithm (ASHA). To use ASHA optimization, specify "HyperparameterOptimizationOptions",struct("Optimizer","asha"). You can include additional fields in the structure to control other aspects of the optimization.

[Mdl,OptimizationResults] = fitrauto(___) also returns OptimizationResults, which contains the results of the model selection and hyperparameter tuning process. This output is a BayesianOptimization object when you use Bayesian optimization, and a table when you use ASHA optimization.

Examples

collapse all

Use fitrauto to automatically select a regression model with optimized hyperparameters, given predictor and response data stored in a table.

Load Data

Load the carbig data set, which contains measurements of cars made in the 1970s and early 1980s.

load carbig

Create a table containing the predictor variables Acceleration, Displacement, and so on, as well as the response variable MPG.

cars = table(Acceleration,Displacement,Horsepower, ...
    Model_Year,Origin,Weight,MPG);

Partition Data

Partition the data into training and test sets. Use approximately 80% of the observations for the model selection and hyperparameter tuning process, and 20% of the observations to test the performance of the final model returned by fitrauto. Use cvpartition to partition the data.

rng("default") % For reproducibility of the data partition
c = cvpartition(length(MPG),"Holdout",0.2);
trainingIdx = training(c); % Training set indices
carsTrain = cars(trainingIdx,:);
testIdx = test(c); % Test set indices
carsTest = cars(testIdx,:);

Run fitrauto

Pass the training data to fitrauto. By default, fitrauto determines appropriate model types to try, uses Bayesian optimization to find good hyperparameter values, and returns a trained model Mdl with the best expected performance. Additionally, fitrauto provides a plot of the optimization and an iterative display of the optimization results. For more information on how to interpret these results, see Verbose Display.

Expect this process to take some time. To speed up the optimization process, consider running the optimization in parallel, if you have a Parallel Computing Toolbox™ license. To do so, pass "HyperparameterOptimizationOptions",struct("UseParallel",true) to fitrauto as a name-value argument.

Mdl = fitrauto(carsTrain,"MPG");
Learner types to explore: ensemble, svm, tree
Total iterations (MaxObjectiveEvaluations): 90
Total time (MaxTime): Inf

|=========================================================================================================================================|
| Iter | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|=========================================================================================================================================|
|    1 | Best   |           2.5161 |           0.42811 |           2.5161 |           2.5161 |         tree | MinLeafSize:              6 |
|    2 | Accept |           4.1439 |           0.31653 |           2.5161 |           2.5161 |          svm | BoxConstraint:       336.91 |
|      |        |                  |                   |                  |                  |              | KernelScale:      0.0018275 |
|      |        |                  |                   |                  |                  |              | Epsilon:             0.1074 |
|    3 | Accept |            4.144 |            6.1354 |           2.5161 |           2.5161 |     ensemble | Method:                 Bag |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      257 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:            156 |
|    4 | Accept |           3.1976 |            21.572 |           2.5161 |           2.5161 |          svm | BoxConstraint:     0.033502 |
|      |        |                  |                   |                  |                  |              | KernelScale:         153.38 |
|      |        |                  |                   |                  |                  |              | Epsilon:           0.093672 |
|    5 | Best   |           2.5041 |          0.098707 |           2.5041 |           2.5101 |         tree | MinLeafSize:              5 |
|    6 | Best   |            2.173 |             8.434 |            2.173 |           2.2138 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      287 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|    7 | Accept |           2.7182 |           0.10727 |            2.173 |           2.2138 |         tree | MinLeafSize:              1 |
|    8 | Accept |           17.207 |            24.418 |            2.173 |           2.2138 |          svm | BoxConstraint:       196.73 |
|      |        |                  |                   |                  |                  |              | KernelScale:         34.789 |
|      |        |                  |                   |                  |                  |              | Epsilon:            0.03716 |
|    9 | Accept |           4.1439 |           0.08053 |            2.173 |           2.2138 |          svm | BoxConstraint:       346.92 |
|      |        |                  |                   |                  |                  |              | KernelScale:       0.032493 |
|      |        |                  |                   |                  |                  |              | Epsilon:            0.23974 |
|   10 | Accept |           2.2139 |            7.9036 |            2.173 |           2.1945 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      278 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:             13 |
|=========================================================================================================================================|
| Iter | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|=========================================================================================================================================|
|   11 | Accept |           2.8889 |           0.10655 |            2.173 |           2.1945 |          svm | BoxConstraint:     0.033068 |
|      |        |                  |                   |                  |                  |              | KernelScale:         585.38 |
|      |        |                  |                   |                  |                  |              | Epsilon:             4.6993 |
|   12 | Accept |           4.1439 |          0.060722 |            2.173 |           2.1945 |          svm | BoxConstraint:       48.997 |
|      |        |                  |                   |                  |                  |              | KernelScale:      0.0045904 |
|      |        |                  |                   |                  |                  |              | Epsilon:             18.085 |
|   13 | Accept |           4.1439 |          0.079298 |            2.173 |           2.1945 |          svm | BoxConstraint:       985.69 |
|      |        |                  |                   |                  |                  |              | KernelScale:      0.0010988 |
|      |        |                  |                   |                  |                  |              | Epsilon:             449.48 |
|   14 | Accept |           2.2801 |            8.2142 |            2.173 |           2.1824 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      287 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:             63 |
|   15 | Accept |           4.1439 |          0.075809 |            2.173 |           2.1824 |          svm | BoxConstraint:     0.010812 |
|      |        |                  |                   |                  |                  |              | KernelScale:         1.2015 |
|      |        |                  |                   |                  |                  |              | Epsilon:           0.034209 |
|   16 | Accept |           4.1439 |          0.061902 |            2.173 |           2.1824 |          svm | BoxConstraint:    0.0021787 |
|      |        |                  |                   |                  |                  |              | KernelScale:       0.018209 |
|      |        |                  |                   |                  |                  |              | Epsilon:             443.71 |
|   17 | Accept |           2.2159 |            7.9406 |            2.173 |           2.1777 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      283 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:             17 |
|   18 | Accept |           2.6056 |          0.091476 |            2.173 |           2.1777 |         tree | MinLeafSize:              2 |
|   19 | Accept |           2.6056 |           0.13203 |            2.173 |           2.1777 |         tree | MinLeafSize:              2 |
|   20 | Accept |           2.7182 |          0.087514 |            2.173 |           2.1777 |         tree | MinLeafSize:              1 |
|=========================================================================================================================================|
| Iter | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|=========================================================================================================================================|
|   21 | Accept |           2.1763 |            7.9262 |            2.173 |             2.17 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      282 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              2 |
|   22 | Accept |           2.6056 |          0.077927 |            2.173 |             2.17 |         tree | MinLeafSize:              2 |
|   23 | Accept |           2.3016 |            5.2336 |            2.173 |           2.1774 |     ensemble | Method:                 Bag |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      202 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              9 |
|   24 | Accept |           4.1439 |          0.073168 |            2.173 |           2.1774 |          svm | BoxConstraint:       37.028 |
|      |        |                  |                   |                  |                  |              | KernelScale:       0.033731 |
|      |        |                  |                   |                  |                  |              | Epsilon:             0.2457 |
|   25 | Accept |            3.352 |          0.049267 |            2.173 |           2.1774 |         tree | MinLeafSize:            122 |
|   26 | Accept |           4.1439 |          0.060427 |            2.173 |           2.1774 |          svm | BoxConstraint:      0.01045 |
|      |        |                  |                   |                  |                  |              | KernelScale:      0.0024261 |
|      |        |                  |                   |                  |                  |              | Epsilon:             12.355 |
|   27 | Accept |           2.3188 |            5.9728 |            2.173 |           2.1761 |     ensemble | Method:                 Bag |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      212 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              2 |
|   28 | Accept |           2.4075 |            5.8104 |            2.173 |           2.1765 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      247 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:             83 |
|   29 | Accept |           2.6056 |          0.098163 |            2.173 |           2.1765 |         tree | MinLeafSize:              2 |
|   30 | Accept |           4.1439 |          0.070094 |            2.173 |           2.1765 |          svm | BoxConstraint:       2.1296 |
|      |        |                  |                   |                  |                  |              | KernelScale:         3.2623 |
|      |        |                  |                   |                  |                  |              | Epsilon:             599.62 |
|=========================================================================================================================================|
| Iter | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|=========================================================================================================================================|
|   31 | Accept |           2.5241 |          0.049706 |            2.173 |           2.1765 |         tree | MinLeafSize:              8 |
|   32 | Accept |           2.6443 |            4.9903 |            2.173 |           2.1764 |     ensemble | Method:                 Bag |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      229 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:             52 |
|   33 | Accept |            2.241 |            5.9324 |            2.173 |            2.175 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      235 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:             26 |
|   34 | Accept |           2.5448 |          0.046743 |            2.173 |            2.175 |         tree | MinLeafSize:             19 |
|   35 | Accept |           2.4438 |          0.068662 |            2.173 |            2.175 |         tree | MinLeafSize:             13 |
|   36 | Accept |           2.7182 |          0.076403 |            2.173 |            2.175 |         tree | MinLeafSize:              1 |
|   37 | Accept |           2.4749 |          0.047877 |            2.173 |            2.175 |         tree | MinLeafSize:              9 |
|   38 | Accept |           13.083 |            30.935 |            2.173 |            2.175 |          svm | BoxConstraint:       5.2568 |
|      |        |                  |                   |                  |                  |              | KernelScale:         10.811 |
|      |        |                  |                   |                  |                  |              | Epsilon:           0.073361 |
|   39 | Accept |           2.2349 |            5.6292 |            2.173 |           2.1758 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      214 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              4 |
|   40 | Accept |           3.0919 |          0.044015 |            2.173 |           2.1758 |         tree | MinLeafSize:             62 |
|=========================================================================================================================================|
| Iter | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|=========================================================================================================================================|
|   41 | Accept |           2.6335 |            6.4037 |            2.173 |           2.1735 |     ensemble | Method:                 Bag |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      280 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:             45 |
|   42 | Accept |           4.1439 |          0.077174 |            2.173 |           2.1735 |          svm | BoxConstraint:     0.093799 |
|      |        |                  |                   |                  |                  |              | KernelScale:      0.0053728 |
|      |        |                  |                   |                  |                  |              | Epsilon:             17.332 |
|   43 | Accept |           2.8766 |          0.097864 |            2.173 |           2.1735 |          svm | BoxConstraint:      0.20553 |
|      |        |                  |                   |                  |                  |              | KernelScale:         880.29 |
|      |        |                  |                   |                  |                  |              | Epsilon:             4.5637 |
|   44 | Accept |           2.1763 |            5.7872 |            2.173 |           2.1731 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      233 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              2 |
|   45 | Accept |           2.4576 |            5.4877 |            2.173 |           2.1732 |     ensemble | Method:                 Bag |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      232 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:             27 |
|   46 | Accept |           4.1439 |          0.052135 |            2.173 |           2.1732 |          svm | BoxConstraint:    0.0010276 |
|      |        |                  |                   |                  |                  |              | KernelScale:         5.6652 |
|      |        |                  |                   |                  |                  |              | Epsilon:             804.02 |
|   47 | Accept |           3.1594 |           0.08652 |            2.173 |           2.1732 |          svm | BoxConstraint:     0.002278 |
|      |        |                  |                   |                  |                  |              | KernelScale:         906.35 |
|      |        |                  |                   |                  |                  |              | Epsilon:           0.015573 |
|   48 | Accept |           14.659 |            21.351 |            2.173 |           2.1732 |          svm | BoxConstraint:    0.0010072 |
|      |        |                  |                   |                  |                  |              | KernelScale:         39.716 |
|      |        |                  |                   |                  |                  |              | Epsilon:           0.039845 |
|   49 | Accept |           4.1439 |           0.06733 |            2.173 |           2.1732 |          svm | BoxConstraint:    0.0010085 |
|      |        |                  |                   |                  |                  |              | KernelScale:        0.24517 |
|      |        |                  |                   |                  |                  |              | Epsilon:             447.36 |
|   50 | Accept |           4.1439 |          0.067864 |            2.173 |           2.1732 |          svm | BoxConstraint:        893.9 |
|      |        |                  |                   |                  |                  |              | KernelScale:         290.03 |
|      |        |                  |                   |                  |                  |              | Epsilon:             624.64 |
|=========================================================================================================================================|
| Iter | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|=========================================================================================================================================|
|   51 | Accept |           2.6859 |            2.8671 |            2.173 |           2.1732 |          svm | BoxConstraint:    0.0019596 |
|      |        |                  |                   |                  |                  |              | KernelScale:         264.51 |
|      |        |                  |                   |                  |                  |              | Epsilon:          0.0090654 |
|   52 | Accept |           4.1439 |          0.066538 |            2.173 |           2.1732 |          svm | BoxConstraint:       904.73 |
|      |        |                  |                   |                  |                  |              | KernelScale:       0.099617 |
|      |        |                  |                   |                  |                  |              | Epsilon:           0.014351 |
|   53 | Accept |           4.1439 |          0.050841 |            2.173 |           2.1732 |          svm | BoxConstraint:       975.67 |
|      |        |                  |                   |                  |                  |              | KernelScale:        0.50151 |
|      |        |                  |                   |                  |                  |              | Epsilon:             88.566 |
|   54 | Accept |           4.1439 |          0.065868 |            2.173 |           2.1732 |          svm | BoxConstraint:    0.0011848 |
|      |        |                  |                   |                  |                  |              | KernelScale:         201.25 |
|      |        |                  |                   |                  |                  |              | Epsilon:             441.13 |
|   55 | Accept |           4.8245 |             19.19 |            2.173 |           2.1732 |          svm | BoxConstraint:       548.22 |
|      |        |                  |                   |                  |                  |              | KernelScale:         548.99 |
|      |        |                  |                   |                  |                  |              | Epsilon:           0.010854 |
|   56 | Accept |           4.1439 |           0.08348 |            2.173 |           2.1732 |          svm | BoxConstraint:     0.001489 |
|      |        |                  |                   |                  |                  |              | KernelScale:         895.16 |
|      |        |                  |                   |                  |                  |              | Epsilon:             855.15 |
|   57 | Accept |           4.1439 |          0.076295 |            2.173 |           2.1732 |          svm | BoxConstraint:    0.0074202 |
|      |        |                  |                   |                  |                  |              | KernelScale:         0.3217 |
|      |        |                  |                   |                  |                  |              | Epsilon:          0.0096831 |
|   58 | Accept |           4.1439 |          0.085455 |            2.173 |           2.1732 |          svm | BoxConstraint:       757.82 |
|      |        |                  |                   |                  |                  |              | KernelScale:       0.065896 |
|      |        |                  |                   |                  |                  |              | Epsilon:             870.69 |
|   59 | Accept |           2.6999 |            5.8429 |            2.173 |           2.1732 |          svm | BoxConstraint:      0.00131 |
|      |        |                  |                   |                  |                  |              | KernelScale:         249.09 |
|      |        |                  |                   |                  |                  |              | Epsilon:            0.27904 |
|   60 | Accept |           4.1439 |          0.076182 |            2.173 |           2.1732 |          svm | BoxConstraint:     0.001578 |
|      |        |                  |                   |                  |                  |              | KernelScale:       0.010906 |
|      |        |                  |                   |                  |                  |              | Epsilon:          0.0091265 |
|=========================================================================================================================================|
| Iter | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|=========================================================================================================================================|
|   61 | Accept |           4.1439 |          0.057696 |            2.173 |           2.1732 |          svm | BoxConstraint:    0.0011475 |
|      |        |                  |                   |                  |                  |              | KernelScale:         1.2958 |
|      |        |                  |                   |                  |                  |              | Epsilon:              354.6 |
|   62 | Accept |           4.1439 |          0.077794 |            2.173 |           2.1732 |          svm | BoxConstraint:    0.0027272 |
|      |        |                  |                   |                  |                  |              | KernelScale:      0.0010042 |
|      |        |                  |                   |                  |                  |              | Epsilon:           0.014664 |
|   63 | Accept |           2.3368 |            5.1396 |            2.173 |           2.1732 |     ensemble | Method:                 Bag |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      205 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   64 | Accept |           2.7175 |            12.745 |            2.173 |           2.1732 |          svm | BoxConstraint:    0.0011027 |
|      |        |                  |                   |                  |                  |              | KernelScale:         188.56 |
|      |        |                  |                   |                  |                  |              | Epsilon:          0.0089013 |
|   65 | Accept |            2.173 |            4.8092 |            2.173 |           2.1731 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      200 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   66 | Accept |           4.1439 |          0.060669 |            2.173 |           2.1731 |          svm | BoxConstraint:     0.011536 |
|      |        |                  |                   |                  |                  |              | KernelScale:      0.0039517 |
|      |        |                  |                   |                  |                  |              | Epsilon:          0.0090597 |
|   67 | Best   |            2.173 |             8.695 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      300 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   68 | Accept |            2.173 |            5.0512 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      202 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   69 | Accept |            2.173 |            7.5798 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      299 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   70 | Accept |            2.173 |            4.8479 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      200 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|=========================================================================================================================================|
| Iter | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|=========================================================================================================================================|
|   71 | Accept |            2.173 |            7.5734 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      300 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   72 | Accept |            2.173 |            7.4612 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      299 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   73 | Accept |            2.173 |            4.7911 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      200 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   74 | Accept |            2.173 |             7.333 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      299 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   75 | Accept |            2.173 |            7.0648 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      277 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   76 | Accept |            2.173 |            4.9778 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      200 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   77 | Accept |            2.173 |            4.6684 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      200 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   78 | Accept |            2.173 |            7.1746 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      297 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   79 | Accept |           2.1763 |            5.5721 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      230 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              2 |
|   80 | Accept |            2.173 |            4.9422 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      200 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|=========================================================================================================================================|
| Iter | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|=========================================================================================================================================|
|   81 | Accept |            2.173 |            7.4431 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      298 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   82 | Accept |            2.173 |            7.4708 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      299 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   83 | Accept |            2.173 |            4.8532 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      202 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   84 | Accept |            2.173 |            7.3628 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      300 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   85 | Accept |            2.173 |            5.8364 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      240 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   86 | Accept |            2.173 |             4.821 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      200 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   87 | Accept |            2.173 |            5.4126 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      220 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   88 | Accept |            2.173 |            7.9721 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      300 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   89 | Accept |            2.173 |            6.8672 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      275 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   90 | Accept |            2.173 |            4.9636 |            2.173 |            2.173 |     ensemble | Method:             LSBoost |
|      |        |                  |                   |                  |                  |              | NumLearningCycles:      216 |
|      |        |                  |                   |                  |                  |              | MinLeafSize:              1 |

__________________________________________________________
Optimization completed.
Total iterations: 90
Total elapsed time: 643.9812 seconds
Total time for training and validation: 401.0444 seconds

Best observed learner is an ensemble model with:
	Method:             LSBoost
	NumLearningCycles:      300
	MinLeafSize:              1
Observed log(1 + valLoss): 2.173
Time for training and validation: 8.695 seconds

Best estimated learner (returned model) is an ensemble model with:
	Method:             LSBoost
	NumLearningCycles:      300
	MinLeafSize:              1
Estimated log(1 + valLoss): 2.173
Estimated time for training and validation: 7.5797 seconds

Documentation for fitrauto display

The final model returned by fitrauto corresponds to the best estimated learner. Before returning the model, the function retrains it using the entire training data (carsTrain), the listed Learner (or model) type, and the displayed hyperparameter values.

Evaluate Test Set Performance

Evaluate the performance of the model on the test set. testError is based on the test set mean squared error (MSE). Smaller MSE values indicate better performance.

testMSE = loss(Mdl,carsTest,"MPG");
testError = log(1 + testMSE)
testError = 2.2971

Use fitrauto to automatically select a regression model with optimized hyperparameters, given predictor and response data stored in separate variables.

Load Data

Load the carbig data set, which contains measurements of cars made in the 1970s and early 1980s.

load carbig

Create a matrix X containing the predictor variables Acceleration, Cylinders, and so on. Store the response variable MPG in the variable Y.

X = [Acceleration Cylinders Displacement Weight];
Y = MPG;

Create a variable indicating which predictors are categorical. Cylinders is the only categorical variable in X.

categoricalVars = [false true false false];

Partition Data

Partition the data into training and test sets. Use approximately 80% of the observations for the model selection and hyperparameter tuning process, and 20% of the observations to test the performance of the final model returned by fitrauto. Use cvpartition to partition the data.

rng("default") % For reproducibility of the partition
c = cvpartition(length(Y),"Holdout",0.20);
trainingIdx = training(c); % Indices for the training set
XTrain = X(trainingIdx,:);
YTrain = Y(trainingIdx);
testIdx = test(c); % Indices for the test set
XTest = X(testIdx,:);
YTest = Y(testIdx);

Run fitrauto

Pass the training data to fitrauto. By default, fitrauto determines appropriate model (or learner) types to try, uses Bayesian optimization to find good hyperparameter values for those models, and returns a trained model Mdl with the best expected performance. Specify the categorical predictors, and run the optimization in parallel (requires Parallel Computing Toolbox™). Return a second output OptimizationResults that contains the details of the Bayesian optimization.

Expect this process to take some time. By default, fitrauto provides a plot of the optimization and an iterative display of the optimization results. For more information on how to interpret these results, see Verbose Display.

options = struct("UseParallel",true);
[Mdl,OptimizationResults] = fitrauto(XTrain,YTrain, ...
    "CategoricalPredictors",categoricalVars, ...
    "HyperparameterOptimizationOptions",options);
Starting parallel pool (parpool) using the 'local' profile ...
Connected to the parallel pool (number of workers: 6).
Copying objective function to workers...
Done copying objective function to workers.
Learner types to explore: ensemble, svm, tree
Total iterations (MaxObjectiveEvaluations): 90
Total time (MaxTime): Inf

|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|    1 |       5 | Best   |           3.0205 |            1.4452 |           3.0205 |           3.0329 |         tree | MinLeafSize:              6 |
|    2 |       5 | Accept |           3.0453 |             1.431 |           3.0205 |           3.0329 |         tree | MinLeafSize:              5 |
|    3 |       5 | Accept |            4.143 |            2.2922 |           3.0205 |           3.0329 |          svm | BoxConstraint:       336.91 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:      0.0018275 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             0.1074 |
|    4 |       5 | Accept |            4.143 |           0.59844 |           3.0205 |           3.0329 |          svm | BoxConstraint:       346.92 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:       0.032493 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:            0.23974 |
|    5 |       6 | Best   |           2.9275 |           0.30064 |           2.9275 |           2.9275 |          svm | BoxConstraint:     0.033068 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         585.38 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             4.6993 |
|    6 |       5 | Accept |           4.1439 |            6.9662 |           2.9275 |           2.9275 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      257 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:            156 |
|    7 |       5 | Accept |           2.9275 |           0.83001 |           2.9275 |           2.9275 |          svm | BoxConstraint:     0.033068 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         585.38 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             4.6993 |
|    8 |       4 | Accept |            2.938 |            9.5987 |           2.9275 |           2.9275 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      287 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|    9 |       4 | Accept |            4.143 |           0.15524 |           2.9275 |           2.9275 |          svm | BoxConstraint:       48.997 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:      0.0045904 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             18.085 |
|   10 |       6 | Accept |            4.143 |           0.18295 |           2.9275 |           2.9275 |          svm | BoxConstraint:    0.0021787 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:       0.018209 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             443.71 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   11 |       4 | Best   |           2.8597 |            8.2455 |           2.8597 |           2.9275 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      278 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             13 |
|   12 |       4 | Accept |            4.143 |           0.64902 |           2.8597 |           2.9275 |          svm | BoxConstraint:    0.0021787 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:       0.018209 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             443.71 |
|   13 |       4 | Accept |            4.143 |           0.52394 |           2.8597 |           2.9275 |          svm | BoxConstraint:    0.0021787 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:       0.018209 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             443.71 |
|   14 |       5 | Accept |           3.2501 |           0.21659 |           2.8597 |           2.9275 |         tree | MinLeafSize:              1 |
|   15 |       5 | Accept |           3.2501 |           0.15812 |           2.8597 |           2.9275 |         tree | MinLeafSize:              1 |
|   16 |       4 | Accept |           2.9167 |            7.7641 |           2.8597 |           2.9275 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      287 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             63 |
|   17 |       4 | Accept |           3.2501 |            0.1166 |           2.8597 |           2.9275 |         tree | MinLeafSize:              1 |
|   18 |       4 | Accept |           3.1971 |           0.37955 |           2.8597 |           2.9275 |         tree | MinLeafSize:              2 |
|   19 |       2 | Accept |           3.6673 |            21.933 |           2.8597 |           2.9276 |          svm | BoxConstraint:     0.033502 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         153.38 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:           0.093672 |
|   20 |       2 | Accept |           2.8734 |            6.5786 |           2.8597 |           2.9276 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      283 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             17 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   21 |       2 | Accept |            4.143 |          0.089152 |           2.8597 |           2.9276 |          svm | BoxConstraint:       37.028 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:       0.033731 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             0.2457 |
|   22 |       6 | Accept |           3.3225 |             0.186 |           2.8597 |           2.9276 |         tree | MinLeafSize:            122 |
|   23 |       4 | Accept |           2.9536 |           0.15373 |           2.8597 |           2.9276 |         tree | MinLeafSize:             11 |
|   24 |       4 | Accept |            4.143 |            0.2424 |           2.8597 |           2.9276 |          svm | BoxConstraint:       240.91 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:      0.0063646 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             92.342 |
|   25 |       4 | Accept |           2.9969 |            0.2371 |           2.8597 |           2.9276 |         tree | MinLeafSize:             40 |
|   26 |       4 | Accept |           3.1971 |          0.087498 |           2.8597 |           2.9276 |         tree | MinLeafSize:              2 |
|   27 |       3 | Accept |           3.0259 |            5.4043 |           2.8597 |           2.8589 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      247 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             83 |
|   28 |       3 | Accept |           2.8673 |            5.2056 |           2.8597 |           2.8589 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      234 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             31 |
|   29 |       6 | Accept |           2.9403 |          0.060585 |           2.8597 |           2.8589 |         tree | MinLeafSize:             13 |
|   30 |       4 | Accept |            2.868 |            4.3862 |           2.8597 |           2.8589 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      229 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             52 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   31 |       4 | Accept |           3.3587 |           0.46693 |           2.8597 |           2.8589 |         tree | MinLeafSize:            109 |
|   32 |       4 | Accept |           3.1971 |           0.32157 |           2.8597 |           2.8589 |         tree | MinLeafSize:              2 |
|   33 |       4 | Accept |           3.2501 |          0.078839 |           2.8597 |           2.8589 |         tree | MinLeafSize:              1 |
|   34 |       4 | Accept |           2.8708 |            5.4437 |           2.8597 |           2.8595 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      235 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             26 |
|   35 |       3 | Best   |           2.8244 |            5.9186 |           2.8244 |           2.8595 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      275 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              4 |
|   36 |       3 | Accept |            3.112 |          0.053088 |           2.8244 |           2.8595 |         tree | MinLeafSize:             62 |
|   37 |       6 | Accept |           2.8872 |            5.1029 |           2.8244 |           2.8245 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      214 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              4 |
|   38 |       5 | Accept |           2.9282 |          0.095731 |           2.8244 |           2.8245 |          svm | BoxConstraint:      0.20553 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         880.29 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             4.5637 |
|   39 |       5 | Accept |            4.143 |          0.087217 |           2.8244 |           2.8245 |          svm | BoxConstraint:       26.303 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:        0.40313 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:              228.3 |
|   40 |       2 | Accept |           2.8652 |            5.7512 |           2.8242 |           2.8242 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      280 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             45 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   41 |       2 | Accept |           3.0951 |            5.1977 |           2.8242 |           2.8242 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      250 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             70 |
|   42 |       2 | Best   |           2.8242 |            5.2948 |           2.8242 |           2.8242 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      207 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              8 |
|   43 |       2 | Accept |           2.9041 |            5.4999 |           2.8242 |           2.8242 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      233 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              2 |
|   44 |       5 | Accept |           2.9804 |          0.074442 |           2.8242 |           2.8242 |         tree | MinLeafSize:              8 |
|   45 |       5 | Accept |           3.3765 |          0.047037 |           2.8242 |           2.8242 |         tree | MinLeafSize:            117 |
|   46 |       4 | Accept |            4.143 |          0.095028 |           2.8242 |           2.8242 |          svm | BoxConstraint:     0.032384 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         797.08 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             64.843 |
|   47 |       4 | Accept |            4.143 |          0.061103 |           2.8242 |           2.8242 |          svm | BoxConstraint:       28.209 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         77.831 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             21.256 |
|   48 |       3 | Accept |           2.8452 |            3.6683 |           2.8242 |           2.8243 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      200 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   49 |       3 | Accept |           2.8655 |            4.0616 |           2.8242 |           2.8243 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      202 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   50 |       6 | Accept |            4.143 |           0.10804 |           2.8242 |           2.8243 |          svm | BoxConstraint:       267.23 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:       0.028148 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:           0.097477 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   51 |       3 | Accept |           4.8036 |            16.322 |           2.8193 |           2.8188 |          svm | BoxConstraint:     0.006061 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         127.62 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:          0.0090183 |
|   52 |       3 | Best   |           2.8193 |            4.0637 |           2.8193 |           2.8188 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      200 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             23 |
|   53 |       3 | Accept |           2.8228 |            6.0192 |           2.8193 |           2.8188 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      298 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              5 |
|   54 |       3 | Accept |           2.8448 |            5.0715 |           2.8193 |           2.8188 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      249 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              2 |
|   55 |       6 | Accept |           3.2501 |          0.077577 |           2.8193 |           2.8188 |         tree | MinLeafSize:              1 |
|   56 |       4 | Accept |           2.9351 |          0.098541 |           2.8193 |           2.8188 |          svm | BoxConstraint:     0.015396 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         707.02 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             1.8654 |
|   57 |       4 | Accept |            4.143 |          0.062758 |           2.8193 |           2.8188 |          svm | BoxConstraint:      0.20213 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:        0.56699 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             803.81 |
|   58 |       4 | Accept |            4.143 |          0.076261 |           2.8193 |           2.8188 |          svm | BoxConstraint:     0.001047 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:      0.0019199 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:              4.501 |
|   59 |       4 | Accept |           2.8469 |            3.5621 |           2.8193 |           2.8223 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      200 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             35 |
|   60 |       5 | Accept |           2.8288 |            3.9552 |           2.8193 |           2.8223 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      207 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             14 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   61 |       5 | Accept |            4.143 |          0.066618 |           2.8193 |           2.8223 |          svm | BoxConstraint:     0.043338 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:       0.026299 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:           0.057475 |
|   62 |       5 | Accept |            4.143 |            31.142 |           2.8193 |           2.8223 |          svm | BoxConstraint:       13.655 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         4.3086 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             6.9116 |
|   63 |       4 | Accept |           2.8697 |            7.1892 |           2.8193 |           2.8223 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      291 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              8 |
|   64 |       4 | Accept |            4.143 |          0.051217 |           2.8193 |           2.8223 |          svm | BoxConstraint:       164.25 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:            422 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             709.16 |
|   65 |       4 | Accept |           15.816 |            29.101 |           2.8193 |           2.8223 |          svm | BoxConstraint:        280.6 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         20.045 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             2.9565 |
|   66 |       4 | Accept |           2.8697 |             6.626 |           2.8193 |           2.8224 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      300 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              8 |
|   67 |       3 | Accept |            4.143 |            30.413 |           2.8193 |           2.8223 |          svm | BoxConstraint:       1.3468 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         9.6762 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:           0.023868 |
|   68 |       3 | Accept |           2.8398 |            7.0162 |           2.8193 |           2.8223 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      386 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              3 |
|   69 |       3 | Accept |           2.8358 |            6.4998 |           2.8193 |           2.8223 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      344 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             21 |
|   70 |       3 | Accept |            4.143 |          0.076191 |           2.8193 |           2.8223 |          svm | BoxConstraint:       6.1442 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:       0.068257 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             5.7363 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   71 |       3 | Accept |            4.143 |          0.066335 |           2.8193 |           2.8223 |          svm | BoxConstraint:     0.027503 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:      0.0041093 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:           0.051041 |
|   72 |       3 | Accept |            4.143 |           0.07249 |           2.8193 |           2.8223 |          svm | BoxConstraint:      0.52138 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:        0.43854 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:            0.67088 |
|   73 |       5 | Accept |           2.8214 |            3.9165 |           2.8193 |           2.8215 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      207 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              6 |
|   74 |       5 | Accept |           2.8872 |            6.1359 |           2.8193 |           2.8215 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      252 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              4 |
|   75 |       3 | Accept |           2.9284 |          0.054998 |           2.8193 |           2.8215 |         tree | MinLeafSize:             20 |
|   76 |       3 | Accept |           2.8468 |             3.983 |           2.8193 |           2.8215 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      225 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             33 |
|   77 |       3 | Accept |           2.9969 |           0.10337 |           2.8193 |           2.8215 |         tree | MinLeafSize:             40 |
|   78 |       6 | Accept |           3.0866 |          0.058426 |           2.8193 |           2.8215 |          svm | BoxConstraint:    0.0070395 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         988.24 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:          0.0096375 |
|   79 |       5 | Accept |            4.143 |          0.094698 |           2.8193 |           2.8215 |          svm | BoxConstraint:       954.83 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:      0.0016114 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             45.114 |
|   80 |       5 | Accept |           3.2501 |          0.083131 |           2.8193 |           2.8215 |         tree | MinLeafSize:              1 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   81 |       3 | Accept |            4.143 |             6.269 |           2.8193 |           2.8215 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      294 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:            162 |
|   82 |       3 | Accept |           2.8742 |            6.9216 |           2.8193 |           2.8215 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      293 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             27 |
|   83 |       3 | Accept |            4.143 |          0.051169 |           2.8193 |           2.8215 |          svm | BoxConstraint:      0.47136 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:        0.11232 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:           0.058234 |
|   84 |       2 | Accept |            9.656 |            19.111 |           2.8193 |           2.8215 |          svm | BoxConstraint:       121.18 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         196.01 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:           0.010913 |
|   85 |       2 | Accept |            4.143 |            6.6385 |           2.8193 |           2.8215 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      294 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:            162 |
|   86 |       2 | Accept |           3.0281 |          0.055432 |           2.8193 |           2.8215 |         tree | MinLeafSize:             57 |
|   87 |       2 | Accept |           3.1971 |           0.10328 |           2.8193 |           2.8215 |         tree | MinLeafSize:              2 |
|   88 |       2 | Accept |           3.1507 |          0.081176 |           2.8193 |           2.8215 |         tree | MinLeafSize:              3 |
|   89 |       6 | Accept |           2.8507 |            5.7074 |           2.8193 |           2.8214 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | NumLearningCycles:      275 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|   90 |       5 | Accept |            4.143 |          0.078128 |           2.8193 |           2.8214 |          svm | BoxConstraint:       220.96 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         28.058 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             66.219 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   91 |       5 | Accept |            4.143 |            0.0599 |           2.8193 |           2.8214 |          svm | BoxConstraint:        8.342 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         70.835 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             38.428 |

__________________________________________________________
Optimization completed.
Total iterations: 91
Total elapsed time: 174.9553 seconds
Total time for training and validation: 350.9822 seconds

Best observed learner is an ensemble model with:
	Method:                 Bag
	NumLearningCycles:      200
	MinLeafSize:             23
Observed log(1 + valLoss): 2.8193
Time for training and validation: 4.0637 seconds

Best estimated learner (returned model) is an ensemble model with:
	Method:                 Bag
	NumLearningCycles:      207
	MinLeafSize:              6
Estimated log(1 + valLoss): 2.8214
Estimated time for training and validation: 4.0733 seconds

Documentation for fitrauto display

The final model returned by fitrauto corresponds to the best estimated learner. Before returning the model, the function retrains it using the entire training data (XTrain and YTrain), the listed Learner (or model) type, and the displayed hyperparameter values.

Evaluate Test Set Performance

Evaluate the performance of the model on the test set. testError is based on the test set mean squared error (MSE). Smaller MSE values indicate better performance.

testMSE = loss(Mdl,XTest,YTest);
testError = log(1 + testMSE)
testError = 2.8921

Use fitrauto to automatically select a regression model with optimized hyperparameters, given predictor and response data stored in a table. Compare the performance of the resulting regression model to the performance of a simple linear regression model created with fitlm.

Load and Partition Data

Load the carbig data set, which contains measurements of cars made in the 1970s and early 1980s. Convert the Cylinders variable to a categorical variable. Create a table containing the predictor variables Acceleration, Cylinders, Displacement, and so on, as well as the response variable MPG.

load carbig
Cylinders = categorical(Cylinders);
cars = table(Acceleration,Cylinders,Displacement, ...
    Horsepower,Model_Year,Origin,Weight,MPG);

Partition the data into training and test sets. Use approximately 80% of the observations for training, and 20% of the observations for testing. Use cvpartition to partition the data.

rng("default") % For reproducibility of the data partition
c = cvpartition(length(MPG),"Holdout",0.2);
trainingIdx = training(c); % Training set indices
carsTrain = cars(trainingIdx,:);
testIdx = test(c); % Test set indices
carsTest = cars(testIdx,:);

Run fitrauto

Pass the training data to fitrauto. By default, fitrauto determines appropriate model types to try, uses Bayesian optimization to find good hyperparameter values, and returns a trained model autoMdl with the best expected performance. Specify to optimize over all optimizable hyperparameters and run the optimization in parallel (requires Parallel Computing Toolbox™).

Expect this process to take some time. By default, fitrauto provides a plot of the optimization and an iterative display of the optimization results. For more information on how to interpret these results, see Verbose Display.

options = struct("UseParallel",true);
autoMdl = fitrauto(carsTrain,"MPG","OptimizeHyperparameters","all", ...
    "HyperparameterOptimizationOptions",options);
Starting parallel pool (parpool) using the 'local' profile ...
Connected to the parallel pool (number of workers: 6).
Copying objective function to workers...
Done copying objective function to workers.
Learner types to explore: ensemble, svm, tree
Total iterations (MaxObjectiveEvaluations): 90
Total time (MaxTime): Inf

|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|    1 |       4 | Accept |           3.1825 |            1.8704 |           2.6934 |           2.6935 |         tree | MinLeafSize:             38 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:             2 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     1 |
|    2 |       4 | Accept |           2.8075 |            1.8645 |           2.6934 |           2.6935 |         tree | MinLeafSize:              1 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:            44 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     4 |
|    3 |       4 | Best   |           2.6934 |             1.854 |           2.6934 |           2.6935 |         tree | MinLeafSize:             29 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:            52 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     6 |
|    4 |       4 | Accept |           4.1439 |            2.6026 |           2.6934 |           2.6935 |          svm | BoxConstraint:     0.010718 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         1.7547 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:              182.6 |
|    5 |       2 | Accept |           2.4136 |            7.0256 |           2.2154 |           2.6935 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | LearnRate:          0.64294 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             39 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:   NaN |
|    6 |       2 | Best   |           2.2154 |            7.7597 |           2.2154 |           2.6935 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | LearnRate:         0.033855 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              6 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:   NaN |
|    7 |       2 | Accept |           4.1439 |           0.27852 |           2.2154 |           2.6935 |          svm | BoxConstraint:     0.012677 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         351.81 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             140.99 |
|    8 |       6 | Accept |           4.1439 |           0.85944 |           2.2154 |           2.6935 |          svm | BoxConstraint:       37.191 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         21.113 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             33.874 |
|    9 |       6 | Accept |           2.7394 |            1.4707 |           2.2154 |           2.6935 |          svm | BoxConstraint:     0.057859 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         448.87 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             4.2169 |
|   10 |       4 | Accept |           2.5848 |            5.8685 |           2.2154 |           2.4611 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | LearnRate:          0.89898 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              2 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:   NaN |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   11 |       4 | Accept |           2.6816 |             5.073 |           2.2154 |           2.4611 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             51 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     2 |
|   12 |       4 | Accept |           2.4608 |           0.25674 |           2.2154 |           2.4611 |         tree | MinLeafSize:              6 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:            32 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     5 |
|   13 |       4 | Accept |           3.2336 |            6.4662 |           2.2154 |           2.4611 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | LearnRate:          0.56281 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:            123 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:   NaN |
|   14 |       6 | Accept |            2.845 |           0.35832 |           2.2154 |           2.4611 |          svm | BoxConstraint:    0.0027083 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         413.17 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:            0.13572 |
|   15 |       4 | Accept |           2.7122 |            5.2558 |           2.2154 |           2.4611 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | LearnRate:          0.74839 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             88 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:   NaN |
|   16 |       4 | Accept |            2.845 |            0.9025 |           2.2154 |           2.4611 |          svm | BoxConstraint:    0.0027083 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         413.17 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:            0.13572 |
|   17 |       4 | Accept |            2.845 |           0.81343 |           2.2154 |           2.4611 |          svm | BoxConstraint:    0.0027083 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         413.17 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:            0.13572 |
|   18 |       3 | Accept |           2.6527 |            4.4298 |           2.2154 |           2.4723 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             46 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     2 |
|   19 |       3 | Accept |           2.5035 |           0.29266 |           2.2154 |           2.4723 |         tree | MinLeafSize:              5 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:            18 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     5 |
|   20 |       6 | Accept |           2.8243 |           0.15229 |           2.2154 |           2.4616 |         tree | MinLeafSize:             12 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:             5 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     2 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   21 |       4 | Accept |            4.143 |          0.064514 |           2.2154 |           2.4607 |         tree | MinLeafSize:            132 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:             8 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     5 |
|   22 |       4 | Accept |            4.143 |           0.18836 |           2.2154 |           2.4607 |         tree | MinLeafSize:            138 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:             3 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     7 |
|   23 |       4 | Accept |           3.3663 |           0.13449 |           2.2154 |           2.4607 |         tree | MinLeafSize:             83 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:            41 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     2 |
|   24 |       3 | Accept |           2.3614 |             4.546 |           2.2154 |           2.4607 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              2 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     2 |
|   25 |       3 | Accept |           4.1439 |           0.58435 |           2.2154 |           2.4607 |          svm | BoxConstraint:    0.0050384 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:        0.18651 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             11.818 |
|   26 |       6 | Accept |           4.1439 |           0.07419 |           2.2154 |           2.4607 |          svm | BoxConstraint:      0.19519 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:        0.48473 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:            0.02267 |
|   27 |       6 | Accept |           2.5796 |          0.081162 |           2.2154 |           2.4613 |         tree | MinLeafSize:              8 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:            85 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     5 |
|   28 |       5 | Accept |           5.9862 |             5.516 |           2.2154 |           2.4622 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | LearnRate:         0.001143 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:            104 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:   NaN |
|   29 |       5 | Accept |           2.6716 |          0.071817 |           2.2154 |           2.4622 |         tree | MinLeafSize:              6 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:            43 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     2 |
|   30 |       2 | Accept |           4.1439 |            33.722 |           2.2154 |           2.4815 |          svm | BoxConstraint:      0.15265 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         1.4893 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:            0.44287 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   31 |       2 | Accept |           2.2534 |            6.2607 |           2.2154 |           2.4815 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             12 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     7 |
|   32 |       2 | Accept |           2.9788 |            6.8285 |           2.2154 |           2.4815 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | LearnRate:         0.010155 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             13 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:   NaN |
|   33 |       2 | Accept |           2.7529 |          0.055823 |           2.2154 |           2.4815 |         tree | MinLeafSize:              1 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:           123 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     2 |
|   34 |       6 | Accept |           3.0557 |            0.4318 |           2.2154 |            2.494 |         tree | MinLeafSize:             42 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:             4 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     4 |
|   35 |       3 | Accept |           4.1439 |           0.27218 |           2.2154 |            2.494 |          svm | BoxConstraint:       2.1967 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:        0.02117 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:            0.20631 |
|   36 |       3 | Accept |           3.2946 |          0.066155 |           2.2154 |            2.494 |         tree | MinLeafSize:             88 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:             2 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     2 |
|   37 |       3 | Accept |           4.1439 |           0.13289 |           2.2154 |            2.494 |          svm | BoxConstraint:       127.62 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:      0.0010166 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             16.049 |
|   38 |       3 | Accept |           4.1439 |           0.12273 |           2.2154 |            2.494 |          svm | BoxConstraint:       77.831 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         11.323 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             24.046 |
|   39 |       6 | Accept |           4.1439 |          0.090716 |           2.2154 |            2.494 |          svm | BoxConstraint:       1.5262 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:        0.16982 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:            0.09432 |
|   40 |       5 | Accept |           4.1439 |          0.060884 |           2.2154 |            2.494 |          svm | BoxConstraint:       347.06 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:       0.024995 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:           0.012891 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   41 |       5 | Accept |           4.1439 |          0.078944 |           2.2154 |            2.494 |          svm | BoxConstraint:     0.017688 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         968.17 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             350.72 |
|   42 |       4 | Accept |           2.5097 |            14.423 |           2.1926 |           2.1939 |          svm | BoxConstraint:       5.9191 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         699.18 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:           0.010916 |
|   43 |       4 | Best   |           2.1926 |            6.6572 |           2.1926 |           2.1939 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | LearnRate:          0.03225 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              6 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:   NaN |
|   44 |       4 | Accept |           4.1439 |          0.055712 |           2.1926 |           2.1939 |          svm | BoxConstraint:   0.00076626 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:        0.27348 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:            0.18351 |
|   45 |       2 | Accept |           13.985 |            32.958 |           2.1926 |           2.1967 |          svm | BoxConstraint:       797.08 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         43.175 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             4.1489 |
|   46 |       2 | Accept |           4.1439 |            30.972 |           2.1926 |           2.1967 |          svm | BoxConstraint:     0.067167 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         6.6015 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:           0.010914 |
|   47 |       2 | Accept |           2.2235 |            6.0717 |           2.1926 |           2.1967 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | LearnRate:         0.022919 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:   NaN |
|   48 |       6 | Accept |           4.1439 |          0.054027 |           2.1926 |           2.1967 |          svm | BoxConstraint:       1.4081 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         1068.3 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             47.856 |
|   49 |       2 | Accept |           2.5906 |            4.7498 |           2.1926 |           2.0428 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | LearnRate:          0.96713 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             14 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:   NaN |
|   50 |       2 | Accept |           4.1439 |          0.080148 |           2.1926 |           2.0428 |          svm | BoxConstraint:       19.339 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         336.27 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             745.75 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   51 |       2 | Accept |           2.4027 |           0.12426 |           2.1926 |           2.0428 |         tree | MinLeafSize:              8 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:            80 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     5 |
|   52 |       2 | Accept |           3.3875 |            0.1023 |           2.1926 |           2.0428 |         tree | MinLeafSize:             84 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:             4 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     7 |
|   53 |       2 | Accept |           4.1439 |          0.050927 |           2.1926 |           2.0428 |          svm | BoxConstraint:       94.294 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:      0.0014232 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:          0.0090047 |
|   54 |       6 | Accept |            4.859 |            6.2453 |           2.1926 |           2.2036 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | LearnRate:        0.0040831 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             10 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:   NaN |
|   55 |       1 | Accept |            2.624 |            4.7525 |           2.1926 |           2.2036 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             51 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     6 |
|   56 |       1 | Accept |           2.7473 |          0.060583 |           2.1926 |           2.2036 |         tree | MinLeafSize:              9 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:           204 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     2 |
|   57 |       1 | Accept |           4.1439 |          0.066677 |           2.1926 |           2.2036 |          svm | BoxConstraint:    0.0012156 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:       0.015427 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:           0.060481 |
|   58 |       1 | Accept |           4.1439 |          0.094823 |           2.1926 |           2.2036 |          svm | BoxConstraint:      0.44269 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:       0.004171 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:            0.12586 |
|   59 |       1 | Accept |           3.0883 |            0.0586 |           2.1926 |           2.2036 |         tree | MinLeafSize:             23 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:             4 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     2 |
|   60 |       1 | Accept |           4.1439 |          0.056798 |           2.1926 |           2.2036 |          svm | BoxConstraint:     0.038648 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         1.6731 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             181.22 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   61 |       6 | Accept |           4.1439 |          0.067435 |           2.1926 |           2.2036 |          svm | BoxConstraint:    0.0073804 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:        0.26555 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:          0.0091652 |
|   62 |       2 | Accept |           2.4796 |            4.6971 |           2.1926 |           2.2036 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              5 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     1 |
|   63 |       2 | Accept |           2.5862 |          0.087002 |           2.1926 |           2.2036 |         tree | MinLeafSize:              2 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:            36 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     4 |
|   64 |       2 | Accept |           2.5227 |            4.8002 |           2.1926 |           2.2036 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             35 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     5 |
|   65 |       2 | Accept |           2.2692 |            5.7741 |           2.1926 |           2.2036 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | LearnRate:         0.025248 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             29 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:   NaN |
|   66 |       2 | Accept |           4.1439 |          0.061232 |           2.1926 |           2.2036 |          svm | BoxConstraint:     0.015213 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         121.18 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             228.77 |
|   67 |       6 | Accept |           3.0619 |           0.20501 |           2.1926 |           2.2036 |         tree | MinLeafSize:              8 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:            37 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     1 |
|   68 |       2 | Accept |           4.1439 |            32.145 |           2.1926 |           2.1946 |          svm | BoxConstraint:     0.023727 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         2.1083 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:           0.026879 |
|   69 |       2 | Accept |           2.2059 |            6.3033 |           2.1926 |           2.1946 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | LearnRate:         0.030274 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              9 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:   NaN |
|   70 |       2 | Accept |           2.5736 |            5.4884 |           2.1926 |           2.1946 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | LearnRate:         0.015531 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             76 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:   NaN |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   71 |       2 | Accept |           2.2438 |            6.4062 |           2.1926 |           2.1946 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              6 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     7 |
|   72 |       2 | Accept |           4.1429 |            4.1039 |           2.1926 |           2.1946 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:            134 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     2 |
|   73 |       5 | Accept |            4.143 |            4.4894 |           2.1926 |           2.1946 |     ensemble | Method:             LSBoost |
|      |         |        |                  |                   |                  |                  |              | LearnRate:          0.17357 |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:            177 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:   NaN |
|   74 |       5 | Accept |           4.1439 |          0.054069 |           2.1926 |           2.1946 |          svm | BoxConstraint:       2.4711 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:     0.00086032 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:            0.65606 |
|   75 |       3 | Accept |           4.1439 |           0.09691 |           2.1926 |           2.1949 |          svm | BoxConstraint:       131.74 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:      0.0031145 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:           0.028465 |
|   76 |       3 | Accept |            4.143 |          0.092964 |           2.1926 |           2.1949 |         tree | MinLeafSize:            156 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:             1 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     5 |
|   77 |       3 | Accept |           2.3039 |            4.4363 |           2.1926 |           2.1949 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              9 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     3 |
|   78 |       5 | Accept |           2.6824 |          0.088024 |           2.1926 |           2.1949 |         tree | MinLeafSize:             11 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:             6 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     3 |
|   79 |       5 | Accept |           4.1439 |          0.065162 |           2.1926 |           2.1949 |          svm | BoxConstraint:    0.0010003 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:        0.85686 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             699.42 |
|   80 |       2 | Accept |           10.894 |            31.235 |           2.1926 |           2.1952 |          svm | BoxConstraint:      0.05924 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         16.477 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:              1.204 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   81 |       2 | Accept |           2.3629 |             4.051 |           2.1926 |           2.1952 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              2 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     2 |
|   82 |       2 | Accept |           3.3755 |          0.057721 |           2.1926 |           2.1952 |         tree | MinLeafSize:             79 |
|      |         |        |                  |                   |                  |                  |              | MaxNumSplits:            65 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     3 |
|   83 |       2 | Accept |           2.3673 |            4.0629 |           2.1926 |           2.1952 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              1 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     2 |
|   84 |       6 | Accept |           2.6199 |            4.7274 |           2.1926 |           2.1952 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             53 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     6 |
|   85 |       2 | Accept |           3.1414 |            4.2529 |           2.1926 |           2.1985 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             75 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     7 |
|   86 |       2 | Accept |           2.2514 |            5.0768 |           2.1926 |           2.1985 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              4 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     5 |
|   87 |       2 | Accept |           4.1439 |          0.077312 |           2.1926 |           2.1985 |          svm | BoxConstraint:       230.13 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:         15.715 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             425.18 |
|   88 |       2 | Accept |           4.1439 |           0.06662 |           2.1926 |           2.1985 |          svm | BoxConstraint:       10.758 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:       0.020507 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:             4.9755 |
|   89 |       2 | Accept |           2.2525 |            6.0028 |           2.1926 |           2.1985 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:              2 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     7 |
|   90 |       5 | Accept |           2.5768 |            4.4924 |           2.1926 |           2.1985 |     ensemble | Method:                 Bag |
|      |         |        |                  |                   |                  |                  |              | LearnRate:              NaN |
|      |         |        |                  |                   |                  |                  |              | MinLeafSize:             40 |
|      |         |        |                  |                   |                  |                  |              | NumVariablesToSample:     5 |
|===================================================================================================================================================|
| Iter | Active  | Eval   | log(1 + valLoss) | Time for training | Observed min     | Estimated min    | Learner      | Hyperparameter:       Value |
|      | workers | result |                  | & validation (sec)| log(1 + valLoss) | log(1 + valLoss) |              |                             |
|===================================================================================================================================================|
|   91 |       5 | Accept |           4.1439 |          0.062303 |           2.1926 |           2.1985 |          svm | BoxConstraint:       2.5681 |
|      |         |        |                  |                   |                  |                  |              | KernelScale:        0.19989 |
|      |         |        |                  |                   |                  |                  |              | Epsilon:            0.59994 |

__________________________________________________________
Optimization completed.
Total iterations: 91
Total elapsed time: 279.9304 seconds
Total time for training and validation: 366.0998 seconds

Best observed learner is an ensemble model with:
	Method:             LSBoost
	LearnRate:          0.03225
	MinLeafSize:              6
	NumVariablesToSample:   NaN
Observed log(1 + valLoss): 2.1926
Time for training and validation: 6.6572 seconds

Best estimated learner (returned model) is an ensemble model with:
	Method:             LSBoost
	LearnRate:          0.03225
	MinLeafSize:              6
	NumVariablesToSample:   NaN
Estimated log(1 + valLoss): 2.1985
Estimated time for training and validation: 6.572 seconds

Documentation for fitrauto display

The final model returned by fitrauto corresponds to the best estimated learner. Before returning the model, the function retrains it using the entire training data (carsTrain), the listed Learner (or model) type, and the displayed hyperparameter values.

Create Simple Model

Create a simple linear regression model linearMdl by using the fitlm function.

linearMdl = fitlm(carsTrain);

Although the linearMdl object does not have the exact same properties and methods as the autoMdl object, you can use both models to predict response values for new data by using the predict object function.

Compare Test Set Performance of Models

Compare the performance of the linearMdl and autoMdl models on the test data set. For each model, compute the test set mean squared error (MSE). Smaller MSE values indicate better performance.

ypred = predict(linearMdl,carsTest);
linearMSE = mean((carsTest.MPG-ypred).^2,"omitnan")
linearMSE = 11.0981
autoMSE = loss(autoMdl,carsTest,"MPG")
autoMSE = 8.8322

The autoMdl model seems to outperform the linearMdl model.

Input Arguments

collapse all

Sample data, specified as a table. Each row of Tbl corresponds to one observation, and each column corresponds to one predictor. Optionally, Tbl can contain one additional column for the response variable. Multicolumn variables and cell arrays other than cell arrays of character vectors are not accepted.

If Tbl contains the response variable, and you want to use all remaining variables in Tbl as predictors, specify the response variable using ResponseVarName.

If Tbl contains the response variable, and you want to use only a subset of the remaining variables in Tbl as predictors, specify a formula using formula.

If Tbl does not contain the response variable, specify a response variable using Y. The length of the response variable and the number of rows in Tbl must be equal.

Data Types: table

Response variable name, specified as the name of a variable in Tbl. The response variable must be a numeric vector.

You must specify ResponseVarName as a character vector or string scalar. For example, if the response variable Y is stored as Tbl.Y, then specify it as "Y". Otherwise, the software treats all columns of Tbl, including Y, as predictors when training a model.

Data Types: char | string

Explanatory model of the response variable and a subset of the predictor variables, specified as a character vector or string scalar in the form "Y~x1+x2+x3". In this form, Y represents the response variable, and x1, x2, and x3 represent the predictor variables.

To specify a subset of variables in Tbl as predictors for training the model, use a formula. If you specify a formula, then the software does not use any variables in Tbl that do not appear in formula.

The variable names in the formula must be both variable names in Tbl (Tbl.Properties.VariableNames) and valid MATLAB® identifiers. You can verify the variable names in Tbl by using the isvarname function. If the variable names are not valid, then you can convert them by using the matlab.lang.makeValidName function.

Data Types: char | string

Response data, specified as a numeric vector. The length of Y must be equal to the number of rows in Tbl or X.

To specify the response variable name, use the ResponseName name-value argument.

Data Types: single | double

Predictor data, specified as a numeric matrix.

Each row of X corresponds to one observation, and each column corresponds to one predictor.

The length of Y and the number of rows in X must be equal.

To specify the names of the predictors in the order of their appearance in X, use the PredictorNames name-value argument.

Data Types: single | double

Note

The software treats NaN, empty character vector (''), empty string (""), <missing>, and <undefined> elements as missing data. The software removes rows of data corresponding to missing values in the response variable. However, the treatment of missing values in the predictor data X or Tbl varies among models (or learners).

Name-Value Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: "HyperparameterOptimizationOptions",struct("MaxObjectiveEvaluations",200,"Verbose",2) specifies to run 200 iterations of the optimization process (that is, try 200 model hyperparameter combinations), and to display information in the Command Window about the next model hyperparameter combination to be evaluated.
Optimizer Options

collapse all

Types of regression models to try during the optimization, specified as a value in the first table below or one or more learner names in the second table. Specify multiple learner names as a string or cell array.

ValueDescription
"auto"fitrauto automatically selects a subset of learners, suitable for the given predictor and response data. The learners can have model hyperparameter values that differ from the default. For more information, see Automatic Selection of Learners.
"all"fitrauto selects all possible learners.
"all-linear"fitrauto selects linear ("linear") learners.
"all-nonlinear"fitrauto selects all nonlinear learners: "ensemble", "gp", "kernel", "svm" (with a Gaussian or polynomial kernel), and "tree".

Note

For greater efficiency, fitrauto does not select the following combinations of models when you specify one of the previous values.

  • "kernel" and "svm" (with a Gaussian kernel) — fitrauto chooses the first when the predictor data has more than 11,000 observations, and the second otherwise.

  • "linear" and "svm" (with a linear kernel) — fitrauto chooses the first.

Learner NameDescription
"ensemble"Ensemble regression model
"gp"Gaussian process regression model
"kernel"Kernel regression model
"linear"Linear regression model for high-dimensional data
"svm"Support vector machine regression model
"tree"Binary decision regression tree

Example: "Learners","all"

Example: "Learners","ensemble"

Example: "Learners",["gp","svm"]

Hyperparameters to optimize, specified as "auto" or "all". The optimizable hyperparameters depend on the model (or learner), as described in this table.

Learner NameHyperparameters for "auto"Additional Hyperparameters for "all"Notes
"ensemble"Method, NumLearningCycles, LearnRate, MinLeafSizeMaxNumSplits, NumVariablesToSample

When the ensemble Method value is a boosting method, the ensemble NumBins value is 50.

For more information, including hyperparameter search ranges, see OptimizeHyperparameters. Note that you cannot change hyperparameter search ranges when you use fitrauto.

"gp"SigmaBasisFunction, KernelFunction, KernelScale (KernelParameters), Standardize

The fitrauto function ignores all ARD kernel options and, therefore, chooses among the KernelFunction values of "exponential", "matern32", "matern52", "rationalquadratic", and "squaredexponential" when the OptimizeHyperparameters value is "all".

For more information, including hyperparameter search ranges, see OptimizeHyperparameters. Note that you cannot change hyperparameter search ranges when you use fitrauto.

"kernel"Epsilon, KernelScale, LambdaLearner, NumExpansionDimensionsFor more information, including hyperparameter search ranges, see OptimizeHyperparameters. Note that you cannot change hyperparameter search ranges when you use fitrauto.
"linear"Lambda, LearnerRegularizationFor more information, including hyperparameter search ranges, see OptimizeHyperparameters. Note that you cannot change hyperparameter search ranges when you use fitrauto.
"svm"BoxConstraint, Epsilon, KernelScaleKernelFunction, PolynomialOrder, Standardize

  • When the Learners value is "all-linear", the fitrauto function does not optimize the KernelFunction or PolynomialOrder hyperparameters when the OptimizeHyperparameters value is "all".

  • When the Learners value is "all-nonlinear", the fitrauto function chooses among the KernelFunction values of "gaussian" and "polynomial", regardless of the OptimizeHyperparameters value.

For more information, including hyperparameter search ranges, see OptimizeHyperparameters. Note that you cannot change hyperparameter search ranges when you use fitrauto.

"tree"MinLeafSizeMaxNumSplitsFor more information, including hyperparameter search ranges, see OptimizeHyperparameters. Note that you cannot change hyperparameter search ranges when you use fitrauto.

Note

When Learners is set to a value other than "auto", the default values for the model hyperparameters not being optimized match the default fit function values, unless otherwise indicated in the table notes. When Learners is set to "auto", the optimized hyperparameter search ranges and nonoptimized hyperparameter values can vary, depending on the characteristics of the training data. For more information, see Automatic Selection of Learners.

Example: "OptimizeHyperparameters","all"

Options for the optimization, specified as a structure. All fields in the structure are optional.

Field NameValuesDefault
Optimizer
"bayesopt"
MaxObjectiveEvaluationsMaximum number of iterations (objective function evaluations), specified as a positive integer

30*L, where L is the number of learners (see Learners)

  • This value is the default when the Optimizer field is set to "bayesopt".

  • For the default value when the Optimizer field is set to "asha", see Number of ASHA Iterations.

MaxTime

Time limit, specified as a positive real number. The time limit is in seconds, as measured by tic and toc. Run time can exceed MaxTime because MaxTime does not interrupt function evaluations.

Inf
ShowPlotsLogical value indicating whether to show a plot of the optimization progress. If true, this field plots the observed minimum validation loss against the iteration number. When you use Bayesian optimization, the plot also shows the estimated minimum validation loss.true
SaveIntermediateResultsLogical value indicating whether to save results. If true, this field overwrites a workspace variable at each iteration. The variable is a BayesianOptimization object named BayesoptResults if you use Bayesian optimization, and a table named ASHAResults if you use ASHA optimization.false
Verbose

Display at the command line:

  • 0 — No iterative display

  • 1 — Iterative display

  • 2 — Iterative display with additional information about the next point to be evaluated

1
UseParallelLogical value indicating whether to run the optimization in parallel, which requires Parallel Computing Toolbox™. Due to the nonreproducibility of parallel timing, parallel optimization does not necessarily yield reproducible results.false
Repartition

Logical value indicating whether to repartition the cross-validation at every iteration. If false, the optimizer uses a single partition for the optimization.

true usually gives the most robust results because this setting takes partitioning noise into account. However, for good results, true requires at least twice as many function evaluations.

false
MaxTrainingSetSize

Maximum number of observations in each training set for ASHA optimization, specified as a positive integer. This value matches the largest training set size.

Note

If you want to specify this value, the Optimizer field must be set to "asha".

Largest available training partition size

  • When the optimization uses k-fold cross-validation, this value is (k – 1)*n/k, where n is the total number of observations.

  • When the optimization uses a cvpartition object cvp, this value is max(cvp.TrainSize).

  • When the optimization uses a holdout fraction p, this value is (1 – p)*n, where n is the total number of observations.

MinTrainingSetSize

Minimum number of observations in each training set for ASHA optimization, specified as a positive integer. This value is a lower bound for the smallest training set size.

Note

If you want to specify this value, the Optimizer field must be set to "asha".

100
Specify only one of the following three options.
CVPartitioncvpartition object, created by cvpartition"Kfold",5 if you do not specify any cross-validation field
HoldoutScalar in the range (0,1) representing the holdout fraction
KfoldInteger greater than 1

Example: "HyperparameterOptimizationOptions",struct("UseParallel",true)

Regression Options

collapse all

Categorical predictors list, specified as one of the values in this table.

ValueDescription
Vector of positive integers

Each entry in the vector is an index value indicating that the corresponding predictor is categorical. The index values are between 1 and p, where p is the number of predictors used to train the model.

If fitrauto uses a subset of input variables as predictors, then the function indexes the predictors using only the subset. The CategoricalPredictors values do not count the response variable, observation weight variable, or any other variables that the function does not use.

Logical vector

A true entry means that the corresponding predictor is categorical. The length of the vector is p.

Character matrixEach row of the matrix is the name of a predictor variable. The names must match the entries in PredictorNames. Pad the names with extra blanks so each row of the character matrix has the same length.
String array or cell array of character vectorsEach element in the array is the name of a predictor variable. The names must match the entries in PredictorNames.
"all"All predictors are categorical.

By default, if the predictor data is in a table (Tbl), fitrauto assumes that a variable is categorical if it is a logical vector, categorical vector, character array, string array, or cell array of character vectors. However, learners that use decision trees assume that mathematically ordered categorical vectors are continuous variables. If the predictor data is a matrix (X), fitrauto assumes that all predictors are continuous. To identify any other predictors as categorical predictors, specify them by using the CategoricalPredictors name-value argument.

For more information on how fitting functions treat categorical predictors, see Automatic Creation of Dummy Variables.

Example: "CategoricalPredictors","all"

Data Types: single | double | logical | char | string | cell

Predictor variable names, specified as a string array of unique names or cell array of unique character vectors. The functionality of PredictorNames depends on the way you supply the training data.

  • If you supply X and Y, then you can use PredictorNames to assign names to the predictor variables in X.

    • The order of the names in PredictorNames must correspond to the column order of X. That is, PredictorNames{1} is the name of X(:,1), PredictorNames{2} is the name of X(:,2), and so on. Also, size(X,2) and numel(PredictorNames) must be equal.

    • By default, PredictorNames is {'x1','x2',...}.

  • If you supply Tbl, then you can use PredictorNames to choose which predictor variables to use in training. That is, fitrauto uses only the predictor variables in PredictorNames and the response variable during training.

    • PredictorNames must be a subset of Tbl.Properties.VariableNames and cannot include the name of the response variable.

    • By default, PredictorNames contains the names of all predictor variables.

    • A good practice is to specify the predictors for training using either PredictorNames or formula, but not both.

Example: "PredictorNames",["SepalLength","SepalWidth","PetalLength","PetalWidth"]

Data Types: string | cell

Response variable name, specified as a character vector or string scalar.

  • If you supply Y, then you can use ResponseName to specify a name for the response variable.

  • If you supply ResponseVarName or formula, then you cannot use ResponseName.

Example: "ResponseName","response"

Data Types: char | string

Observation weights, specified as a positive numeric vector or the name of a variable in Tbl. The software weights each observation in X or Tbl with the corresponding value in Weights. The length of Weights must equal the number of rows in X or Tbl.

If you specify the input data as a table Tbl, then Weights can be the name of a variable in Tbl that contains a numeric vector. In this case, you must specify Weights as a character vector or string scalar. For example, if the weights vector W is stored as Tbl.W, then specify it as "W". Otherwise, the software treats all columns of Tbl, including W, as predictors or the response variable when training the model.

By default, Weights is ones(n,1), where n is the number of observations in X or Tbl.

The software normalizes Weights to sum to 1.

Data Types: single | double | char | string

Output Arguments

collapse all

Trained regression model, returned as one of the regression model objects in this table.

Optimization results, returned as a BayesianOptimization object if you use Bayesian optimization or a table if you use ASHA optimization. For more information, see Bayesian Optimization and ASHA Optimization.

More About

collapse all

Verbose Display

When you set the Verbose field of the HyperparameterOptimizationOptions name-value argument to 1 or 2, the fitrauto function provides an iterative display of the optimization results.

The following table describes the columns in the display and their entries.

Column NameDescription
IterIteration number — You can set a limit to the number of iterations by using the MaxObjectiveEvaluations field of the HyperparameterOptimizationOptions name-value argument.
Active workersNumber of active parallel workers — This column appears only when you run the optimization in parallel by setting the UseParallel field of the HyperparameterOptimizationOptions name-value argument to true.
Eval result

One of the following evaluation results:

  • Best — The learner and hyperparameter values at this iteration give the minimum observed validation loss computed so far. That is, the log(1 + valLoss) value is the smallest computed so far.

  • Accept — The learner and hyperparameter values at this iteration give meaningful (for example, non-NaN) validation loss values.

  • Error — The learner and hyperparameter values at this iteration result in an error (for example, a log(1 + valLoss) value of NaN).

log(1 + valLoss)Log-transformed validation loss computed for the learner and hyperparameter values at this iteration — In particular, fitrauto computes log(1 + valLoss), where valLoss is the cross-validation mean squared error (MSE) by default. You can change the validation scheme by using the CVPartition, Holdout, or Kfold field of the 'HyperparameterOptimizationOptions' name-value argument.
Time for training & validation (sec)Time taken to train and compute the validation loss for the model with the learner and hyperparameter values at this iteration (in seconds) — When you use Bayesian optimization, this value excludes the time required to update the objective function model maintained by the Bayesian optimization process. For more details, see Bayesian Optimization.
Observed min log(1 + valLoss)

Observed minimum log-transformed validation loss computed so far — This value corresponds to the smallest log(1 + valLoss) value computed so far in the optimization process.

By default, fitrauto returns a plot of the optimization that displays dark blue points for the observed minimum log-transformed validation loss values. This plot does not appear when the ShowPlots field of the HyperparameterOptimizationOptions name-value argument is set to false.

Estimated min log(1 + valLoss)

Estimated minimum log-transformed validation loss — When you use Bayesian optimization, fitrauto updates, at each iteration, an objective function model maintained by the Bayesian optimization process, and uses this model to estimate the minimum log-transformed validation loss. For more details, see Bayesian Optimization.

By default, fitrauto returns a plot of the optimization that displays light blue points for the estimated minimum log-transformed validation loss values. This plot does not appear when the ShowPlots field of the HyperparameterOptimizationOptions name-value argument is set to false.

Note

This column appears only when you use Bayesian optimization, that is, when the Optimizer field of the HyperparameterOptimizationOptions name-value argument is set to "bayesopt".

Training set size

Number of observations used in each training set at this iteration — Use the MaxTrainingSetSize and MinTrainingSetSize fields of the HyperparameterOptimizationOptions name-value argument to specify bounds for the training set size. For more details, see ASHA Optimization.

Note

This column appears only when you use ASHA optimization, that is, when the Optimizer field of the HyperparameterOptimizationOptions name-value argument is set to "asha".

LearnerModel type evaluated at this iteration — Specify the learners used in the optimization by using the Learners name-value argument.
Hyperparameter: ValueHyperparameter values at this iteration — Specify the hyperparameters used in the optimization by using the OptimizeHyperparameters name-value argument.

The display also includes these model descriptions:

  • Best observed learner — This model, with the listed learner type and hyperparameter values, yields the final observed minimum validation loss (log-transformed). When you use ASHA optimization, fitrauto retrains the model on the entire training data set and returns it as the Mdl output.

  • Best estimated learner — This model, with the listed learner type and hyperparameter values, yields the final estimated minimum validation loss (log-transformed) when you use Bayesian optimization. In this case, fitrauto retrains the model on the entire training data set and returns it as the Mdl output.

    Note

    The Best estimated learner model appears only when you use Bayesian optimization, that is, when the Optimizer field of the HyperparameterOptimizationOptions name-value argument is set to "bayesopt".

Tips

  • Depending on the size of your data set, the number of learners you specify, and the optimization method you choose, fitrauto can take some time to run.

    • If you have a Parallel Computing Toolbox license, you can speed up computations by running the optimization in parallel. To do so, specify "HyperparameterOptimizationOptions",struct("UseParallel",true). You can include additional fields in the structure to control other aspects of the optimization. See HyperparameterOptimizationOptions.

    • If fitrauto with Bayesian optimization takes a long time to run because of the number of observations in your training set (for example, over 10,000), consider using fitrauto with ASHA optimization instead. ASHA optimization often finds good solutions faster than Bayesian optimization for data sets with many observations. To use ASHA optimization, specify "HyperparameterOptimizationOptions",struct("Optimizer","asha"). You can include additional fields in the structure to control additional aspects of the optimization. In particular, if you have a time constraint, specify the MaxTime field of the HyperparameterOptimizationOptions structure to limit the number of seconds fitrauto runs.

Algorithms

collapse all

Automatic Selection of Learners

When you specify "Learners","auto", the fitrauto function analyzes the predictor and response data in order to choose appropriate learners. The function considers whether the data set has any of these characteristics:

  • Categorical predictors

  • Missing values for more than 5% of the data

  • Wide data, where the number of predictors is greater than or equal to the number of observations

  • High-dimensional data, where the number of predictors is greater than 100

  • Large data, where the number of observations is greater than 50,000

The selected learners are always a subset of those listed in the Learners table. However, the associated models tried during the optimization process can have different default values for hyperparameters not being optimized, as well as different search ranges for hyperparameters being optimized.

Bayesian Optimization

The goal of Bayesian optimization, and optimization in general, is to find a point that minimizes an objective function. In the context of fitrauto, a point is a learner type together with a set of hyperparameter values for the learner (see Learners and OptimizeHyperparameters), and the objective function is log(1 + valLoss), where valLoss is the cross-validation mean squared error (MSE), by default. The Bayesian optimization implemented in fitrauto internally maintains a multi-RegressionGP model of the objective function. That is, the objective function model splits along the learner type and, for a given learner, the model is a Gaussian process regression (GPR) model. (This underlying model differs from the single GPR model employed by other Statistics and Machine Learning Toolbox™ functions that use Bayesian optimization.) Bayesian optimization trains the underlying model by using objective function evaluations, and determines the next point to evaluate by using an acquisition function ("expected-improvement"). For more information, see Expected Improvement. The acquisition function balances between sampling at points with low modeled objective function values and exploring areas that are not well modeled yet. At the end of the optimization, fitrauto chooses the point with the minimum objective function model value, among the points evaluated during the optimization. For more information, see the "Criterion","min-visited-mean" name-value argument of bestPoint.

ASHA Optimization

The asynchronous successive halving algorithm (ASHA) in fitrauto randomly chooses several models with different hyperparameter values (see Learners and OptimizeHyperparameters) and trains them on a small subset of the training data. If the performance of a particular model is promising, the model is promoted and trained on a larger amount of the training data. This process repeats, and successful models are trained on progressively larger amounts of data. By default, at the end of the optimization, fitrauto chooses the model that has the lowest log(1 + valLoss) value, where valLoss is the cross-validation mean squared error (MSE).

At each iteration, ASHA either chooses a previously trained model and promotes it (that is, retrains the model using more training data), or selects a new model (learner type and hyperparameter values) using random search. ASHA promotes models as follows:

  • The algorithm searches for the group of models with the largest training set size for which this condition does not hold: floor(g/4) of the models have been promoted, where g is the number of models in the group.

  • Among the group of models, ASHA chooses the model with the lowest log(1 + valLoss) value and retrains that model with 4*(Training Set Size) observations.

  • If no such group of models exists, then ASHA selects a new model instead of promoting an old one, and trains the new model using the smallest training set size.

When a model is trained on a subset of the training data, ASHA computes the cross-validation MSE in the as follows:

  • For each training fold, the algorithm selects a random sample of the observations (of size Training set size) using nonstratified sampling, and then trains a model on that subset of data.

  • The algorithm then tests the fitted model on the test fold (that is, the observations not in the training fold) and computes the MSE.

  • Finally, the algorithm averages the results across all folds.

For more information on ASHA, see [1].

Number of ASHA Iterations

When you use ASHA optimization, the default number of iterations depends on the number of observations in the data, the number of learner types, the use of parallel processing, and the type of cross-validation. The algorithm selects the number of iterations such that, for L learner types (see Learners), fitrauto trains L models on the largest training set size.

This table describes the default number of iterations based on the given specifications when you use 5-fold cross-validation. Note that n represents the number of observations and L represents the number of learner types.

Number of Observations

n

Default Number of Iterations

(run in serial)

Default Number of Iterations

(run in parallel)

n < 50030*Ln is too small to implement ASHA optimization, and fitrauto implements random search to find and assess models instead.30*Ln is too small to implement ASHA optimization, and fitrauto implements random search to find and assess models instead.
500 ≤ n < 20005*L5*(L + 1)
2000 ≤ n < 800021*L21*(L + 1)
8000 ≤ n < 32,00085*L85*(L + 1)
32,000 ≤ n341*L341*(L + 1)

Alternative Functionality

  • If you are unsure which models work best for your data set, you can alternatively use the Regression Learner app. Using the app, you can perform hyperparameter tuning for different models, and choose the optimized model that performs best. Although you must select a specific model before you can tune the model hyperparameters, Regression Learner provides greater flexibility for selecting optimizable hyperparameters and setting hyperparameter values. The app also allows you to train a variety of linear regression models (see Linear Regression Models). However, you cannot optimize in parallel, optimize "linear" or "kernel" learners, specify observation weights, or use ASHA optimization in the app. For more information, see Hyperparameter Optimization in Regression Learner App.

  • If you know which models might suit your data, you can alternatively use the corresponding model fit functions and specify the OptimizeHyperparameters name-value argument to tune hyperparameters. You can compare the results across the models to select the best regression model. For an example of this process applied to classification models, see Moving Towards Automating Model Selection Using Bayesian Optimization.

References

[1] Li, Liam, Kevin Jamieson, Afshin Rostamizadeh, Ekaterina Gonina, Moritz Hardt, Benjamin Recht, and Ameet Talwalkar. “A System for Massively Parallel Hyperparameter Tuning.” ArXiv:1810.05934v5 [Cs], March 16, 2020. https://arxiv.org/abs/1810.05934v5.

Extended Capabilities

Introduced in R2020b