Date transformation for KNN

I have data set with date features like 01/01/2019 and I would like to use KNN. However, I cannot find a good transformation for dates that has a meaningful distance result for the last feature.

For example:

f1 | 1 | 2 | 3 | 4 | 01/01/2019

f2 | 10 | 3 | 12 | 1 | 14/01/2019

Does anyone have any recommendations?

Topic k-nn data distance machine-learning

Category Data Science


You may consider the difference in number of days between each available date and the current day. The larger the number, the older the date will be.


Find the time difference in an appropriate granularity(/ies):

daysDiffFeature = diffInDays(dateCol)
hoursDiffFeature = diffInHours(dateCol)

Then you can use whatever distance based metrics/calculations are required in your algorithsm

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.