0
0
ML Pythonml~12 mins

Date and time feature extraction in ML Python - Model Pipeline Trace

Choose your learning style9 modes available
Model Pipeline - Date and time feature extraction

This pipeline shows how raw date and time data is changed into useful features for a machine learning model. It helps the model understand patterns related to time, like days of the week or hours of the day.

Data Flow - 4 Stages
1Raw data input
1000 rows x 1 columnDataset with a single column of timestamps (date and time strings)1000 rows x 1 column
['2024-06-01 14:23:45', '2024-06-02 09:15:00', '2024-06-03 20:05:30']
2Convert to datetime object
1000 rows x 1 columnParse strings into datetime objects for easier extraction1000 rows x 1 column
[datetime(2024,6,1,14,23,45), datetime(2024,6,2,9,15,0), datetime(2024,6,3,20,5,30)]
3Feature extraction
1000 rows x 1 columnExtract year, month, day, weekday, hour, minute, second as separate columns1000 rows x 7 columns
[[2024, 6, 1, 5, 14, 23, 45], [2024, 6, 2, 6, 9, 15, 0], [2024, 6, 3, 0, 20, 5, 30]]
4Model input preparation
1000 rows x 7 columnsUse extracted features as input to train a model1000 rows x 7 columns
Numerical features ready for model training
Training Trace - Epoch by Epoch
Loss
1.0 |          *
0.8 |        *  
0.6 |      *    
0.4 |    *      
0.2 |  *        
0.0 +-----------
      1 2 3 4 5
      Epochs
EpochLoss ↓Accuracy ↑Observation
10.850.55Model starts learning with high loss and low accuracy
20.650.70Loss decreases and accuracy improves as model learns time patterns
30.500.78Model continues to improve with clearer time feature understanding
40.400.83Loss lowers steadily, accuracy rises, showing good learning progress
50.350.86Model converges with stable loss and high accuracy
Prediction Trace - 9 Layers
Layer 1: Input timestamp
Layer 2: Extract year
Layer 3: Extract month
Layer 4: Extract day
Layer 5: Extract weekday
Layer 6: Extract hour
Layer 7: Extract minute
Layer 8: Extract second
Layer 9: Model prediction
Model Quiz - 3 Questions
Test your understanding
What is the shape of the data after extracting date and time features?
A1000 rows x 1 column
B700 rows x 7 columns
C1000 rows x 7 columns
D1000 rows x 14 columns
Key Insight
Extracting date and time features turns raw timestamps into meaningful numbers that help the model learn patterns related to time, improving prediction accuracy.