Skip to content

matlab/matlab-agentic-toolkit / skills-catalog/ai-and-statistics/matlab-classify-tabular-data

matlab-classify-tabular-data

Unverified

Use this skill to classify tabular data end-to-end in MATLAB — load a dataset, prepare and clean it, select promising classifiers, train them, and compare accuracies with cross-validation, holdout, or hyperparameter optimization plus statistical tests. TRIGGER when: user asks to classify tabular data, pick classifiers for a dataset, compare classifier accuracy, run cross-validation or a holdout evaluation, or find the best model with statistical uncertainty. DO NOT TRIGGER when: user has non-tabular inputs (images, sequences, time series), wants a regression model, is training a specific neural network architecture (use matlab-train-network), or wants cost-sensitive learning or an arbitrary class-prior vector (this skill only supports the built-in uniform-prior toggle for imbalanced data).

FileKindSize
SKILL.mdskill md36.1 KB
manifest.yamlconfig524 B
references/README.mdmarkdown3.1 KB
references/dataprep.mdmarkdown7.5 KB
references/hpo.mdmarkdown11.5 KB
references/save-and-export.mdmarkdown7.0 KB
references/select-classifiers-imbalanced.mdmarkdown3.0 KB
references/select-classifiers.mdmarkdown9.4 KB
scripts/README.mdmarkdown2.3 KB
scripts/helpers/aggregate_nested_cv_loss.mother470 B
scripts/helpers/apply_preproc.mother4.1 KB
scripts/helpers/build_model_definitions.mother16.6 KB
scripts/helpers/compute_data_flags.mother2.8 KB
scripts/helpers/compute_pairwise_pvalues_cv.mother623 B
scripts/helpers/compute_pairwise_pvalues_holdout.mother556 B
scripts/helpers/count_categorical_levels.pbinary376 B
scripts/helpers/export_workflow_script.mother15.2 KB
scripts/helpers/find_zero_variance_columns.mother810 B
scripts/helpers/is_bag_of_tokens.mother181 B
scripts/helpers/make_holdout_split.mother387 B
scripts/helpers/plot_accuracy_bars.mother994 B
scripts/helpers/plot_boosting_curve.mother1.2 KB
scripts/helpers/plot_pvalue_heatmap.mother465 B
scripts/helpers/plot_training_time.mother797 B
scripts/helpers/resolve_recipe.mother1.1 KB
scripts/helpers/resume_boosting_cv.mother543 B
scripts/helpers/resume_boosting_holdout.mother448 B
scripts/helpers/retrain_with_hpo.mother2.7 KB
scripts/helpers/retrain_with_resume.mother2.5 KB
scripts/helpers/sanitize_model_name.mother799 B
scripts/helpers/save_selected_models.mother4.0 KB
scripts/helpers/score_holdout_test.mother278 B
scripts/helpers/stratified_subsample.pbinary367 B
scripts/helpers/train_and_score_cv.mother405 B
scripts/helpers/train_and_score_holdout.mother1.1 KB
scripts/model_catalog/branch_categorical.mother4.2 KB
scripts/model_catalog/branch_many_missing.mother3.1 KB
scripts/model_catalog/branch_regular.mother4.1 KB
scripts/model_catalog/branch_sparse.mother1.3 KB
scripts/model_catalog/branch_wide.mother2.0 KB
scripts/model_catalog/classifier_branches.mother2.2 KB
scripts/model_catalog/classifier_thresholds.mother2.2 KB
scripts/model_catalog/imbalanced_boosting.mother3.0 KB
scripts/model_catalog/model_recipe.mother3.5 KB

scripts/helpers/apply_preproc.m

View on GitHub
function [X, Y] = apply_preproc(preproc, X, Y)
% APPLY_PREPROC  Replay recorded data-preparation operations on new data.
%
%   [X, Y] = APPLY_PREPROC(PREPROC, X, Y) walks PREPROC (a struct array
%   written by the parent skill during Step 2 "Analyze and clean data")
%   and applies each recorded operation to X (and Y where relevant) in
%   order.
%
%   Every PREPROC entry has:
%       .op          char, one of 'omitColumns', 'dropZeroVariance',
%                    'removeClasses', 'mergeClasses'
%       .payload     op-specific data:
%           omitColumns.columnNames    cellstr (table X) OR
%           omitColumns.columnIndices  numeric row vector (matrix X)
%           dropZeroVariance.columnNames  cellstr (table X) OR
%           dropZeroVariance.columnIndices  numeric row vector (matrix X)
%           removeClasses.classes      cellstr of class labels
%           mergeClasses.map           struct with fields:
%                                        .from — cellstr of source labels
%                                        .to   — char, target label
%       .note        (optional) char — human-readable description
%
%   Y may be any label container the skill supports (categorical, string,
%   cellstr, or numeric). Class-editing ops only apply when Y is
%   categorical or coercible to one.

    arguments
        preproc struct
        X
        Y
    end

    for k = 1:numel(preproc)
        op = preproc(k).op;
        payload = preproc(k).payload;
        switch op
            case 'omitColumns'
                X = drop_columns(X, payload);
            case 'dropZeroVariance'
                X = drop_columns(X, payload);
            case 'removeClasses'
                [X, Y] = remove_classes(X, Y, payload.classes);
            case 'mergeClasses'
                Y = merge_classes(Y, payload.map);
            otherwise
                error('apply_preproc:unknownOp', ...
                    'Unknown preproc op "%s"', op);
        end
    end
end

% -------------------------------------------------------------------------
function X = drop_columns(X, payload)
    if istable(X)
        if isfield(payload, 'columnNames') && ~isempty(payload.columnNames)
            keep = ~ismember(X.Properties.VariableNames, payload.columnNames);
            X = X(:, keep);
        elseif isfield(payload, 'columnIndices') && ~isempty(payload.columnIndices)
            keep = true(1, width(X));
            keep(payload.columnIndices) = false;
            X = X(:, keep);
        end
    else
        if isfield(payload, 'columnIndices') && ~isempty(payload.columnIndices)
            keep = true(1, size(X, 2));
            keep(payload.columnIndices) = false;
            X = X(:, keep);
        elseif isfield(payload, 'columnNames') && ~isempty(payload.columnNames)
            error('apply_preproc:namedDropOnMatrix', ...
                'Cannot drop columns by name from a numeric matrix.');
        end
    end
end

% -------------------------------------------------------------------------
function [X, Y] = remove_classes(X, Y, classes)
    if iscategorical(Y)
        mask = ismember(Y, classes);
    elseif isstring(Y) || iscellstr(Y)
        mask = ismember(cellstr(Y), classes);
    else
        mask = ismember(Y, classes);
    end
    keep = ~mask;
    X = X(keep, :);
    Y = Y(keep);
    if iscategorical(Y)
        Y = removecats(Y);
    end
end

% -------------------------------------------------------------------------
function Y = merge_classes(Y, mapSpec)
    from = mapSpec.from;
    to   = mapSpec.to;
    if iscategorical(Y)
        Y = mergecats(Y, from, to);
    elseif isstring(Y)
        Y = arrayfun(@(v) merge_scalar(v, from, to), Y);
    elseif iscellstr(Y)
        Y = cellfun(@(v) char(merge_scalar(string(v), from, to)), Y, 'UniformOutput', false);
    else
        error('apply_preproc:mergeUnsupportedY', ...
            'mergeClasses op requires Y to be categorical, string, or cellstr.');
    end
end

% -------------------------------------------------------------------------
function v = merge_scalar(v, from, to)
    if any(v == string(from))
        v = string(to);
    end
end

% Copyright 2026 The MathWorks, Inc.
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 319kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 319kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 319kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 196kUpdated Claude CodeCodexVerifiedInstall