Creating
Derived Variables
Transform raw data into powerful new features that unlock deeper insights and drive smarter business decisions.
What Are Derived Variables?
A derived variable is a new column created by applying a transformation, calculation, or logical rule to one or more existing columns in your dataset. Instead of collecting new data, you engineer features from what you already have.
Why Derived Variables Matter
The Transformation Pipeline
Core Formula Types
Derived vs. Raw Variables
| Raw Variable | Derived Variable | |
|---|---|---|
| Source | Collected directly | Calculated from raw data |
| Example | Revenue, Date, Units Sold | Profit Margin, Day of Week |
| Storage | Original dataset | Added as new column |
| Updates | Changes when new data arrives | Must be recalculated |
| Purpose | Record observations | Enhance analysis power |
What Are Feature Columns?
In machine learning and predictive analytics, a feature column (or simply feature) is any input variable used by a model to make predictions. Derived variables become feature columns when they are fed into an analytical model.
How to Create Derived Variables
Example 1: Profit Margin
Example 2: Growth Rate
A retail chain wants to know how each store's sales changed from last year to this year. We derive a year-over-year growth rate.
Example 3: Conditional Categories
A marketing team wants to label customers as High, Medium, or Low value based on their total spending. This creates a categorical derived variable.
Example 4: Date Extraction
A single date column like "2024-03-15" can yield multiple derived features that reveal seasonality and timing patterns.
Text-Based Derivations
Text columns hold valuable information that can be extracted using string operations: splitting, searching, counting, and transforming.
Combining Multiple Derivations
Real-world analytics often chains several derived variables together. Each derived column can serve as input for the next.
Common Mistakes to Avoid
Summary: Derivation Techniques
| Technique | Operation | Example Output |
|---|---|---|
| Arithmetic | \( A + B \), \( A - B \), \( A \times B \) | Profit, Total Cost |
| Ratio | \( \frac{A}{B} \times 100 \) | Margin %, Growth % |
| Conditional | \(\text{IF/ELSE}\) logic | Tier Label, Risk Flag |
| Aggregation | \(\text{SUM}\), \(\text{AVG}\), \(\text{COUNT}\) per group | Avg Order Value |
| Date Parsing | Extract year, month, day | Quarter, Is Weekend |
| Text Parsing | Split, search, count | Domain, Word Count |
Question 1 of 5
A company has columns for Revenue and Cost. Which formula correctly computes the profit margin percentage?
Question 2 of 5
Extracting the day of the week from a date column is an example of which derivation technique?
Question 3 of 5
Store A had $400K in sales last year and $500K this year. What is the year-over-year growth rate?
Question 4 of 5
Which of the following is a derived variable rather than a raw variable?
Question 5 of 5
A dataset has a "Revenue" column where some rows contain \( \$0 \). You want to calculate \( \text{Cost} / \text{Revenue} \). What is the primary risk?