主要内容

火车Classifier Using Hyperparameter Optimization in Classification Learner App

此示例显示如何通过在分类学习者应用程序中使用HyperParameter Optimization来调整分类支持向量机(SVM)模型的金宝appHyperParameters。将培训的优化SVM的测试设置性能与最佳性能预设SVM模型的测试设置性能进行比较。

  1. 在matlab.®命令窗口,加载ionosphere数据集,并创建包含数据的表。

    loadionosphereTBL.= array2table(X); tbl.Y = Y;
  2. Open Classification Learner. Click theApps选项卡,然后单击右侧的箭头Apps要打开Apps Gallery的部分。在里面机器学习和深度学习group, click分类学习者

  3. 在这方面分类学习者标签,在文件section, select新会话>从工作区

  4. 在里面New Session from Workspace dialog box, selectTBL.来自Data Set Variablelist. The app selects the response and predictor variables. The default response variable isY。这default validation option is 5-fold cross-validation, to protect against overfitting.

    在里面Test部分,单击复选框以拨出测试数据集。指定使用15percent of the imported data as a test set.

    New Session from Workspace dialog box with 15 percent of the imported data set aside for testing

  5. 要接受选项并继续,请单击开始课程

  6. 培训所有预设的SVM型号。在这方面分类学习者标签,在楷模部分,单击箭头打开的n the gallery. In theSupport Vector Machinesgroup, click所有SVMS。在里面火车section, click火车All和select火车All。这app trains one of each SVM model type, as well as the default fine tree model, and displays the models in the楷模窗格。

    Note

    • 如果您有并行计算工具箱™,则该应用程序具有使用并行默认情况下按钮切换。点击后火车All和select火车All或者列车选择, the app opens a parallel pool of workers. During this time, you cannot interact with the software. After the pool opens, you can continue to interact with the app while models train in parallel.

    • 如果您没有并行计算工具箱,则该应用程序具有使用背景培训复选框火车All默认选择的菜单。点击培训模型后,该应用程序将打开一个背景池。池后,您可以继续与应用程序进行互动,而模型在背景中列车。

    Validation confusion matrix of the ionosphere data modeled by a linear SVM model

    该应用程序显示第一个SVM模型的验证混淆矩阵(模型2.1)。蓝色值表示正确的分类,红色值表示不正确的分类。这楷模pane on the left shows the validation accuracy for each model.

    Note

    Validation introduces some randomness into the results. Your model validation results can vary from the results shown in this example.

  7. Select an optimizable SVM model to train. On the分类学习者标签,在楷模部分,单击箭头打开的n the gallery. In theSupport Vector Machinesgroup, click优化的SVM

  8. Select the model hyperparameters to optimize. In the概括tab, you can select优化复选框the hyperparameters that you want to optimize. By default, all the check boxes for the available hyperparameters are selected. For this example, clear the优化复选框Kernel function标准化数据。By default, the app disables the优化复选框Kernel scalewhenever the kernel function has a fixed value other thanGaussian。Select aGaussiankernel function, and select the优化复选框Kernel scale

    SVM HyperParameters的摘要选项卡选择优化

  9. 培训可优化的型号。在里面火车section of the分类学习者tab, click火车All和select列车选择

  10. 这个应用程序显示一个最小分类错误情节当它运行优化过程时。在每次迭代时,该应用程序尝试不同的HyperParameter值组合,并使用最小验证分类错误更新绘图,该映射由深蓝色表示的迭代。当应用程序完成优化过程时,它会选择由红场指示的优化的超参数集。有关更多信息,请参阅最小分类错误情节

    这app lists the optimized hyperparameters in both the优化结果情节右侧的部分和优化的SVM模型超参数模型的一部分概括tab.

    最低可优化SVM模型的最小分类错误图

    Note

    In general, the optimization results are not reproducible.

  11. Compare the trained preset SVM models to the trained optimizable model. In the楷模窗格,应用程序突出显示最高准确性(验证)通过在一个盒子里勾勒出来。在此示例中,训练有素的优化SVM模型优于六个预设模型。

    训练有素的可优化型号并不总是比训练有素的预设型号更高的精度。如果训练有素的可优化型号不表现良好,则可以尝试通过运行更长时间的优化来获得更好的结果。在这方面分类学习者标签,在Optionssection, click优化r。在对话框中,增加迭代value. For example, you can double-click the default value of30并输入价值60。这n click保存并申请。这options will be applied to future optimizable models created using the楷模gallery.

  12. Because hyperparameter tuning often leads to overfitted models, check the performance of the optimizable SVM model on a test set and compare it to the performance of the best preset SVM model. Use the data you reserved for testing when you imported data into the app.

    首先,在楷模pane, click the star icons next to theMedium Gaussian SVMmodel and the优化的SVMmodel.

  13. For each model, select the model in the楷模窗格。在里面Testsection of the分类学习者tab, clickTest All然后选择测试选择。这app computes the test set performance of the model trained on the rest of the data, namely the training and validation data.

  14. Sort the models based on the test set accuracy. In the楷模pane, open the排序方式list and selectAccuracy (Test)

    在此示例中,训练有素的可优化模型仍然优于测试集数据上的训练的预设模型。但是,两种模型都没有像验证精度一样高的测试精度。

    火车ed models sorted by test accuracy

  15. Visually compare the test set performance of the models. For each of the starred models, select the model in the楷模窗格。在这方面分类学习者标签,在Plots部分,单击箭头打开的n the gallery, and then click混乱矩阵(测试)在里面测试结果团体。

  16. Rearrange the layout of the plots to better compare them. First, close the plot and summary tabs for all models exceptModel 2.5Model 3。然后,在里面Plots部分,单击Layout按钮和选择比较模型。Click the Hide plot options button在地块的右上角,为情节制作更多空间。

    测试集合模型的混淆矩阵

    To return to the original layout, you can click theLayout按钮和选择Single model (Default)

相关话题