AI Glossary / Mathematics and optimization / Advanced

Data matrix

Definition

A data matrix is a rectangular arrangement of data values used for analysis or learning. In the common machine-learning convention, each row represents one example and each column represents one feature or attribute. A matrix with n examples and p features has shape n × p. Its entry Xᵢⱼ contains the value of feature j for example i, under a documented ordering.

What it means

A matrix gives learning methods a consistent numerical input structure. It does not explain what the numbers mean by itself. Feature names, units, encoding rules and record identities provide the interpretation that connects the array to the real problem.
A broader table may include identifiers, text, categories and outcomes. Preparing a model's input matrix can involve selecting and encoding some of those fields. In supervised learning, the target is commonly stored separately as y, with its rows aligned to X. Including the answer among the input features would change the learning problem.

How it works

Choose the observational unit, define the features and establish a stable schema. Each row must describe the intended unit consistently: a customer, transaction, image or other example. Convert values into the representation required by the model, treating missing values and categories explicitly.
With row-oriented examples, multiplying an n × p input matrix X by a p-element weight vector w produces n linear predictions, Xw. An intercept can be handled separately or through an added column of ones. Some mathematical texts use a different orientation, so read the dimensions rather than assuming all authors follow the same layout.

Three practical examples

  • A support model represents each ticket with its message length, number of attachments and other features. The row must correspond to the same ticket as the associated outcome used in training.
  • An image pipeline flattens pixels or extracts numerical descriptors into a feature vector. Stacking those vectors creates a matrix. The matrix representation does not imply that the image geometry is irrelevant to the task.
  • A text model records document-term counts in a sparse matrix. Rows represent documents and columns share a fixed vocabulary. Sparse storage can avoid explicitly storing many zeros while preserving the logical matrix dimensions and feature meanings.

Think of it this way

Think of a ledger whose columns have agreed labels and units. Removing the headings leaves the same numbers but makes them easy to misinterpret. A data matrix is useful because every position has a consistent role. A rectangular array can still be wrong if one system places hours where another expects minutes or rearranges the columns.

Worked example

Consider three examples described by two numerical features. Let X have rows (1, 2), (2, 0) and (3, 1). Its shape is 3 × 2. Choose a demonstration weight vector w = (2, −1), with no intercept. These demonstration weights are not claimed to be fitted or optimal.
The first prediction is 1 × 2 + 2 × (−1) = 0. The second is 2 × 2 + 0 × (−1) = 4. The third is 3 × 2 + 1 × (−1) = 5. Thus Xw is the three-element prediction vector (0, 4, 5).
Suppose the aligned targets are y = (1, 3, 6). The prediction errors are −1, 1 and −1, giving mean squared error (1 + 1 + 1)/3 = 1.
Now swap the feature columns without changing the weights. The rows become (2, 1), (0, 2) and (1, 3), and the resulting predictions are 3, −2 and −1. The dimensions still match, so a shape check alone would not catch the mistake. The column meanings no longer match the coefficient positions.
If both the columns and their corresponding weights are swapped, the original predictions are restored. Similarly, reordering examples requires applying the same row permutation to their targets. The lesson is that matrix arithmetic depends on semantic alignment as well as compatible dimensions.

Illustrative case study

In a fictional delivery company, a training export places distance first and package weight second. A replacement export places package weight first and distance second. Both files contain two numeric columns, so the prediction service accepts the new file without a dimensional error.
The service then applies the distance coefficient to package weight and the weight coefficient to distance. Its output remains numerical and may even look plausible, making the fault harder to notice than a crash.
The team fixes the handoff by validating named features, expected units and order before constructing the matrix. It also retains a reference record with a checked transformation and prediction. When records are joined with outcome data, it verifies identifiers before dropping them from the modeling inputs. These checks protect the meaning of the data rather than only its rectangular shape.

Common misconceptions and mistakes

A data matrix need not be square or invertible. Having more rows than columns does not guarantee independent columns or a unique unregularized least-squares solution. Duplicate or redundant features can still reduce rank.
A spreadsheet table is not automatically ready for numerical modeling. Assigning arbitrary numeric codes to categories can introduce an unintended ordering or distance. Finally, a sparse zero is not automatically a missing value, and a feature matrix is not the same thing as a covariance matrix summarizing relationships between features.

Business use

Treat the input schema as part of the model's specification. Record feature names, units, encodings, missing-value rules and the definition of one row. Keep preprocessing consistent between training and use. Verify row alignment after sorting, filtering or joining tables, and preserve enough metadata to trace a prediction back to its source record. These practices prevent errors that numerical calculations alone cannot identify.

People also ask

Is the target part of the data matrix?

A general data table may include it, but a supervised model's input matrix usually separates it from the target vector.

Must the matrix be square?

No; the number of examples and features can differ.

Does compatible shape guarantee correct predictions?

No. Swapped columns can produce incorrect results with valid dimensions.

Check your understanding

What is the worked example's matrix shape?

Answer: Three rows by two columns.

What does the weight vector contain?

Answer: One coefficient for each feature, in matching order.

Why must targets follow a row reordering?

Answer: Each target must remain paired with the example it describes.

Related terms

  • Feature vector
  • Schema
  • Sparse matrix
  • Tabular data
  • design matrix
  • target vector
  • matrix multiplication
  • matrix rank

Learn next

Practice checking the dimensions and meanings of X, w and y. Then study how encoding, scaling and intercept columns change a model's design matrix while preserving record alignment.

More in Mathematics and optimization

  • Absolute error loss - Absolute error loss measures a numerical prediction's error as the absolute difference between its predicted and reference values: L(y,y-hat)=|y-y-hat|.
  • Active-set method - An active-set method is an optimization approach that works with a changing subset of constraints believed to be tight at the solution.
  • Adjoint state method - The adjoint state method computes how a chosen objective changes when the parameters of a mathematical model change.
  • Σ-algebra
  • Algebraic connectivity - Algebraic connectivity is the second-smallest eigenvalue of a graph's Laplacian matrix.
  • Algorithm IMED - Algorithm IMED, short for Indexed Minimum Empirical Divergence, is a method for choosing actions in a stochastic multi-armed bandit problem.

Sources

AIMA glossary, data matrix: one input example per row and use in learning methods. https://github.com/aimacode/aima-glossary/blob/master/glossary.md Aalto Dictionary of Machine Learning, data matrix and tabular data: numeric rows for data points and columns for attributes. https://aaltodictionaryofml.github.io/ADictML_Main.pdf The matrix calculations and fictional delivery-company case are original teaching illustrations.

Previous: Data masking Next: Data minimization principle

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer