S6-SA2-0434
What is the Use of Trigonometry in Machine Learning for Feature Engineering?
Grade Level:
Class 10
AI/ML, Physics, Biotechnology, Space Technology, Chemistry, Engineering, Medicine
Definition
What is it?
Trigonometry helps Machine Learning models understand patterns in data that repeat, like daily temperature changes or sound waves. In 'Feature Engineering,' we use trigonometric functions (like sine and cosine) to transform raw data into new, more useful features that highlight these repeating cycles for the ML model.
Simple Example
Quick Example
Imagine you want to predict how many cups of chai a shop will sell each hour. Sales usually go up in the morning and evening, and down in the afternoon. This is a daily cycle. Trigonometry can help convert the 'hour of the day' (e.g., 9 AM, 3 PM) into a value that tells the ML model 'it's morning peak' or 'it's afternoon low' more clearly, making predictions better.
Worked Example
Step-by-Step
Let's say we have 'Time of Day' data in hours, from 0 (midnight) to 23 (11 PM), and we want to create a cyclical feature.
Step 1: Understand the cycle. A day has 24 hours. So, our cycle length is 24.
---Step 2: Convert the time into an angle. We can use the formula: `angle = (time / cycle_length) * 2 * pi`. Let's take 'Time = 6 hours' (6 AM).
---Step 3: Calculate the angle for Time = 6. `angle = (6 / 24) * 2 * pi = (1/4) * 2 * pi = 0.5 * pi` (approximately 1.57 radians).
---Step 4: Apply sine and cosine functions. `Sine_feature = sin(angle)` and `Cosine_feature = cos(angle)`.
---Step 5: Calculate the values. `Sine_feature = sin(0.5 * pi) = 1`. `Cosine_feature = cos(0.5 * pi) = 0`.
---Step 6: For Time = 18 hours (6 PM), calculate the angle. `angle = (18 / 24) * 2 * pi = (3/4) * 2 * pi = 1.5 * pi` (approximately 4.71 radians).
---Step 7: Calculate the values for Time = 18. `Sine_feature = sin(1.5 * pi) = -1`. `Cosine_feature = cos(1.5 * pi) = 0`.
Answer: For 6 AM, the features are (Sine=1, Cosine=0). For 6 PM, they are (Sine=-1, Cosine=0). These pairs uniquely represent the time within the 24-hour cycle, helping the ML model.
Why It Matters
Understanding cyclical patterns is crucial in many fields. For example, in predicting weather patterns (Physics), analyzing heartbeats (Medicine), or optimizing traffic flow (Engineering). This skill can lead to careers in data science, AI research, and even space technology at organizations like ISRO.
Common Mistakes
MISTAKE: Using only sine or only cosine for cyclical features. | CORRECTION: Always use both sine and cosine together. Using only one can confuse the model because two different times (e.g., 6 AM and 6 PM) can have the same sine value but are distinct.
MISTAKE: Not normalizing the time data to the cycle length before applying trigonometry. | CORRECTION: Make sure to divide the time value by the total cycle length (e.g., 24 for hours in a day, 12 for months in a year) to get a fraction of the cycle, then multiply by 2*pi.
MISTAKE: Forgetting that trigonometric functions expect angles in radians, not degrees. | CORRECTION: When using programming libraries for sine/cosine, ensure your angle is calculated in radians (by multiplying by 2*pi) or convert degrees to radians if you started with degrees.
Practice Questions
Try It Yourself
QUESTION: A sensor records temperature every hour. If the cycle length is 24 hours, what is the angle (in radians) for the 12th hour (noon)? | ANSWER: (12 / 24) * 2 * pi = pi radians (approximately 3.14)
QUESTION: For the 12th hour (noon), calculate the sine and cosine features using the angle from Q1. | ANSWER: Sine_feature = sin(pi) = 0, Cosine_feature = cos(pi) = -1
QUESTION: You are tracking monthly sales, and the cycle is 12 months. For the 3rd month (March), calculate the sine and cosine features. | ANSWER: Angle = (3 / 12) * 2 * pi = 0.5 * pi. Sine_feature = sin(0.5 * pi) = 1, Cosine_feature = cos(0.5 * pi) = 0
MCQ
Quick Quiz
Why is it important to use both sine and cosine functions when creating cyclical features from time data?
To make the calculations faster for the machine learning model.
To ensure that each point in the cycle has a unique representation, avoiding ambiguity.
Because machine learning models only understand pairs of values.
To increase the complexity of the feature engineering process.
The Correct Answer Is:
B
Using both sine and cosine creates a unique (x, y) coordinate for each point in the cycle, ensuring the model can distinguish between different points that might have the same sine or cosine value alone.
Real World Connection
In the Real World
Imagine an app like 'Swiggy' or 'Zomato' trying to predict demand for food delivery. They need to know when people order most – lunch rush, dinner peak, late-night cravings. By using trigonometry to feature engineer the 'time of day' or 'day of week,' their ML models can better predict demand, optimize delivery routes, and ensure enough delivery partners are available, making your food arrive faster.
Key Vocabulary
Key Terms
FEATURE ENGINEERING: The process of creating new input features for a machine learning model from existing data to improve model performance. | CYCLICAL DATA: Data that repeats in a regular pattern, like time of day, day of week, or months of a year. | SINE FUNCTION: A trigonometric function that describes the vertical position of a point on a circle as it rotates. | COSINE FUNCTION: A trigonometric function that describes the horizontal position of a point on a circle as it rotates. | RADIANS: A unit for measuring angles, where one full rotation is 2*pi radians.
What's Next
What to Learn Next
Next, explore 'One-Hot Encoding' for categorical data. While trigonometry is great for cyclical numbers, One-Hot Encoding helps ML models understand non-numerical categories like 'city' or 'color' by turning them into numbers in a different way. Keep building your feature engineering toolkit!


