Skip to main content

Scalars - The Foundation

Before diving into complex structures like vectors and matrices, we must start with the most fundamental concept in Linear Algebra: the Scalar.

Understanding scalars is crucial because they are the building blocks of all mathematical objects used to represent data in Machine Learning.

1. What is a Scalar?

A scalar is simply a single numerical quantity. It is a value that has magnitude (size) but no direction.

In the context of data science and machine learning, scalars are single numbers representing an attribute or a quantity.

Examples of Scalars

Common scalar values include:

  • 5
  • -3
  • 0.01
  • 42.7

These values stand alone and are not collections like vectors or matrices.

Notation

Scalars are typically denoted by standard, non-bold, lowercase letters (e.g., a,x,y,λa, x, y, \lambda). They belong to a specific set of numbers, such as:

  • The set of Real Numbers (R\mathbb{R}).
  • The set of Integers (Z\mathbb{Z}).
info

A scalar is an element of the number field used to define a vector space. For most of ML, this field is the set of Real Numbers (R\mathbb{R}).

2. Scalars in Machine Learning

In Machine Learning, almost every single point of data is derived from an initial set of scalars.

A. Feature Values

In a dataset, individual feature values are scalars.

Feature NameExample Value (Scalar)Description
House_Size15001500The size of the house in square feet.
Bedrooms33The number of bedrooms.
Age1212The age of the house in years.
Scalars vs Other Mathematical Objects
ObjectDescriptionExample
ScalarSingle number3
VectorList of numbers[1, 2, 3]
Matrix2D grid of numbers[[1,2],[3,4]]
TensorMulti-dimensional arrayUsed in deep learning

B. Parameters and Hyperparameters

Scalars are used to represent the learned parameters within an ML model and the manually set hyperparameters.

  • Learning Rate (α\alpha): A scalar value, typically small (e.g., α=0.01\alpha = 0.01), that controls how much the model's parameters are adjusted during training.
  • Bias (bb): A single, learned scalar value added to the output of a neuron.
  • Kernel Size (kk): A scalar defining the size of the kernel in a Convolutional Neural Network (e.g., k=3k=3 for a 3×33\times3 kernel).

C. The Cost/Loss Function Output

The objective of training an ML model is often to minimize a Cost Function JJ. The output of this function is always a single scalar value.

J(θ)=12mi=1m(hθ(x(i))y(i))2J(\theta) = \frac{1}{2m} \sum_{i=1}^{m} (h_\theta(x^{(i)}) - y^{(i)})^2
tip

The result J(θ)J(\theta) (the mean squared error) is a single scalar that represents the total error of the model. The training process seeks to find the parameter vector θ\theta that minimizes this single scalar value.

3. Operations with Scalars

Scalars follow basic arithmetic rules. They are used to scale (or modify the magnitude of) other mathematical objects, which is where the term scalar multiplication comes from.

If xx is a scalar and v\mathbf{v} is a vector, then the operation xvx\mathbf{v} results in a vector where every component of v\mathbf{v} is multiplied by the scalar xx.

  • Addition: a+ba + b
  • Multiplication: aba \cdot b

Let the scalar a=5a = 5 and the scalar b=10b = 10.


a + b = 15
a * b = 50


Scalars are the fundamental "zero-dimensional" objects. The next step is to combine scalars into ordered lists, giving us direction the concept of a Vector.