0
0
ML Pythonml~5 mins

Date and time feature extraction in ML Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is date and time feature extraction in machine learning?
It is the process of taking raw date and time data and turning it into useful pieces of information (features) that a machine learning model can understand and use to make predictions.
Click to reveal answer
beginner
Name three common features extracted from a date-time value.
Year, month, day of the week, hour, minute, and second are common features extracted from date-time values.
Click to reveal answer
beginner
Why might extracting the day of the week be useful for a model?
Because some patterns depend on the day, like sales being higher on weekends or traffic being heavier on weekdays.
Click to reveal answer
intermediate
How can you extract the hour from a timestamp in Python using pandas?
Use pandas' dt accessor: df['timestamp'].dt.hour extracts the hour part from a datetime column.
Click to reveal answer
intermediate
What is the benefit of extracting cyclical features like hour or month as sine and cosine values?
It helps the model understand that these features repeat in cycles, for example, hour 23 is close to hour 0, which normal numbers don't show well.
Click to reveal answer
Which feature is NOT typically extracted from a datetime value?
ADay of the week
BHour of the day
CUser's age
DMonth
Why do we sometimes convert hour or month into sine and cosine values?
ATo capture the cyclical nature of time
BTo make the data categorical
CTo reduce the number of features
DTo normalize the data between 0 and 1
Which Python library is commonly used to extract date and time features?
ANumPy
Bpandas
Cmatplotlib
Dscikit-learn
What does df['date'].dt.weekday return in pandas?
AThe day of the week as an integer (Monday=0)
BThe day of the month
CThe week number in the year
DThe month number
Which feature might help predict traffic patterns best?
AYear
BMicrosecond
CSecond
DDay of the week
Explain how you would extract useful features from a timestamp for a machine learning model.
Think about breaking down the timestamp into parts and representing repeating patterns.
You got /7 concepts.
    Why is it important to transform cyclical time features like hour or month before using them in models?
    Consider how time repeats and how numbers alone might mislead the model.
    You got /4 concepts.