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.
Common scalar values include:
5-30.0142.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., ). They belong to a specific set of numbers, such as:
- The set of Real Numbers ().
- The set of Integers ().
- Formal Definition
- Physical Examples
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 ().
- Temperature:
- Mass:
- Speed:
- Time:
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 Name | Example Value (Scalar) | Description |
|---|---|---|
House_Size | The size of the house in square feet. | |
Bedrooms | The number of bedrooms. | |
Age | The age of the house in years. |
| Object | Description | Example |
|---|---|---|
| Scalar | Single number | 3 |
| Vector | List of numbers | [1, 2, 3] |
| Matrix | 2D grid of numbers | [[1,2],[3,4]] |
| Tensor | Multi-dimensional array | Used 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 (): A scalar value, typically small (e.g., ), that controls how much the model's parameters are adjusted during training.
- Bias (): A single, learned scalar value added to the output of a neuron.
- Kernel Size (): A scalar defining the size of the kernel in a Convolutional Neural Network (e.g., for a kernel).
C. The Cost/Loss Function Output
The objective of training an ML model is often to minimize a Cost Function . The output of this function is always a single scalar value.
The result (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 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 is a scalar and is a vector, then the operation results in a vector where every component of is multiplied by the scalar .
- Addition:
- Multiplication:
- Scalar Operation Example
- Scaling in ML
Let the scalar and the scalar .
a + b = 15
a * b = 50
In Feature Scaling (Normalization), you subtract the mean () and divide by the standard deviation (). Both and are scalars calculated from the training data.
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.