Matlab Use Machine Learning Apps
MathWorksOfficialCreated by MathWorks
- Skill
- Tool integration
- Data and AI
- BSD-2-Clause
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides an automated interface for driving MATLAB's Classification Learner and Regression Learner apps. It enables users to train, evaluate, and compare various machine learning models, perform hyperparameter tuning, and export models for deployment in environments like Simulink, MATLAB Coder, or production servers. The agent manages the app lifecycle, data partitioning, and model interpretability analysis, ensuring a streamlined workflow from data import to final model export.
What it does
- Opens and manages Classification Learner and Regression Learner app sessions.
- Automates model training, validation, and performance metric evaluation.
- Facilitates model comparison using interactive plots and results tables.
- Provides tools for model interpretability, including Shapley, LIME, and partial dependence plots.
- Exports trained models to the workspace, Simulink, Coder, or production environments.
- Generates reproducible training code for integration into larger MATLAB workflows.
When to use it
- When you need to interactively train and compare multiple machine learning models.
- When you require a guided workflow for model validation and performance testing.
- When you need to deploy models to embedded systems, Simulink, or web services.
- When you need to explain model decisions using advanced interpretability techniques.
- When you want to automate the training process while maintaining the ability to inspect results.
Advantages
- Reduces manual effort by automating repetitive app interactions.
- Ensures consistent validation schemes and testing procedures.
- Provides seamless export paths to professional deployment targets.
- Simplifies complex tasks like hyperparameter optimization and feature selection.
- Enables programmatic access to visual insights and model diagnostics.
Usage examples
- “I have a dataset in my workspace and I want to find the best classification model.”
- The agent will open the Classification Learner app, guide you through selecting the response variable, configure the validation scheme, and begin training multiple model types for comparison.
- “Can you help me export my trained model to Simulink?”
- The agent will verify if your model is compatible with Simulink, perform any necessary checks, and execute the export command to generate the required model files.
- “I need to explain why my model is making certain predictions.”
- The agent will configure and display interpretability plots like Shapley or LIME to help you visualize predictor importance and local model behavior.
- “Generate a script that reproduces my current training workflow.”
- The agent will trigger the code generation feature to create a standalone MATLAB script that replicates the preprocessing, training, and validation steps performed in the app.
Install
16 of its files are not mirrored here, so install it from its source:
https://github.com/matlab/matlab-agentic-toolkit/tree/2a7f215e965597acf6ed495beb9e7b8aff45a3be/skills-catalog/ai-and-statistics/matlab-use-machine-learning-apps
Documentation by MathWorks
Learner Apps AppController Reference
mlearnapp.internal.appcontroller.AppController provides programmatic access to the Classification Learner and Regression Learner apps. Use it to interact with learner apps and query their state.
Source (loaded at runtime): <skill-base-directory>/scripts/+mlearnapp/+internal/+appcontroller/AppController.p
API Reference (load on demand)
| When you need... | Load this file |
|---|---|
| Open/close/save/load app, session setup, create/train/select/delete models, model status, GalleryModels enum | api-session-and-models.md |
| Metrics, model spec queries, toolstrip buttons, set feature selection/PCA/optimizer/cost/hyperparameters | api-metrics-and-options.md |
| Open/configure standard plots, results table, standard plot data getters | api-plots.md |
| PDP, permutation importance, Shapley, LIME, Set Shapley Parameters, explainability plot data getters | api-explainability.md |
| Export methods, command logging, diagnostics | api-export-and-diagnostics.md |
Required: Statistics and Machine Learning Toolbox. Optional: Parallel Computing Toolbox (parallel training), Deep Learning Toolbox (only for Deep Learning models introduced in R2026a — FullyConnected, Residual, All; plain Neural Network models added in R2024a ship with Statistics and Machine Learning Toolbox), Simulink (Simulink export), MATLAB Coder (Coder export), MATLAB Compiler SDK (Production Server export).
When to Use
User wants to train, compare, or export models (to workspace, Simulink, Coder, or Production Server), generate training code, or run advanced hyperparameter tuning (via Experiment Manager) using Classification Learner or Regression Learner
User asks to open, drive, or automate either learner app
User wants to compare multiple model types interactively with validation metrics
User needs to test a model on held-out data or separate test data and export from the app
When NOT to Use
User wants command-line ML without the app — use
fitc*/fitr*functions directlyCustom deep learning with non-tabular data (images, sequences, text) — use Deep Learning Toolbox directly
Data preprocessing or cleaning — must be done before importing into the app
IMPORTANT
Do not expose API to users. This API is for agent's internal use only. Never mention AppController, programmatic access, or automation APIs to the user. Drive the app silently on the user's behalf. When greeting the user after this skill loads, simply ask about their goals (dataset, export target, constraints) without referencing the underlying mechanism.
Never use
closeApp('Force', true)without explicit user permission. Force-closing skips the save confirmation dialog and silently discards all unsaved work — trained models, session state, and results are permanently lost. Always prefercloseApp()(without Force) so the user gets a chance to save. Only use'Force', truewhen: (1) the user explicitly permits it, or (2) automated testing where no human is present.
Setup
When this skill is invoked, add the skill's scripts folder to the MATLAB path so that mlearnapp.internal.appcontroller classes are available. The scripts folder is located relative to this skill's base directory at scripts/. Run this via the MATLAB MCP evaluate_matlab_code tool, using the skill's base directory path shown at the top of the skill load message:
addpath('<skill-base-directory>/scripts');For example, if the skill base directory is C:\MATLAB\AgenticAI\.claude\skills\matlab-use-machine-learning-apps, then:
addpath('C:\MATLAB\AgenticAI\.claude\skills\matlab-use-machine-learning-apps\scripts');User Goals Inquiry
Before starting any workflow, gather the information below so the session can be configured up front without wasted training cycles. Each item lists what the agent needs to know (internal use) and how to ask the user (in plain terms — avoid ML terminology unless the user's vocabulary shows they're comfortable with it).
End goal / where will the model be used?
Agent needs to know: target of
exportModelTo*— workspace, Simulink, Coder, Production Server, Experiment Manager, or exploratory. Drives constraints (no categorical predictors for Simulink, model support lists for Coder/Simulink, etc.).Ask the user: "How will the model ultimately be used? For example: exploring the data, generating a report or figure, running inside a Simulink simulation, generating C/C++ code for an embedded device, deploying as a web service, or making predictions in MATLAB."
Validation scheme.
Agent needs to know: Set at session open via
openApp, fixed for the session — cannot be changed later without starting a new session. The app default is 5-fold CV ('KFold', 5). Pick based on dataset size × training cost:Scheme When to pick Syntax 5-fold CV Small-medium data (≤few thousand rows), fast models 'KFold', 5(default)20% hold-out Large data, slow models (ensembles, DL, optimization), or time-constrained 'HoldOut', 0.2Resubstitution User explicitly wants fast iteration without accuracy estimate (training-set accuracy, optimistic) 'CrossVal', 'off'Ask the user: "Two things, since the validation setting is fixed once we start: (1) roughly how many rows does your dataset have, and (2) is there a training time budget I should keep in mind, or is training time not a concern? I'll pick a validation approach that works for both."
Independent test dataset.
Agent needs to know: whether to use
importTestDatawith an existing table, reserve a fraction viaTestDataFraction(e.g., 0.2), or skip test entirely. Test data is distinct from validation and is used only once on the final model.Ask the user: "Do you have a separate dataset you want to keep aside for a final check, or should we reserve a slice of your data (say, 20%) that we don't train on and use it only at the end?"
Performance requirements.
Agent needs to know: target metric thresholds (min accuracy, max RMSE), prediction latency, deployment throughput.
Ask the user: "Are there specific accuracy or speed targets the model must meet? For example, minimum acceptable accuracy, maximum acceptable prediction time per sample, or throughput on a given device."
Model size / deployment environment.
Agent needs to know: whether target is embedded / memory-constrained. If so, favor compact learners (linear, single tree, small SVM) and check
ModelSizeMetric(general) orModelSizeCoderMetric(Coder-specific).Ask the user: "Will this model need to run on a small device, embedded system, or in a memory-limited environment? If so, we'll favor smaller/simpler models."
Interpretability need.
Agent needs to know: whether interpretable model families (trees, linear, discriminant) should be prioritized, and whether to plan interpretability plots (Permutation Importance, PDP, LIME, Shapley) after training.
Ask the user: "Will you need to explain the model's decisions to anyone — regulators, auditors, or non-technical stakeholders — or is raw accuracy the only priority?"
Use the answers to configure the session appropriately from the start — choosing the right predictors, validation scheme, model types, and export path without wasted training cycles.
Best Practices
Data & Setup
Test data splitting: Before opening the app, ask the user whether they want to hold out a portion of the data as an independent test set. If they have a separate test dataset already available in the workspace, use that. If not, offer to split the data using
TestDataFraction(e.g., 0.2–0.25) when opening the app, or let the user import test data later. This ensures an unbiased evaluation path is available after training. ForopenAppsyntax and partitioning NV arguments, seereferences/api-session-and-models.md#opening-the-app.Data inspection before training: Before training models, inspect the data for potential issues. Check for: (1) missing values — models handle these differently, and some fail on NaN; (2) class distribution (classification) — use
tabulateorgroupcountsto detect imbalance; (3) response distribution (regression) — check for skewness or outliers in the response variable that may warrant transformation; (4) outliers in numeric predictors that could skew model performance; (5) constant or near-constant predictors that add no information. Report findings to the user and suggest preprocessing or model choices accordingly.⚠ Preprocessing and data leakage: Any preprocessing that uses aggregate statistics from the dataset — mean/median imputation, IQR- or z-score-based outlier removal, standardization/normalization, target encoding, etc. — leaks information from validation/test folds into training when done before importing into the app, and produces over-optimistic metrics. The app does not perform these operations inside its CV/holdout folds (only feature-selection ranking, PCA, and misclassification cost matrices are applied per-fold). For practical guidance on how to handle this, see
references/skill-guidance-details.md#preprocessing-and-data-leakage.Class imbalance handling: If the dataset has imbalanced classes (e.g., 90%/10% split), suggest: (1)
ClassificationRUSBoostedEnsemble(RUSBoost) which is specifically designed for imbalanced data by undersampling the majority class during boosting, (2) adjusting the cost matrix viaapp.setModelCostMatrix()to penalize misclassification of the minority class more heavily, (3) using Macro F1 or per-class metrics instead of overall accuracy to evaluate model quality — accuracy can be misleading with imbalanced data. Ask the user which class is more important to get right.
Feature Engineering
Feature selection and ranking: Suggest when: (1) dataset has many predictors (>20) and training is slow or models overfit, (2) user wants a simpler/more interpretable model, (3) model size must be minimized for deployment, (4) some predictors are known to be irrelevant/redundant. APIs:
app.setDefaultFeatureSelectionOptions(...)for all draft models, orapp.setModelFeatureSelectionOptions(...)for a specific one. For which ranking method to pick per problem type and goal, seereferences/skill-guidance-details.md#feature-selection.PCA: Suggest PCA when: (1) predictors are highly correlated (multicollinearity), (2) the dataset has many numeric predictors and dimensionality reduction could improve training speed without losing much information, (3) the user wants to reduce model complexity. Do NOT suggest PCA when interpretability is critical (PCA components lose predictor meaning). Note: PCA applies only to numeric predictors — categorical predictors are preserved unchanged and concatenated back after transformation, so mixed datasets are supported. Use
app.setDefaultPCAOptions('OnOff', true, 'PercentVarianceExplained', 95)to set for all draft models, orapp.setModelPCAOptions('OnOff', true, 'PercentVarianceExplained', 95)to target the current/specific model.
Model Training & Selection
Comparing models: After training multiple models, open the Results Table (
app.clickResultsTableToolstripButton()) and Compare Results plot (app.openCompareResultsPlot()) to help the user compare models side-by-side. The Results Table shows all validation (and test) metrics in a sortable table. The Compare Results plot visualizes models either as a bar plot for a single metric or on two axes (e.g., accuracy vs prediction speed, or accuracy vs model size) for quick trade-off analysis. Useapp.getResultsTableData()andapp.getCompareResultsPlotData()to read the data programmatically. Suggest these views before the user picks the best model, so the decision is informed by multiple metrics — not just accuracy. For compare-results plot configuration, seereferences/api-plots.md#compare-results-plot-configuration-r2024b.Importing externally trained models: Ask the user if they have pre-trained models in the workspace to include in the comparison. Supports workspace models (R2026a+). For compatibility requirements, validation limitations, and import details, see
references/skill-guidance-details.md#importing-models.Hyperparameter optimization: Suggest after initial model comparison when default presets are unsatisfactory and user has time budget. Optimization requires an
Optimizable*preset (e.g.,ClassificationOptimizableTree) — duplicating a regular model does not make it optimizable. Default:'bayesopt'with 30 iterations. Use'grid'only for exhaustive search over a small space;'random'for quick exploration of very large spaces. For time-constrained users, set'HasTrainingTimeLimit', true, 'MaximumTrainingTimeInSeconds', N. Seereferences/skill-guidance-details.md#hyperparameter-optimizationfor additional detail.Parallel and background training: Suggest enabling parallel computing (
app.toggleUseParallelButton()) when: (1) the dataset is large (>10K observations or >50 predictors), (2) training multiple models or running optimization with many iterations, (3) cross-validation with many folds. Suggest background training (app.toggleUseBackgroundTrainingCheckbox()) or parallel ON when the user wants to continue working in MATLAB while models train (check box is only available when user does not have Parallel Computing Toolbox). Note: parallel requires Parallel Computing Toolbox.Model iteration workflow: When a model type shows promise but needs improvement, prefer manual tuning (duplicate → adjust → compare) before jumping to optimization. For the workflow steps, constraints (Draft status requirement, All-preset limitations), and tips, see
references/skill-guidance-details.md#model-iteration.
Evaluation & Interpretability
Test before export: After identifying the best model by validation metrics, always ask the user if they have an independent test dataset available. Testing on held-out data reveals generalization accuracy on unseen data, which is more reliable than cross-validation accuracy alone. Use
app.importTestData()to load test data, thenapp.clickTestSelectedModelToolstripButton()to evaluate. Report test metrics viaapp.getCurrentModelTestDataMetrics()so the user can make an informed decision before exporting.Test only the best model: Do not test multiple models on the test dataset. The test set should only be used once on the final selected model to get an unbiased estimate of generalization performance. Testing many models on the same test set and then choosing the best one undermines the purpose — it leaks test information into model selection and leads to overly optimistic accuracy. If test results are unsatisfactory, suggest the user improve the model using validation techniques (e.g., feature engineering, hyperparameter tuning, trying different model types) rather than re-testing multiple models on the test set.
Interpretability plots: After the best model is identified and tested, suggest interpretability plots when the user needs to explain predictions to stakeholders, is deploying in a regulated domain (healthcare, finance), sees unexpectedly high/low test accuracy, or wants to identify predictor drivers. Available: Permutation Importance (global, fast), Partial Dependence (per-predictor effects), LIME (local, per-observation), Shapley (both global and local). ⚠ Shapley can be slow on large datasets or complex models — always warn the user before triggering it. For per-plot decision aid, Shapley cost-control levers, and choosing between Permutation Importance vs Shapley, see
references/skill-guidance-details.md#interpretability-plots. For Shapley/LIME configuration API and plot data fields, seereferences/api-explainability.md.Plots for model analysis: Suggest plots based on the workflow stage — after training (classification/regression), when comparing models, for optimizable models, for neural networks / DL, after testing on held-out data, or for data exploration. For the full stage-by-stage mapping of which plot to open for each purpose (with API method names), see
references/skill-guidance-details.md#plots-for-model-analysis.
Session & Code Export
Session save/load (R2022a+): Suggest saving sessions when training took a long time, user wants to continue later, or share results. Always suggest saving before closing after significant work. For save/load APIs and the blocking-dialog workaround, see
references/skill-guidance-details.md#session-management.Exporting the training workflow as code:
app.clickGenerateCodeToolstripButton()turns the app workflow into a script — useful when the user wants to work outside the app, integrate the model into a larger MATLAB workflow, version-control the training code, or automate/schedule the workflow. Use theapp.generateCode()variant when the code is needed as a string. Produces a.mtraining function covering data preprocessing (feature selection, PCA), model training, and validation. Works for all model types. Note: re-running the generated script may not exactly reproduce the app's results due to randomization incvpartition.Exporting results programmatically: Use
app.exportPlotData('VariableName', 'myPlot')to export the current active plot's data to the workspace for further analysis. Useapp.exportPlotToFigure()to export the active plot to a standalone MATLAB figure (for saving as an image or customizing). Useapp.exportResultsTableToWorkspace('VariableName', 'myResults')orapp.exportResultsTableToFile('results.csv')to export the Results Table (visible rows and columns only) to the workspace or a CSV file. These are useful when the user wants to share results, create custom visualizations, or integrate findings into reports. For full export method signatures and parameters, seereferences/api-export-and-diagnostics.md#programmatic-export-methods.
Deployment Export
Export to workspace: Use
app.exportModelToWorkspace('MyModel')(optionally'IncludeTrainingData', falsefor a compact export). What gets exported (all paths): a full model trained on the entire training set (not a CV-fold model), so the exported artifact is always a fresh fit on all available training data.Export to Simulink (R2024a+): For model-based design / controller-in-the-loop. Use
app.exportModelToSimulink(...). Categorical predictors are NOT supported — warn early. For full constraint list and supported model types, seereferences/skill-guidance-details.md#export-to-simulink-r2024a. ForexportModelToSimulinkparameter table, seereferences/api-export-and-diagnostics.md#export-model-to-simulink-r2024a.Export to Coder (R2025a+): For C/C++ code generation / embedded targets. Use
app.exportModelToCoder(...). For constraint list and sizing guidance, seereferences/skill-guidance-details.md#export-to-coder-r2025a. ForexportModelToCoderparameter table, seereferences/api-export-and-diagnostics.md#export-model-to-coder-r2025a.Export to Experiment Manager (R2022a+): Suggest when the user needs finer control over hyperparameter tuning (editable search ranges, custom constraints). Use
app.createExperiment(...). Model must be trained first. For decision logic (when to use vs. app-level optimization, when to skip the Learner app), seereferences/skill-guidance-details.md#export-to-experiment-manager-r2022a.Export to Production Server: For REST API / web service deployment. Use
app.clickExportModelToProductionServerToolstripButton(). Requires MATLAB Compiler SDK. Seereferences/skill-guidance-details.md#export-to-production-server.
Minimum Release Requirements
Features have minimum MATLAB release constraints. Calling a feature on an older release will error.
| Feature | Minimum Release |
|---|---|
| Set optimizer options | R2019b |
| Set cost matrix | R2019b |
| Export to Production Server, Optimizable Neural Network models, Classification Kernel models | R2021b |
| Save/load session to file, Feature ranking, Regression Kernel models | R2022a |
| Results table, Partial dependence plot | R2022b |
| Create experiment (Experiment Manager), Save compact session to file, Efficient Linear classification models (LogisticRegression, LinearSVM, All) | R2023a |
| Local Shapley, LIME, Efficient Linear regression models (LS, SVM, All), Optimizable Efficient Linear, Optimizable Kernel | R2023b |
| Export model to Simulink, Simulink multi-train presets (AllSimulink), Neural Network models (Uni/Bi/Tri-Layered, All) | R2024a |
| Shapley importance/summary/dependence plots, Compare results plot, Precision-Recall plot, Export plot data, Additional metrics (Precision, Recall, F1-Score) | R2024b |
| Export model to Coder, Codegen multi-train presets (AllCodegen), Permutation importance plot, Compare ROC Curves plot | R2025a |
| Import trained model from workspace | R2026a |
| Deep Learning models (FullyConnected, Residual, All), Training progress plot, Network analyzer plot, Export partitions and data sets | R2026a |
Quick Reference — Common Workflow
% 1. Open app with data
% Classification:
app = mlearnapp.internal.appcontroller.AppController.openApp('classification', Tbl, 'Response', 'KFold', 5);
% Regression:
% app = mlearnapp.internal.appcontroller.AppController.openApp('regression', Tbl, 'Price', 'KFold', 5);
% 2. Discover available model types and create models
% IMPORTANT: Always call getAvailableModelTypes to discover exact enum names.
% Do NOT guess enum names — they vary by category and release.
% Example: Naive Bayes is 'ClassificationGaussianNaiveBayes', not 'ClassificationNaiveBayes'
available = app.getAvailableModelTypes(); % all valid for this release
% 'Category' is a case-insensitive substring filter on the enum name
% (e.g., 'Tree', 'SVM', 'Ensemble', 'KNN', 'NeuralNetwork', 'Linear', 'Kernel', 'AllSimulink', ...).
% Call getAvailableModelTypes() with no filter first if unsure which substring will match.
treeModels = app.getAvailableModelTypes('Category', 'Tree');
% For guidance on picking an All-* preset family (AllQuickToTrain vs full All vs
% family-specific like AllTrees, AllSVM, AllEnsemble, AllLinear, AllKernel, etc.),
% see references/skill-guidance-details.md#multi-train-presets-all----which-to-pick
% For model type enum names, see references/api-session-and-models.md#gallerymodels-enum-reference
app.createModelType('ClassificationAllQuickToTrain');
% 2b. (Optional) Set hyperparameters on a DRAFT model BEFORE training
% Signature: app.setModelHyperparameterOptions(modelNumber, 'Param', value, ...)
% The first argument MUST be the model number string (e.g., '2', '3.1')
app.setModelHyperparameterOptions('2', 'BoxConstraint', 10, 'KernelScale', 2);
% 3. Train and wait
app.clickTrainToolstripButton();
app.waitForTrainingToComplete();
% 4. Compare models
app.clickResultsTableToolstripButton();
app.openCompareResultsPlot();
allMetrics = app.getAllModelMetrics();
% 5. Select best model (use model number from allMetrics)
% Classification: use AccuracyMetric (or MacroF1ScoreMetric for imbalanced data)
[~, bestIdx] = max([allMetrics.AccuracyMetric]);
% Regression: use RMSEMetric (lower is better) or RSquaredMetric (higher is better)
% [~, bestIdx] = min([allMetrics.RMSEMetric]);
app.selectModelByNumber(allMetrics(bestIdx).ModelNumber);
% 6. Test on held-out data
app.importTestData('testTable');
app.clickTestSelectedModelToolstripButton();
testMetrics = app.getCurrentModelTestDataMetrics();
% 7. Export
app.exportModelToSimulink('MyModel.slx');
% 8. Close app (use 'Force', true ONLY for automated testing — never without user permission)
app.closeApp('Force', true);Copyright 2026 The MathWorks, Inc.
Files
- ATTRIBUTION.mdAdded by AutoGineer1.1 KiB
- LICENSELicence file added by AutoGineer1.4 KiB
- SKILL.md25.5 KiB
- manifest.yaml614 B
- references/api-explainability.md11.7 KiB
- references/api-export-and-diagnostics.md9.6 KiB
- references/api-metrics-and-options.md8.5 KiB
- references/api-plots.md18.3 KiB
- references/api-session-and-models.md16.5 KiB
- references/skill-guidance-details.md21.9 KiB
- scripts/+mlearnapp/+internal/+appcontroller/AlertDialogController.p(opens on GitHub)Not mirrored: opens on GitHub1.7 KiB
- scripts/+mlearnapp/+internal/+appcontroller/AppController.p(opens on GitHub)Not mirrored: opens on GitHub14.4 KiB
- scripts/+mlearnapp/+internal/+appcontroller/AppControllerBase.p(opens on GitHub)Not mirrored: opens on GitHub4.3 KiB
- scripts/+mlearnapp/+internal/+appcontroller/AutoDismissConfirmDialogController.p(opens on GitHub)Not mirrored: opens on GitHub361 B
- scripts/+mlearnapp/+internal/+appcontroller/CoderExportStubs.p(opens on GitHub)Not mirrored: opens on GitHub217 B
- scripts/+mlearnapp/+internal/+appcontroller/CustomModelController.p(opens on GitHub)Not mirrored: opens on GitHub2.9 KiB
- scripts/+mlearnapp/+internal/+appcontroller/ExperimentExportStub.p(opens on GitHub)Not mirrored: opens on GitHub642 B
- scripts/+mlearnapp/+internal/+appcontroller/ExplainPlotController.p(opens on GitHub)Not mirrored: opens on GitHub9.1 KiB
- scripts/+mlearnapp/+internal/+appcontroller/ExportController.p(opens on GitHub)Not mirrored: opens on GitHub3.8 KiB
- scripts/+mlearnapp/+internal/+appcontroller/ImportController.p(opens on GitHub)Not mirrored: opens on GitHub4.1 KiB
- scripts/+mlearnapp/+internal/+appcontroller/ImportTestDataStubView.p(opens on GitHub)Not mirrored: opens on GitHub657 B
- scripts/+mlearnapp/+internal/+appcontroller/ModelOptionsController.p(opens on GitHub)Not mirrored: opens on GitHub2.8 KiB
- scripts/+mlearnapp/+internal/+appcontroller/NewSessionDialogController.p(opens on GitHub)Not mirrored: opens on GitHub1.4 KiB
- scripts/+mlearnapp/+internal/+appcontroller/ResultsPlotController.p(opens on GitHub)Not mirrored: opens on GitHub7.0 KiB
- scripts/+mlearnapp/+internal/+appcontroller/SessionController.p(opens on GitHub)Not mirrored: opens on GitHub1.2 KiB
- scripts/+mlearnapp/+internal/+appcontroller/ToolstripController.p(opens on GitHub)Not mirrored: opens on GitHub2.8 KiB
references/skill-guidance-details.md
Skill Guidance — Expanded Details
This file expands on the guidance bullets in SKILL.md. SKILL.md keeps the "when to suggest" summary; this file holds the decision aids, warnings, and per-option details that don't need to be in the agent's primary context all the time.
For API signatures and parameters, see the split API reference files: api-session-and-models.md, api-metrics-and-options.md, api-plots.md, api-explainability.md, api-export-and-diagnostics.md. This file is complementary — it answers "which option should I pick?", not "what's the syntax?".
How to use the decision tables in this file: These tables are for the agent's internal decision-making. The agent should:
Read the user's stated intent (or infer it from the workflow context).
Pick a row from the relevant table internally.
Report the choice to the user in one short sentence, in plain terms — do not paste the table.
Feature Selection
When to suggest (summary from SKILL.md): dataset has many predictors (>20), training is slow, models overfit, interpretability matters, model size must be minimized, or the user knows some predictors are irrelevant/redundant.
How the agent should use this section:
Infer intent from the user's request. Map the user's stated preference (or the workflow's implicit need) to a row in the method table:
"Predictors are correlated" / "avoid redundant features" → MRMR (classification or regression variant)
"I want a nonparametric ranking" / "ANOVA assumptions look shaky" → KruskalWallis (classification only, rank-based) or Chi2 (classification only, bins data)
"Simple statistical test per predictor" → ANOVA (classification, parametric) or Chi2 (classification, non-parametric) or FTest (regression)
"Some features may only matter in combination" / "distance-based model coming next" → ReliefF / RReliefF
Check applicability constraints before picking ReliefF. If the user (or your inference) points to ReliefF but predictors are mixed (some categorical, some numeric), fall back to MRMR — it also handles nonlinear structure and is the closest agent-safe substitute. Do not attempt to enable a disabled ranking method.
Default choice when the user has no preference: MRMR (
ClassificationMRMRorRegressionMRMR). It handles correlated predictors well, has no predictor-type constraint, and is a robust general-purpose ranking.Where to configure it in the workflow:
For all draft models in the session, call
app.setDefaultFeatureSelectionOptions(...)before creating draft models withapp.createModelType(...). Include'IsFeatureSelectionAutomatic', trueand'NumFeaturesToKeep', Nto auto-apply the top-N.To override for a specific draft model only, call
app.setModelFeatureSelectionOptions(...)after creating that draft (target it by model number).
Do not hide this from the user. The Learner app applies the ranking independently inside each CV fold, so results reflect that pipeline. If the user later inspects generated code, the ranking step will be visible — pick the method consistent with what you'd tell the user aloud.
Which ranking method to pick:
Classification Learner exposes: ANOVA, Chi2, KruskalWallis, ClassificationMRMR, ClassificationReliefF.
Regression Learner exposes: FTest, RegressionMRMR, RegressionReliefF.
| Problem type | Goal | Recommended method |
|---|---|---|
| Classification | Marginal per-predictor association, parametric (assumes roughly normal within-class distributions) | ANOVA |
| Classification | Marginal per-predictor association, non-parametric (bins continuous predictors, tests independence via contingency table — works with any predictor distribution) | Chi2 |
| Classification | Marginal per-predictor association, non-parametric rank-based (safer when ANOVA's distributional assumptions are shaky — small classes, non-normal residuals, ordinal-like responses) | KruskalWallis |
| Classification | Non-redundant / de-duplicated ranking (predictors may be correlated) | ClassificationMRMR |
| Classification | Detect features whose relevance only shows up in combination with others (conditional/contextual relevance) | ClassificationReliefF |
| Regression | Marginal linear association per predictor | FTest |
| Regression | Non-redundant / de-duplicated ranking (predictors may be correlated) | RegressionMRMR |
| Regression | Detect features whose relevance only shows up in combination with others (conditional/contextual relevance) | RegressionReliefF |
Applicability constraints:
ReliefF / RReliefF requires uniform predictor types. The app disables the toggle when predictor types are mixed (some categorical, some numeric). It is enabled only when all predictors are categorical or all predictors are numeric (with more than one observation free of missing values in the numeric case). This mirrors the underlying
reliefffunction requirement.Regression Learner has no non-linear univariate ranking method.
FTestis the sole "marginal-per-predictor" option and captures linear relationships only. There is no regression counterpart to Chi2 / Kruskal-Wallis in the app; for nonlinear per-predictor relevance,RegressionReliefF(with the uniform-type constraint above) orRegressionMRMRare the alternatives.
APIs (all draft models): app.setDefaultFeatureSelectionOptions('IsFeatureSelectionAutomatic', true, 'SelectedFeatureRankingMethod', ...)
APIs (current/specific model): app.setModelFeatureSelectionOptions(...)
Validation: After training, compare validation metrics with and without feature selection to confirm no significant metric loss.
Preprocessing and Data Leakage
Context: The Learner app does not perform statistics-based preprocessing (imputation, normalization, outlier removal) inside its CV/holdout folds — only feature-selection ranking, PCA, and misclassification cost matrices are applied per-fold. If the user has already applied statistics-based preprocessing before importing data, the reported metrics may be over-optimistic.
Practical guidance:
Prefer observation-independent preprocessing before import. Unit conversion, physically-motivated log-transform, dropping columns known a priori to be irrelevant, one-hot encoding a fixed categorical set — none of these use dataset-wide statistics, so they are safe to apply before importing.
If statistics-based cleaning is unavoidable (and no custom partition is used): Warn the user that reported validation/test metrics will be optimistic and that a truly held-out test set (reserved via
TestDataFractionand never touched during cleaning) is the only reliable accuracy check.Custom partition approach (R2026a+): The leak-safe workflow when statistics-based preprocessing is needed:
Partition the data at the command line using
cvpartition.Compute preprocessing statistics (mean, std, IQR, etc.) using only the training fold observations.
Apply the resulting transform to all data.
Pass the custom
cvpartitionobject toopenAppvia the'ValidationPartition'parameter (or'TestPartition'for test splits).This preserves fold boundaries and avoids leakage while still allowing statistics-based cleaning.
Hyperparameter Optimization
When to suggest (summary from SKILL.md): default preset performance is unsatisfactory and the user has training-time budget for a longer run. Suggest after initial model comparison, not as the first step — the user needs a baseline to beat.
Optimizer choice:
'bayesopt'(smart search) — default recommendation. Start with 30 iterations for most cases.'grid'— only when the user wants exhaustive search over a small parameter space.'random'— quick exploration when the search space is very large and bayesopt overhead isn't justified.
Time-limit escape hatch: For time-constrained users, set:
app.setModelHyperparameterOptions(modelNum, ...
'HasTrainingTimeLimit', true, ...
'MaximumTrainingTimeInSeconds', N);Interpretability Plots
When to suggest (summary from SKILL.md): explain predictions to stakeholders, deploy in regulated domain (healthcare, finance), diagnose unexpectedly high/low accuracy, identify predictor drivers.
Which plot for which purpose:
| Question the user is asking | Plot to suggest |
|---|---|
| Which predictors matter overall? | Permutation Importance (fast) |
| How does one predictor affect the prediction, holding others fixed? | Partial Dependence |
| Why did the model predict this value for this observation? | LIME (local) |
| Both global and local explanations, principled game-theoretic attribution | Shapley |
Warning — Shapley cost: Shapley computation can be very time-consuming for large datasets or complex models (ensembles, neural networks). Always warn the user before triggering computation. Levers to reduce cost via app.setShapleyParameters():
Reduce
NumQueryPoints— fewer background samples.Reduce
NumObservationSamples— fewer instances used to build the estimator.
Both trade precision for speed. When time is very limited and the user only needs global feature ranking, prefer Permutation Importance instead of Shapley.
Multi-Train Presets (All-*) — Which to Pick
All* presets create and train every model preset in a family at once, giving the user a broad baseline across that family without hand-picking individual presets. Pass them to app.createModelType(...) like any other preset.
Cross-cutting presets (both classification and regression):
| Preset | When to pick |
|---|---|
ClassificationAllQuickToTrain / RegressionAllQuickToTrain | Default first pass. Trains only the fast-to-fit presets across all families. Best for large datasets, initial exploration, or when the user just wants a baseline before committing time. |
ClassificationAll / RegressionAll | Full non-optimizable sweep across every family. Comprehensive but slower — use when the dataset is small enough or the user has time budget, and no family has been ruled out. |
ClassificationAllSimulink / RegressionAllSimulink | Filter to only models the app can export to Simulink. Use when Simulink is the end goal — avoids training models that can't be deployed. |
ClassificationAllCodegen / RegressionAllCodegen | Same idea for MATLAB Coder (R2025a+). |
ClassificationAllDLNetworks / RegressionAllDLNetworks (R2026a+) | Only the Deep Learning family (FullyConnected, Residual, All). Requires Deep Learning Toolbox. Use when the user has explicitly asked for deep networks. |
Family-specific presets — pick when the user has a domain reason to prefer a family:
| Preset (classification / regression) | When to pick |
|---|---|
ClassificationAllTrees / RegressionAllTrees | Interpretability is important; user wants to visualize decisions; predictors may include categoricals; deployment target favors small memory footprint. |
ClassificationAllSVM / RegressionAllSVM | High-dimensional data with a clear margin; smaller-to-medium datasets; user wants a max-margin model. Not great for very large N. |
ClassificationAllKNN (classification only) | Small datasets with well-separated classes; simple non-parametric baseline; the user wants an explainable nearest-neighbor approach. |
ClassificationAllEnsemble / RegressionAllEnsemble | Predictive accuracy matters more than interpretability; user has time for slower training; robust to noisy or heterogeneous features. |
ClassificationAllNeuralNetwork / RegressionAllNeuralNetwork (R2024a+) | Nonlinear tabular relationships; medium-to-large datasets. Ships with Statistics and ML Toolbox — no Deep Learning Toolbox required. |
ClassificationAllKernel / RegressionAllKernel (R2023b+) | Large datasets where full SVM is too slow — kernel approximation for scale. |
ClassificationAllLinear (classification only) | Logistic-regression-based linear models. Interpretable, cheap, good baseline. |
ClassificationAllClassificationLinear (classification only, R2023a+) | SVM-based linear models. Similar use case but different underlying optimizer / model family than AllLinear. |
ClassificationAllLogisticRegression (classification only, R2024a+) | Logistic-regression variants specifically (not the broader linear family). |
ClassificationAllDiscriminant (classification only) | Linear or quadratic discriminant analysis — small data, roughly Gaussian class distributions. |
ClassificationAllNaiveBayes (classification only) | Text-like or high-dimensional sparse data; a fast probabilistic baseline. |
RegressionAllLinear (regression only) | Baseline linear regression family (linear, robust, stepwise). Highly interpretable. |
RegressionAllGPR (regression only) | Small-to-medium datasets where uncertainty estimates matter; smooth nonlinear regression. Slow on large N. |
Recommendations for the agent:
Default first suggestion:
*AllQuickToTrain. It's fast enough to run without asking, and its results inform the next choice.After the first pass, suggest a family-specific
All*preset only when the user has stated a preference the results don't yet satisfy (e.g., "these trees look good but I want more interpretability" →AllLinear; "accuracy still isn't enough" →AllEnsemble).If Simulink or Coder is the deployment target, prefer
AllSimulink/AllCodegenover broader presets so no training time is spent on unsupported models.Availability varies by release. Always call
app.getAvailableModelTypes()(unfiltered) before assuming a preset exists — e.g.,AllDLNetworksis R2026a+,AllClassificationLinearis R2023a+.
Deployment Constraints
When to consult: Only when the user's export target is Simulink, Coder, Experiment Manager, or Production Server. Not needed for workspace export or code generation.
Export to Simulink (R2024a+)
Requires Simulink toolbox.
Categorical predictors are NOT supported. Simulink Predict blocks cannot accept categorical inputs. Warn the user early — before opening the app — and either use only numeric predictors or encode categoricals as numeric before loading data.
Unsupported model types: linear/stepwise linear regression, ensembles with non-tree learners (discriminant/KNN-learner ensembles), tree models with surrogate splits enabled (
SurrogateUse≠'Off'), binary GLM logistic regression, custom models.Use
ClassificationAllSimulink/RegressionAllSimulinkpresets to avoid training unsupported models.Cost of a bad export choice: iterating on a Simulink diagram after finding a model problem is much more expensive than switching models in the app.
Export to Coder (R2025a+)
Requires MATLAB Coder toolbox.
Unsupported: multiclass kernel classifiers, ECOC with kernel learners, tree models with surrogate splits, binary GLM logistic regression, custom models.
Use
ClassificationAllCodegen/RegressionAllCodegenpresets.For sizing/latency-constrained targets, check
ModelSizeCoderMetric(codegen-specific, differs fromModelSizeMetric) andPredictionSpeed; favor compact learners (linear, single tree, small SVM) over large ensembles.Other types may fail at export time (surfaced as a dialog error).
Export to Experiment Manager (R2022a+)
Part of MATLAB — no extra toolbox required.
Which API to call: Default to
app.createExperiment(...)for agent-driven workflows. Only useapp.clickCreateExperimentToolstripButton()when the user explicitly asks to click the toolstrip button.Model must be trained before calling
createExperiment.Why Experiment Manager vs. app-level optimization: The Learner app's
Optimizable*presets let the user pick the optimizer and toggle which hyperparameters to include, but search ranges are fixed. Experiment Manager exposes ranges for editing, plus custom training/evaluation logic, constraints, parallelizable/resumable/versioned experiments.setModelHyperparameterOptionsin the Learner app is unrelated — it sets fixed values for draft (non-optimizable) models, not tunable ranges.When to skip the Learner app entirely: May be simpler when (a) user's only goal is tuning and the model type has no known constraint functions, (b) they need a custom training function, (c) they want a non-app model type, or (d) they need unusual hyperparameters.
Why routing through the Learner app is usually better: It pre-generates a working training function, default search ranges, and critically the
ConditionalConstraintsandDeterministicConstraintsfunctions that encode valid hyperparameter combinations. These are poorly documented and very hard to author correctly from scratch.
Export to Production Server
Requires MATLAB Compiler SDK.
Use when: model serves predictions via REST API, deployment target is a server, multiple clients query remotely.
Importing Models
Externally Trained Models (R2026a+)
Use
app.importModel('varName')orapp.importModel('varName', 'ModelName', 'Custom Name').Imported models appear in Results Table and Compare Results plot alongside app-trained ones.
Important: Imported models do NOT have validation metrics — only test metrics are available after testing on held-out or imported test data.
To compare imported vs app-trained models, reserve test data (via
TestDataFraction) or import test data, then test both.The model must be trained on a similar dataset (same predictor names and response class names).
Session Management
Save/Load (R2022a+)
When to suggest saving: (1) training took a long time and losing progress would be costly, (2) user wants to continue later, (3) comparing across sessions or sharing with colleagues.
app.saveSessionToFile()— full session.app.saveCompactSessionToFile()— smaller file, no training data.To reload: open the app without data first, then call
app.openSessionFromFile('path.mat').
Blocking Save-Confirmation Dialog
Both openApp with a session file path and openSessionFromFile trigger a blocking save-confirmation dialog if the current session has unsaved changes. The dialog is NOT triggered if the session is already saved or no session has been started.
Avoid the block by:
(a) Opening the app without data before loading a session file.
(b) Saving the current session first.
(c) Force-closing the app (
closeApp('Force', true)) only with user permission or in automated testing.
Model Iteration
Workflow: duplicate → adjust → compare.
app.duplicateModelByNumber('3.1')to preserve the original while creating a draft copy.app.setModelHyperparameterOptions(...)to adjust hyperparameters.Try feature selection variations.
Compare original and tuned versions side-by-side.
Constraints:
The app does NOT allow retraining already trained models (includes Trained, Failed, or Canceled/Interrupted status).
To retrain with new settings, either duplicate the model (creates a draft copy) or create a new model from scratch.
setModelHyperparameterOptionsonly works on models in Draft status.Cannot be used on multi-model "All" presets (e.g.,
ClassificationAllTrees); target individual model presets instead.
Tips:
app.toggleModelFavorite('3.1')to mark promising models.app.sortModelList('Accuracy', 'descend')(classification) orapp.sortModelList('RMSE', 'ascend')(regression) to surface best performers.Prefer manual tuning before jumping to optimization — it builds understanding of what drives performance.
Plots for Model Analysis
When to suggest (summary from SKILL.md): after key workflow milestones (training, comparing, testing) to help the user understand results. Pick by workflow stage:
After training (classification)
Confusion Matrix —
app.openValidationConfusionMatrixPlot(): per-class accuracy and misclassification patterns.ROC Curve —
app.openValidationROCCurvePlot(): discrimination ability across thresholds.Precision-Recall Curve (R2024b+) —
app.openPrecisionRecallPlot(): performance on imbalanced datasets where precision/recall trade-offs matter more than ROC.Scatter Plot —
app.openScatterPlot(): decision boundaries and predictions vs. true labels.
After training (regression)
Predicted vs Actual —
app.openValidationPredictedVsActualPlot(): prediction quality visually.Residuals —
app.openValidationResidualsPlot(): systematic errors, heteroscedasticity, missed patterns.Response Plot —
app.openResponsePlot(): overall fit visualization.
When comparing multiple models
Compare Results —
app.openCompareResultsPlot(): multi-metric trade-off visualization.Compare ROC Curves (classification) —
app.openCompareROCCurvesPlot(): which model discriminates better per class.
For optimizable models
Min Classification Error —
app.openMinClassificationErrorPlot()— monitor optimization convergence; check if more iterations are needed.Min MSE (regression) —
app.openMinMSEPlot()— same idea for regression.
For neural networks / deep learning
Training Progress —
app.openTrainingProgressPlot(): monitor loss, gradient, and step size during training — detect divergence or stalling early.
After testing on held-out data
Mirror the validation plots but on test data to confirm generalization:
Test Confusion Matrix —
app.openTestConfusionMatrixPlot()Test ROC Curve —
app.openTestROCCurvePlot()Test Precision-Recall —
app.openTestPrecisionRecallPlot()Test Predicted vs Actual —
app.openTestPredictedVsActualPlot()Test Residuals —
app.openTestResidualsPlot()
For data exploration (classification)
Parallel Coordinates —
app.openParallelCoordinatesPlot(): how classes separate across predictors — identifies discriminating features.
Copyright 2026 The MathWorks, Inc.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- MathWorks
- Publisher
- MathWorks (Official)
- Source
- matlab/matlab-agentic-toolkit · skills-catalog/ai-and-statistics/matlab-use-machine-learning-apps · commit 2a7f215
- Licence
- BSD 2-Clause License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE.md)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by MathWorks or MathWorks.
Get it from the source
16 of this skill’s files are not mirrored here, so there is no ZIP. Get the complete skill from its source: matlab/matlab-agentic-toolkit