A variableis like a labeled box that stores data in memory.
In ML, variables help us manage:
Data (features, labels)
Hyperparameters (learning rate, epochs)
Results (accuracy, loss)
👉 Think: variable = value
x =5name ="Mr Nerd"price =19.99is_active =True
Notes:
x → integer (int)
name → string (str)
price → float (float)
is_active → Boolean (bool)
Python auto-detects types (no need to declare).
2. Naming Variables (Very Important in ML!)
Python allows flexible names, but ML projects need clarity.
Valid:
Invalid:
Best Practices (PEP8 style):
Use lowercase + underscores → train_data, test_accuracy
Be descriptive → input_vector instead of iv
Avoid keywords (class, def, etc.)
3. Updating Variables
Variables can be updated anytime.
4. Common Data Types in ML
ML Use Cases:
int, float → parameters (epochs, learning rate)
str → model names, labels
list, tuple → feature vectors
dict → configs, hyperparameters
5. Practical Use in ML
6. Multiple Assignments
You can assign multiple values at once:
7. Constants
Python doesn’t enforce constants, but conventionally:
👉 Uppercase = do not change.
8. Type Checking (Debugging in ML)
Helps avoid type errors in training code.
9. Variable Scope
Variables inside functions are local, outside are global.
Output:
10. Dynamic Typing
Python allows changing variable types:
⚠️ Be careful in ML — type mix-ups cause bugs.
11. Variables in NumPy
NumPy is essential in ML.
Output:
12. Summary Table
Feature
Example
Notes
Basic variable
x = 5
Auto-detects type
Multiple assign
x, y = 1, 2
Split values
Type check
type(x)
Debugging help
Update value
x += 1
Shortcut
Store params
params = {"lr": 0.01}
Common in ML configs
Constants
EPOCHS = 100
Use ALL_CAPS
13. Video Tutorial
💖 Support Our Work
If you find this post helpful and would like to support my work, you can send a donation via TRC-20 (USDT). Your contributions help us keep creating and sharing more valuable content.