Python machine learning: time multi-scale processing date variables

Factors such as month, season, and weekend may have an impact on the prediction of the result, and it is necessary to process and add features to the data set by yourself. Features can be processed by using time attributes such as month and weekday.

Time attributes commonly used in feature engineering:

Returns the month, such as January=1

dt.month

The week of the year, such as January 1 = 1

dt.weekofyear

The day of the week, if the corresponding date is Tuesday=2

dt.weekday

day of the week

dt.dayofweek

Other time attributes:
Series.dt.year returns the year
Series.dt.day returns the date
Series.dt.hour returns the hour
Series.dt.minute returns
the minute Series.dt.second returns the second
Series.dt.microsecond returns the microsecond
Series.dt .nanosecond returns nanoseconds


Examples of machining features:

data['policy_bind_date_weekday'] = data['policy_bind_date'].dt.weekday

Code explanation:

data is the original data set;

The brackets in data['policy_bind_date_weekday'] are the newly named features, which are used to store the newly processed features;

dt.weekday is to call the dt attribute of the series and return the day of the week;


operation result:

Contribution to auc:

Without the weekday feature:

 With weekday features:

 Conclusion: The result has improved by 4 thousandths, indicating that this feature is effective.

 

Guess you like

Origin blog.csdn.net/Sukey666666/article/details/128773733