Lesson 01
Arithmetic & Number Systems for AI
Build AI-ready number sense with integers, floats, fractions, percentages, ratios, scientific notation, and logarithms.
Integers
1. Definition
An integer is a whole number without a decimal point. It can be positive, negative, or zero.
2. Principle
Integers represent countable quantities.
If something can be counted as a whole item, it is usually stored as an integer.
| Quantity | Integer Example |
|---|---|
| Epochs | 10 |
| Batch Size | 32 |
| Number of GPUs | 4 |
| Number of Features | 128 |
| Token Count | 512 |
Rule: Counts = Integers
3. Properties of Integers
| Property | Example |
|---|---|
| Positive | 8 |
| Negative | -5 |
| Zero | 0 |
| No decimal | 25 ✓ |
| Decimal is not integer | 25.5 ✗ |
4. Visual Number Line
The diagram above is the number line for integers:
- Left side → Negative integers
- Middle → Zero
- Right side → Positive integers
- The dots
…mean the line continues forever in both directions
5. Mathematical Operations
6. Python Implementation
# Integers
epochs = 10
batch_size = 32
gpu_count = 4
max_tokens = 512
print(type(epochs)) # <class 'int'>
print(type(batch_size)) # <class 'int'>Arithmetic
epochs = 10
extra_epochs = 5
total = epochs + extra_epochs
print(total) # 157. AI & Machine Learning Use Cases
Example 1 — Training Epochs
epochs = 20The model will learn from the dataset 20 times.
Example 2 — Batch Size
batch_size = 64The neural network processes 64 images at once.
Example 3 — Vocabulary Size
vocab_size = 50000The tokenizer contains 50,000 words/tokens.
Example 4 — Token Limit
max_tokens = 2048An LLM can generate up to 2048 tokens.
8. Real-World AI Examples
| AI System | Integer Used |
|---|---|
| ChatGPT | Max Tokens = 4096 |
| CNN | Batch Size = 32 |
| BERT | Sequence Length = 512 |
| YOLO | Number of Classes = 80 |
| Training | Epochs = 100 |
9. Common Mistakes
Wrong
batch_size = 32.5Batch size cannot be half a sample.
Correct
batch_size = 32Wrong
epochs = 10.0Correct
epochs = 1010. Interview Questions
Q1. What is an integer?
A whole number without a decimal point.
Q2. Why is batch size an integer?
Because it represents the number of training samples processed together, and samples are countable.
Q3. Is zero an integer?
Yes. Zero belongs to the integer set.
Q4. Is 7.0 an integer?
Mathematically it represents 7, but in programming 7.0 is a float, not an integer.
11. Practice Questions
- Is
-12an integer? - Is
0an integer? - Is
18.5an integer? - Which is correct for epochs:
20or20.0? - Why can't batch size be
16.5?
Answers: 1. Yes · 2. Yes · 3. No · 4. 20 · 5. Samples cannot be fractional.
12. One-Line Revision
Integers are whole numbers used to represent countable values such as epochs, batch size, GPUs, features, and token counts in AI systems.
Formula Sheet
Memory Rule: Count = Integer
Floats
1. Definition
A float (floating-point number) is a number that contains a decimal point. It is used to represent values that are not whole numbers.
Examples: 0.5, 3.14, 0.001, -2.75
2. Principle
Floats represent measurements, probabilities, and continuous values.
If a value can vary smoothly (instead of being counted), it is usually a float.
| Quantity | Float Example |
|---|---|
| Learning Rate | 0.001 |
| Dropout | 0.25 |
| Temperature | 0.8 |
| Confidence Score | 0.97 |
| Loss Value | 0.142 |
Rule: Measurements = Floats
3. Properties of Floats
| Property | Example |
|---|---|
| Decimal number | 3.14 |
| Positive | 0.75 |
| Negative | -1.25 |
| Zero can be float | 0.0 |
| Can represent fractions | 0.5 |
Integer vs Float
| Integer | Float |
|---|---|
| 5 | 5.0 |
| 32 | 32.5 |
| -7 | -7.25 |
| 0 | 0.0 |
Although 5 and 5.0 have the same value, they are different data types.
4. Visual Number Line
5. Mathematical Operations
6. Python Implementation
# Float variables
learning_rate = 0.001
dropout = 0.25
temperature = 0.8
loss = 0.142
print(type(learning_rate)) # <class 'float'>Arithmetic
loss1 = 0.45
loss2 = 0.32
total_loss = loss1 + loss2
average_loss = total_loss / 2
print(average_loss)7. AI & Machine Learning Use Cases
Example 1 — Learning Rate
learning_rate = 0.001Controls how much the model updates its weights during training.
Example 2 — Dropout
dropout = 0.330% of neurons are randomly disabled during training to reduce overfitting.
Example 3 — Temperature
temperature = 0.7Controls randomness in LLM responses.
- Low = More deterministic
- High = More creative
Example 4 — Confidence Score
confidence = 0.98Model is 98% confident in its prediction.
8. Real-World AI Examples
| AI System | Float Used |
|---|---|
| Adam Optimizer | 0.001 |
| GPT Temperature | 0.7 |
| CNN Dropout | 0.5 |
| BERT Learning Rate | 2e-5 |
| Model Confidence | 0.96 |
9. Common Mistakes
Wrong
learning_rate = 1A learning rate of 1 is usually too large and causes unstable training.
Correct
learning_rate = 0.001Wrong
temperature = 7Correct
temperature = 0.710. Interview Questions
Q1. What is a float?
A decimal number used to represent continuous values.
Q2. Why is learning rate always a float?
Because weight updates require very small decimal values for stable optimization.
Q3. Difference between 5 and 5.0?
5 |
5.0 |
|---|---|
| Integer | Float |
| Count | Measurement |
int |
float |
Q4. Give three AI parameters that are floats.
- Learning Rate
- Dropout
- Temperature
11. Practice Questions
- Is
0.25a float? - Is
7.0a float? - Which data type should learning rate use?
- Is
32.5suitable for batch size? - Why is
0.001better than1for learning rate?
Answers
- Yes
- Yes
- Float
- No
- It provides small, stable weight updates.
12. One-Line Revision
Floats are decimal numbers used to represent continuous values such as learning rates, probabilities, loss values, dropout, and temperature in AI systems.
Formula Sheet
| Parameter | Typical Value |
|---|---|
| Learning Rate | 0.001 |
| Dropout | 0.25 |
| Temperature | 0.7 |
| Confidence | 0.98 |
Memory Rule: Measure = Float
Fractions
1. Definition
A fraction represents a part of a whole. It consists of two integers separated by a horizontal line.
Examples:
- Numerator → Top number (parts selected)
- Denominator → Bottom number (total equal parts)
2. Principle
Fractions represent proportions or portions of a complete set.
In AI, fractions are commonly used for dataset splitting, probabilities, and sampling.
| Fraction | Meaning |
|---|---|
| 1/2 | Half |
| 1/4 | One quarter |
| 3/4 | Three quarters |
| 4/5 | Four parts out of five |
Rule: Part of a whole = Fraction
3. Parts of a Fraction
Example:
- Numerator = 3
- Denominator = 4
Meaning: 3 of the 4 equal parts are selected.
4. Visual Representation
1/2
3/4
5. Converting Fractions
Fraction → Decimal
Fraction → Percentage
Table
| Fraction | Decimal | Percentage |
|---|---|---|
| 1/2 | 0.50 | 50% |
| 1/4 | 0.25 | 25% |
| 3/4 | 0.75 | 75% |
| 4/5 | 0.80 | 80% |
6. Mathematical Operations
7. Python Implementation
from fractions import Fraction
train_split = Fraction(4, 5)
print(train_split)
# Output: 4/5Decimal conversion
train_split = 4 / 5
print(train_split)
# Output: 0.88. AI & Machine Learning Use Cases
Example 1 — Train/Test Split
Suppose a dataset has 1000 images.
- Training = 800
- Testing = 200
total_images = 1000
train = int(total_images * (4/5))
test = total_images - train
print(train, test)Output:
800 200Example 2 — Validation Split
Dataset = 10,000 samples
| Fraction | Samples |
|---|---|
| 7/10 | 7000 |
| 2/10 | 2000 |
| 1/10 | 1000 |
This is a 70/20/10 dataset split.
Example 3 — Probability
A model predicts:
- Cat = 3/4
- Dog = 1/4
Converted to percentages:
- Cat = 75%
- Dog = 25%
9. Real-World AI Examples
| AI Task | Fraction |
|---|---|
| Dataset Split | 4/5 |
| Validation | 1/10 |
| Sampling | 1/100 |
| Mini Dataset | 1/20 |
| Train Ratio | 7/10 |
10. Common Mistakes
Wrong
Writing dataset split as:
train = 4
test = 5This is not a fraction.
Correct
train_ratio = 4 / 5Wrong
Using fractions that don't total 1.
- Train = 3/4
- Test = 1/2
Total = 1.25 ❌
Correct
- Train = 4/5
- Test = 1/5
Total = 1 ✅
11. Interview Questions
Q1. What is a fraction?
A number representing a part of a whole.
Q2. What are numerator and denominator?
- Numerator → Selected parts
- Denominator → Total parts
Q3. Why are fractions used in ML?
To divide datasets into training, validation, and testing portions.
Q4. Convert 3/4 into decimal and percentage.
- Decimal = 0.75
- Percentage = 75%
12. Practice Questions
- Convert 1/2 to decimal.
- Convert 3/5 to percentage.
- A dataset has 500 samples. Find the training size using 4/5.
- Which is larger: 2/3 or 3/5?
- Why must train + test fractions equal 1?
Answers
- 0.5
- 60%
- 400
- 2/3
- Because they must represent the entire dataset.
13. One-Line Revision
Fractions represent parts of a whole and are used in AI for dataset splitting, probabilities, sampling, and proportional calculations.
Formula Sheet
Memory Rule: Part of Whole = Fraction
Percentages
1. Definition
A percentage means "per hundred". It expresses a value as a fraction of 100.
Examples: 10%, 50%, 80%, 95%, 99.8%
2. Principle
Percentages measure performance, proportions, and probabilities.
In AI, percentages are used to evaluate how well a model performs.
| AI Metric | Example |
|---|---|
| Accuracy | 95% |
| Precision | 92% |
| Recall | 88% |
| Confidence | 97% |
Rule: Performance = Percentage
3. Percentage Formula
Example
A model correctly predicts 95 images out of 100.
4. Visual Representation
80%
5. Convert Between Formats
| Percentage | Fraction | Decimal |
|---|---|---|
| 25% | 1/4 | 0.25 |
| 50% | 1/2 | 0.50 |
| 75% | 3/4 | 0.75 |
| 80% | 4/5 | 0.80 |
| 95% | 95/100 | 0.95 |
Conversion Formula
Percentage → Decimal
Example:
Decimal → Percentage
Example:
6. Python Implementation
Calculate Percentage
correct = 95
total = 100
accuracy = (correct / total) * 100
print(accuracy)Output:
95.0Convert Decimal to Percentage
confidence = 0.97
print(confidence * 100)Output:
97.07. AI & Machine Learning Use Cases
Example 1 — Accuracy
Suppose a classifier predicts:
- Correct = 980
- Total = 1000
correct = 980
total = 1000
accuracy = (correct / total) * 100
print(f"Accuracy: {accuracy}%")Example 2 — Confidence Score
confidence = 0.93Displayed to users as:
93%Example 3 — Dataset Split
1000 images
- Train = 80%
- Test = 20%
| Split | Samples |
|---|---|
| Train | 800 |
| Test | 200 |
8. Real-World AI Examples
| AI Application | Percentage |
|---|---|
| Image Classifier Accuracy | 96% |
| Spam Detection Precision | 91% |
| Face Recognition Confidence | 99% |
| OCR Accuracy | 98.5% |
| LLM Evaluation Score | 87% |
9. Common Mistakes
Wrong
accuracy = 95 / 100
print(accuracy)Output:
0.95This is a decimal, not a percentage.
Correct
accuracy = (95 / 100) * 100
print(accuracy)Output:
95.0Wrong
Treating 95 as a decimal.
confidence = 95Correct
confidence = 0.9510. Interview Questions
Q1. What does percentage mean?
A value expressed per hundred.
Q2. Write the percentage formula.
Q3. Difference between 0.95 and 95%?
| Value | Meaning |
|---|---|
| 0.95 | Decimal |
| 95% | Percentage |
Both represent the same quantity.
Q4. Why are percentages important in ML?
They communicate model performance in an easily understandable way.
11. Practice Questions
- Convert 60% to decimal.
- Convert 0.85 to percentage.
- A model predicts 180 correct out of 200. Find accuracy.
- Which is larger: 92% or 0.87?
- Why is confidence usually shown as a percentage?
Answers
- 0.60
- 85%
- 90%
- 92%
- It is easier for humans to interpret.
12. One-Line Revision
Percentages express values per hundred and are used in AI to measure accuracy, precision, recall, confidence, and overall model performance.
Formula Sheet
Memory Rule: Performance = Percentage
Ratios
1. Definition
A ratio compares two or more quantities and shows their relationship.
Examples: 1:1, 2:1, 4:5, 16:9, 80:20
Key idea: A ratio compares values; it does not represent a part of a whole by itself.
2. Principle
Ratios express comparison between quantities.
In AI, ratios are used for dataset splits, image dimensions, class balance, and model evaluation.
| Ratio | Meaning |
|---|---|
| 80:20 | Train : Test |
| 70:15:15 | Train : Validation : Test |
| 16:9 | Image aspect ratio |
| 3:1 | Majority vs minority class |
Rule: Comparison = Ratio
3. Ratio Formula
If two quantities are A and B:
Example:
- Apples = 8
- Oranges = 2
This is called simplifying a ratio.
4. Visual Representation
Train : Test = 80 : 20
5. Simplifying Ratios
Example
Divide both sides by 4:
Another example:
| Original | Simplified |
|---|---|
| 12:4 | 3:1 |
| 80:20 | 4:1 |
| 100:50 | 2:1 |
6. Ratio vs Fraction vs Percentage
| Type | Example | Purpose |
|---|---|---|
| Ratio | 80:20 | Compare |
| Fraction | 4/5 | Part of whole |
| Percentage | 80% | Per hundred |
Conversion
Ratio → Fraction
Ratio → Percentage
7. Python Implementation
Dataset Ratio
train = 80
test = 20
ratio = train / test
print(ratio)Output:
4.0Convert Ratio to Samples
total = 1000
train = int(total * (80/100))
test = total - train
print(train, test)Output:
800 2008. AI & Machine Learning Use Cases
Example 1 — Dataset Split
Dataset = 5000 images
Ratio = 80:20
| Split | Samples |
|---|---|
| Train | 4000 |
| Test | 1000 |
Example 2 — Train / Validation / Test
Ratio = 70:15:15
Dataset = 10,000
| Split | Samples |
|---|---|
| Train | 7000 |
| Validation | 1500 |
| Test | 1500 |
Example 3 — Image Aspect Ratio
A monitor has:
- Width = 1920
- Height = 1080
This is the standard widescreen ratio.
Example 4 — Imbalanced Dataset
Suppose:
- Cats = 900
- Dogs = 100
This tells us the dataset is imbalanced.
9. Real-World AI Examples
| AI Task | Ratio |
|---|---|
| Train/Test | 80:20 |
| Train/Val/Test | 70:15:15 |
| Image Resolution | 16:9 |
| Class Imbalance | 9:1 |
| Sampling | 1:10 |
10. Common Mistakes
Wrong
Confusing ratio with percentage.
80:20 = 80%Incorrect.
Correct
- Ratio = 80:20
- Fraction = 4/5
- Percentage = 80%
Wrong
Using ratios that don't match the total.
Example:
Train = 70
Validation = 20
Test = 20
Total = 110 ❌
Correct
11. Interview Questions
Q1. What is a ratio?
A comparison between two or more quantities.
Q2. Difference between ratio and fraction?
| Ratio | Fraction |
|---|---|
| Compares values | Represents part of whole |
| 80:20 | 4/5 |
Q3. Why is 80:20 commonly used in ML?
It provides a good balance between training data and evaluation data.
Q4. What does 16:9 represent?
An image or screen aspect ratio.
12. Practice Questions
- Simplify 40:20.
- Convert 80:20 into a fraction.
- Convert 3:1 into a percentage of the first value.
- A dataset has 600 samples using 4:1 ratio. Find train and test samples.
- Which represents comparison: Ratio or Fraction?
Answers
- 2:1
- 4/5
- 75%
- Train = 480, Test = 120
- Ratio
13. One-Line Revision
A ratio compares two or more quantities and is used in AI for dataset splits, aspect ratios, class balance, and proportional comparisons.
Formula Sheet
Memory Rule: Compare = Ratio
Scientific Notation
1. Definition
Scientific notation is a compact way to write very large or very small numbers using powers of 10.
Where:
- a = coefficient (1 ≤ a < 10)
- 10 = base
- n = exponent (positive or negative)
Examples
| Scientific | Decimal |
|---|---|
| 1 × 10³ | 1,000 |
| 5 × 10² | 500 |
| 1 × 10⁻³ | 0.001 |
| 1 × 10⁻⁵ | 0.00001 |
Rule: Very small or very large numbers = Scientific Notation
2. Principle
Instead of writing long decimals like:
AI engineers write:
or in Python:
1e-8This improves readability, precision, and consistency.
3. Formula
General Formula
Positive Exponent
Move the decimal right.
Negative Exponent
Move the decimal left.
4. Visual Representation
Positive Exponents
Negative Exponents
Memory Rule
- Positive exponent → Move decimal Right
- Negative exponent → Move decimal Left
5. Conversion Table
| Scientific | Decimal |
|---|---|
| 1e1 | 10 |
| 1e2 | 100 |
| 1e3 | 1,000 |
| 1e6 | 1,000,000 |
| 1e-1 | 0.1 |
| 1e-2 | 0.01 |
| 1e-3 | 0.001 |
| 1e-5 | 0.00001 |
| 1e-8 | 0.00000001 |
Note: In Python,
1e-5means 1 × 10⁻⁵.
6. Python Implementation
Writing Scientific Notation
learning_rate = 1e-3
epsilon = 1e-8
weight_decay = 5e-4
print(learning_rate)
print(epsilon)Output:
0.001
1e-08Verify Values
print(1e-5)
print(2.5e3)Output:
0.00001
2500.07. AI & Machine Learning Use Cases
Example 1 — Learning Rate
learning_rate = 1e-3Equivalent to:
This controls how much weights are updated during training.
Example 2 — Adam Optimizer
epsilon = 1e-8Used to prevent division by zero in optimization algorithms.
Example 3 — Weight Decay
weight_decay = 5e-4Equivalent to:
Used for regularization to reduce overfitting.
Example 4 — BERT Fine-Tuning
Typical learning rates:
| Scientific | Decimal |
|---|---|
| 5e-5 | 0.00005 |
| 3e-5 | 0.00003 |
| 2e-5 | 0.00002 |
These values appear in almost every Transformer training script.
8. Real-World AI Examples
| Parameter | Value |
|---|---|
| CNN Learning Rate | 1e-3 |
| BERT LR | 2e-5 |
| GPT Fine-Tuning LR | 5e-5 |
| Adam Epsilon | 1e-8 |
| Weight Decay | 5e-4 |
9. Common Mistakes
Wrong
learning_rate = 0.0000000001Hard to read.
Correct
learning_rate = 1e-10Wrong
Confusing 1e-3 with 10^-3.
1e-3 means:
Not:
10. Interview Questions
Q1. What is scientific notation?
A compact way to represent very large or very small numbers using powers of 10.
Q2. What does 1e-5 mean?
Q3. Why do AI engineers prefer 1e-5?
Because it is easier to read, less error-prone, and commonly used in ML frameworks.
Q4. Where is scientific notation used in AI?
- Learning rates
- Adam optimizer
- Weight decay
- Numerical stability constants
11. Practice Questions
- Convert
1e3to decimal. - Convert
5e-4to decimal. - Write
0.00001in scientific notation. - Which is larger:
1e-3or1e-5? - Why is
1e-8used in Adam?
Answers
- 1000
- 0.0005
- 1e-5
- 1e-3
- To improve numerical stability and avoid division by zero.
12. One-Line Revision
Scientific notation represents extremely large and small numbers using powers of 10 and is widely used in AI for learning rates, optimizers, and numerical stability.
Formula Sheet
Memory Rule: Positive exponent → Right · Negative exponent → Left
Logarithms
1. Definition
A logarithm answers one question:
"To what power must the base be raised to produce a number?"
Where:
- b = Base
- x = Number
- y = Exponent
Example
Because:
| Logarithm | Answer |
|---|---|
| log₂(8) | 3 |
| log₁₀(100) | 2 |
| log₂(16) | 4 |
| ln(e) | 1 |
2. Principle
Logarithms measure exponential growth, information, and uncertainty.
In AI they are fundamental to:
- Cross-Entropy Loss
- Information Theory
- Decision Trees
- Language Models
- Entropy
Rule: Information = Logarithm
3. Relationship Between Exponents & Logarithms
They are inverse operations.
| Exponential | Logarithm |
|---|---|
| 2³ = 8 | log₂(8) = 3 |
| 10² = 100 | log₁₀(100) = 2 |
4. Types of Logarithms
Base 2
Used in:
- Entropy
- Information theory
- Decision trees
Base 10
Used in:
- Scientific calculations
- Orders of magnitude
Natural Log
Used in:
- Machine learning optimization
- Cross-entropy
- Probability distributions
5. Logarithm Graph
As x increases, the logarithm grows slowly.
Example:
| x | log₂(x) |
|---|---|
| 2 | 1 |
| 4 | 2 |
| 8 | 3 |
| 16 | 4 |
| 32 | 5 |
6. Python Implementation
Natural Log
import math
print(math.log(10))Base 2
import math
print(math.log2(8))Output:
3.0Base 10
import math
print(math.log10(1000))Output:
3.07. AI & Machine Learning Use Cases
Example 1 — Cross-Entropy Loss
The most important loss function in classification.
Where:
- y = True label
- ŷ = Predicted probability
Suppose:
- True = 1
- Prediction = 0.9
Smaller loss = Better prediction.
Example 2 — Decision Tree Entropy
Entropy measures disorder.
Example:
- Cat = 50%
- Dog = 50%
Higher entropy = More uncertainty.
Example 3 — Language Models
LLMs predict token probabilities.
| Token | Probability |
|---|---|
| cat | 0.70 |
| dog | 0.20 |
| bird | 0.10 |
The loss is calculated using log probabilities.
8. Real-World AI Examples
| AI System | Logarithm Used |
|---|---|
| GPT | Cross-Entropy |
| BERT | Log Loss |
| Decision Trees | Entropy |
| CNN Classifier | Negative Log Likelihood |
| Reinforcement Learning | Log Probability |
9. Common Mistakes
Wrong
Thinking:
Correct
Wrong
Ignoring the base.
Incorrect unless the base is 2.
Correct
10. Interview Questions
Q1. What is a logarithm?
A logarithm finds the exponent required to produce a number.
Q2. Why are logarithms important in ML?
Because they measure information and are used in loss functions like Cross-Entropy.
Q3. Difference between log₂ and ln?
| log₂ | ln |
|---|---|
| Base 2 | Base e |
| Entropy | Optimization |
Q4. Where is logarithm used in GPT?
During Cross-Entropy Loss for next-token prediction.
11. Practice Questions
- Find log₂(16).
- Find log₁₀(1000).
- Which log is used in entropy?
- Which loss function uses logarithms?
- Why does a correct prediction produce lower log loss?
Answers
- 4
- 3
- Base 2
- Cross-Entropy
- Because high predicted probability gives a smaller negative log value.
12. One-Line Revision
Logarithms measure exponents, information, and uncertainty, making them essential for Cross-Entropy Loss, entropy, and language model training.
Formula Sheet
Memory Rule: Information = Logarithm