RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • bayesopt
    • classify
    • confusionmat
    • crossvalind
    • cvpartition
    • fitclinear
    • fitctree
    • fitlm
    • kmeans
    • knnsearch
    • lasso
    • lassoglm
    • linkage
    • lscov
    • mnrfit
    • optimizableVariable
    • pdist
    • pdist2
    • perfcurve
    • predict
    • regress
    • ridge
    • squareform
    • test
    • training
    • tsne

classify — Classify observations using discriminant analysis.

classify assigns each row of sample to a class learned from rows of training and labels in group using discriminant analysis.

Syntax

class = classify(sample, training, group)
class = classify(sample, training, group, type, prior)
[class,err,posterior,logp,coeff] = classify(___)

Inputs

NameTypeRequiredDefaultDescription
sampleNumericArrayYes—Sample observations in rows.
trainingNumericArrayYes—Training observations in rows.
groupAnyYes—Training group labels.
typeStringScalarNolinearDiscriminant type: linear, quadratic, diagLinear, diagQuadratic, or mahalanobis.
priorAnyNo—Prior probabilities as a numeric vector, 'empirical', or a struct with group and prob fields.

Returns

NameTypeDescription
classAnyPredicted class labels for sample observations.
errNumericScalarApparent training-set error rate.
posteriorNumericArrayPosterior class probabilities for sample observations.
logpNumericArrayLog unconditional density for sample observations.
coeffAnyPairwise discriminant boundary coefficients.

Returned values from classify depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:classify:InvalidArgumentInputs, labels, dimensions, discriminant type, or priors are malformed.classify: invalid argument
RunMat:classify:NumericalCovariance matrices cannot be solved numerically.classify: numerical failure
RunMat:classify:InternalRunMat cannot construct classification outputs.classify: internal error

How classify works

  • classify(sample,training,group) uses linear discriminant analysis with equal class priors.
  • classify(sample,training,group,type) supports linear, quadratic, diagLinear, diagQuadratic, and mahalanobis discriminants.
  • classify(sample,training,group,type,prior) accepts priors as a numeric vector, the string empirical, or a struct with group and prob fields.
  • sample and training must be finite numeric 2-D matrices with the same number of columns; observations are stored in rows.
  • Typed-integer sample, training, and prior probabilities are independent RunMat extensions for all eight classes and must lie within the exact-integer binary64 range. Logical predictors are separately mode-gated; logical priors reject.
  • Typed-integer group labels are a RunMat extension that preserves exact identity and output class, including uint64 labels above flintmax.
  • group can be numeric, logical, string, character-row, or cell-string labels. Missing numeric labels (NaN) and empty or <missing> text labels are ignored during fitting.
  • Predicted labels preserve the input label family: numeric vectors return numeric labels, logical labels return logical arrays, string labels return string arrays, character-row labels return character matrices, and cell-string labels return cell arrays of character vectors.
  • With multiple outputs, [class,err,posterior,logp,coeff] returns prior-weighted apparent training error, posterior probabilities, unconditional log densities, and a pairwise discriminant coefficient struct array.
  • mahalanobis classification returns NaN posterior and log-density values because it is distance-based rather than prior-probability-based.

Examples

Classify two samples with linear discriminants

training = [0; 0.5; 2; 2.5];
group = [1; 1; 2; 2];
[class,err,posterior] = classify([0.2; 2.2], training, group)

Expected output:

class is [1; 2], err is 0 for the separable training data, and posterior is a 2-by-2 matrix.

Use text labels and an empirical prior

group = ["low"; "low"; "high"; "high"];
class = classify([0.1; 3.2], [0; 0.4; 3; 3.4], group, 'quadratic', 'empirical')

Expected output:

class is a string array containing "low" and "high".

Using classify with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how classify changes the result.

Run a small classify example, explain the result, then change one input and compare the output.

FAQ

Does classify train a reusable model object?⌄

No. It performs one-shot discriminant classification from the supplied training data. Use model-fitting helpers such as fitctree when a reusable object is needed.

Are priors used with the mahalanobis type?⌄

No. Mahalanobis classification is based on class distance; prior values are parsed for compatibility but do not affect class assignment.

Related Stats functions

Ml

bayesopt · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · optimizableVariable · pdist · pdist2 · perfcurve · predict · regress · ridge · squareform · test · training · tsne

Summary

binocdf · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · kstest · kurtosis · lsline · mad · mode · nanmax · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pdf · prctile · quantile · refline · rmse · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest2 · wblinv

Random

binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd

Hist

histc · histcounts · histcounts2

Options

statget · statset

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how classify is executed, line by line, in Rust.

  • View the source for classify in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How classify works
  • Examples
  • Classify two samples with linear discriminants
  • Use text labels and an empirical prior
  • Using classify with coding agents
  • FAQ
  • Related Stats functions
  • Ml
  • Summary
  • Random
  • Hist
  • Options
  • Open-source implementation
  • About RunMat