Main Content

Train Neural Network Classifiers Using Classification Learner App

此示例显示了如何在分类学习者应用程序中创建和比较神经网络分类器,并将培训的模型导出到工作区以对新数据进行预测。

  1. 在里面马铃薯草®命令窗口,加载fisheririsdata set, and create a table from the variables in the data set to use for classification.

    渔业技术= readtable(“fisheriris.csv”);
  2. 点击the应用选项卡,然后单击显示更多右侧的箭头打开Apps Gallery。在里面Machine Learning and Deep Learning组,点击分类Learner

  3. 在这方面分类Learnertab, in theFile部分,点击New Session并选择来自工作区

    分类学习者选项卡

  4. 在里面New Session from Workspace dialog box, select the table渔业技术from the数据集变量列表(如有必要)。观察该应用程序基于其数据类型选择了选定的响应和预测变量。花瓣和萼片长度和宽度是预测因子,并且物种是您想要分类的响应。对于此示例,请勿更改选择。

  5. To accept the default validation scheme and continue, clickStart Session。默认验证选项是5倍交叉验证,以防止过度装备。

    分类Learner creates a scatter plot of the data.

  6. Use the scatter plot to investigate which variables are useful for predicting the response. Select different options in theXandy列表Predictorsto visualize the distribution of species and measurements. Note which variables separate the species colors most clearly.

  7. 创建一系列神经网络模型。在这方面分类Learnertab, in theModels部分,单击箭头以打开图库。在里面神经网络分类器组,点击所有神经网络

  8. 在里面Train部分,点击训练所有并选择训练所有

    笔记

    • If you have Parallel Computing Toolbox™, then the app has theUse Parallelbutton toggled on by default. After you click训练所有并选择训练所有orTrain Selected,该应用程序打开了一个平行的工人池。在此期间,您无法与软件进行互动。池开放后,您可以在并行模型列车时继续与应用程序进行交互。

    • If you do not have Parallel Computing Toolbox, then the app has the使用背景培训check box in the训练所有menu selected by default. After you click to train models, the app opens a background pool. After the pool opens, you can continue to interact with the app while models train in the background.

    分类Learner trains one of each neural network classification option in the gallery, as well as the default fine tree model. In theModels窗格,应用程序概述了Accuracy (Validation)score of the best model. Classification Learner also displays a validation confusion matrix for the first neural network model (Narrow Neural Network)。

  9. Select a model in theModels窗格查看结果。例如,双击Narrow Neural Network模型(2.1型)。检查模型Summary标签,显示培训结果在验证集上计算的指标。

  10. Examine the scatter plot for the trained model. On the分类Learnertab, in the绘图部分,单击箭头以打开图库,然后单击Scatterin theValidation Results团体。Correctly classified points are marked with an O, and incorrectly classified points are marked with an X.

    由神经网络分类器建模的Fisher IRIS数据的散点图

    笔记

    验证将一些随机性引入结果。您的模型验证结果可能因此示例中显示的结果而异。

  11. Inspect the accuracy of the predictions in each class. On the分类Learnertab, in the绘图部分,单击箭头以打开图库,然后单击混乱矩阵(验证)in theValidation Results团体。查看真实类和预测类结果的矩阵。

  12. For each remaining model, select the model in theModels窗格,打开验证混淆矩阵,然后将结果与模型进行比较。

  13. Choose the best model in theModels窗格(最佳分数在突出显示Accuracy (Validation)box). See if you can improve the model by removing features with low predictive power.

    首先重复最好的模型。在这方面分类Learnertab, in theModels部分,点击Duplicate

  14. 要调查包含或排除的功能,请使用并行坐标绘图。在这方面分类Learnertab, in the绘图部分,单击箭头以打开图库,然后单击Parallel Coordinatesin theValidation Results团体。

    您可以指定在模型中培训期间使用的预测器Summary标签。点击Feature Selectionto expand the section, and specify predictors to remove from the model.

  15. 或者,您可以使用特征排名算法来确定在模型培训期间使用的功能。在这方面分类Learnertab, in the选项部分,点击Feature Selection。在里面默认功能选择选项卡,指定要使用的特征排名算法。指定要保持最高排名功能的功能数量。您可以使用条形图来帮助确定要使用的功能。

    点击Save and Apply保存更改。新功能选择应用于现有的现有模型Modelspane and will be applied to new draft models that you create using the gallery in theModels部分分类Learner标签。

  16. 训练模型。在这方面分类Learnertab, in theTrain部分,点击训练所有并选择Train Selected使用新选项培训模型。比较分类器之间的结果Models窗格。

  17. Choose the best model in theModels窗格。要尝试更好地改进模型,请更改其普遍参数。首先,使用该模型复制模型Duplicate按钮在Modelssection. Then, try changing hyperparameter settings, like the sizes of the fully connected layers or the regularization strength, in the modelSummary标签。点击培训新模型训练所有并选择Train Selectedin theTrainsection.

    要了解有关神经网络模型设置的更多信息,请参阅神经网络分类器

  18. 您可以将培训的模型的完整或紧凑版本的版本导出到工作区。在这方面分类Learnertab, in theExport部分,点击出口模式并选择任一个出口模式or出口紧凑型号。SeeExport Classification Model to Predict New Data

  19. To examine the code for training this classifier, click生成函数in theExportsection.

提示

使用相同的工作流程来评估和比较您可以在分类学习者中培训的其他分类器类型。

要培训所有非优化的分类器模型预设,可用于数据集:

  1. 在这方面分类Learnertab, in theModels部分,单击箭头以打开模型图库。

  2. 在里面开始组,点击All。Then, in theTrain部分,点击训练所有并选择训练所有

    Option selected for training all available classifier types

要了解其他分类器类型,请参阅Train Classification Models in Classification Learner App

Related Topics