๐ธ SeasonLayer
๐ธ SeasonLayer
๐ฏ Overview
The SeasonLayer adds seasonal information based on the month, encoding it as a one-hot vector for the four seasons: Winter, Spring, Summer, and Fall. This layer is essential for temporal feature engineering where seasonal patterns are important.
This layer takes date components and adds seasonal information, making it perfect for time series analysis, weather forecasting, and any application where seasonal patterns matter.
๐ How It Works
The SeasonLayer processes date components through seasonal encoding:
- Month Extraction: Extracts month from date components
- Season Classification: Classifies months into four seasons:
- Winter: December (12), January (1), February (2)
- Spring: March (3), April (4), May (5)
- Summer: June (6), July (7), August (8)
- Fall: September (9), October (10), November (11)
- One-Hot Encoding: Creates one-hot vectors for each season
- Feature Combination: Combines original date components with seasonal features
- Output Generation: Produces 8-dimensional feature vector
graph TD
A[Date Components: year, month, day, day_of_week] --> B[Extract Month]
B --> C[Season Classification]
C --> D[Winter: Dec, Jan, Feb]
C --> E[Spring: Mar, Apr, May]
C --> F[Summer: Jun, Jul, Aug]
C --> G[Fall: Sep, Oct, Nov]
D --> H[One-Hot Encoding]
E --> H
F --> H
G --> H
A --> I[Original Components]
H --> I
I --> J[Combined Features: 8 dimensions]
style A fill:#e6f3ff,stroke:#4a86e8
style J fill:#e8f5e9,stroke:#66bb6a
style B fill:#fff9e6,stroke:#ffb74d
style C fill:#f3e5f5,stroke:#9c27b0
style H fill:#e1f5fe,stroke:#03a9f4
๐ก Why Use This Layer?
| Challenge | Traditional Approach | SeasonLayer's Solution |
|---|---|---|
| Seasonal Patterns | Manual season calculation | ๐ฏ Automatic season classification and encoding |
| Temporal Features | Separate season processing | โก Integrated seasonal information with date components |
| One-Hot Encoding | Manual one-hot encoding | ๐ง Built-in one-hot encoding for seasons |
| Feature Engineering | Complex season extraction | ๐ Simple seasonal feature addition |
๐ Use Cases
- Weather Forecasting: Adding seasonal context to weather predictions
- Sales Analysis: Analyzing seasonal sales patterns
- Agricultural Planning: Incorporating seasonal information for crop planning
- Energy Consumption: Predicting energy usage based on seasons
- Event Planning: Considering seasonal factors in event planning
๐ Quick Start
Basic Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
In a Sequential Model
1 2 3 4 5 6 7 8 9 10 11 | |
In a Functional Model
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
Advanced Configuration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
๐ API Reference
kerasfactory.layers.SeasonLayer
SeasonLayer for adding seasonal information based on month.
This layer adds seasonal information based on the month, encoding it as a one-hot vector for the four seasons: Winter, Spring, Summer, and Fall.
Classes
SeasonLayer
1 | |
Layer for adding seasonal information based on month.
This layer adds seasonal information based on the month, encoding it as a one-hot vector for the four seasons: Winter, Spring, Summer, and Fall.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs |
Additional layer arguments |
{}
|
Input shape
Tensor with shape: (..., 4) containing [year, month, day, day_of_week]
Output shape
Tensor with shape: (..., 8) containing the original 4 components plus
4 one-hot encoded season values
Initialize the layer.
Source code in kerasfactory/layers/SeasonLayer.py
30 31 32 | |
Functions
1 2 3 | |
Compute the output shape of the layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_shape |
Shape of the input tensor |
required |
Returns:
| Type | Description |
|---|---|
tuple[tuple[int, ...], tuple[int, ...]]
|
Output shape |
Source code in kerasfactory/layers/SeasonLayer.py
106 107 108 109 110 111 112 113 114 115 116 117 118 | |
๐ง Parameters Deep Dive
No Parameters
- Purpose: This layer has no configurable parameters
- Behavior: Automatically classifies months into four seasons
- Output: Always produces 8-dimensional output (4 original + 4 seasonal)
๐ Performance Characteristics
- Speed: โกโกโกโก Very fast - simple conditional logic
- Memory: ๐พ Low memory usage - no additional parameters
- Accuracy: ๐ฏ๐ฏ๐ฏ๐ฏ Excellent for seasonal feature extraction
- Best For: Temporal data requiring seasonal information
๐จ Examples
Example 1: Weather Prediction with Seasons
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
Example 2: Sales Analysis with Seasonal Patterns
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
Example 3: Seasonal Feature Analysis
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
๐ก Tips & Best Practices
- Input Format: Input must be [year, month, day, day_of_week] format
- Season Classification: Automatically classifies months into four seasons
- One-Hot Encoding: Produces one-hot encoded seasonal features
- Feature Combination: Combines original date components with seasonal features
- Neural Networks: Works well with neural networks for seasonal patterns
- Integration: Combines well with other temporal processing layers
โ ๏ธ Common Pitfalls
- Input Shape: Must be (..., 4) tensor with date components
- Component Order: Must be [year, month, day, day_of_week] in that order
- Data Type: Input should be float32 tensor
- Missing Values: Doesn't handle missing values - preprocess first
- Season Definition: Uses standard Northern Hemisphere season definitions
๐ Related Layers
- DateParsingLayer - Date string parsing
- DateEncodingLayer - Cyclical date encoding
- CastToFloat32Layer - Type casting utility
- DifferentiableTabularPreprocessor - End-to-end preprocessing
๐ Further Reading
- Seasonal Patterns in Time Series - Seasonality concepts
- One-Hot Encoding - One-hot encoding techniques
- Temporal Feature Engineering - Feature engineering techniques
- KerasFactory Layer Explorer - Browse all available layers
- Data Preprocessing Tutorial - Complete guide to data preprocessing