2
$\begingroup$

What's the optimal way to encode a 'month' feature? A single integer value or 12 binary values don't quite grasp the concept of modulo distance...

Say I want to train an SVM for a certain task and believe that the time of the year might contribute some valuable information, how should I transform it into a feature? What's the general approach to encoding numerical values that sit on a ring rather than an axis when using linear classifiers?

$\endgroup$
5
  • $\begingroup$ Perhaps 12 binary variables, one for each month. $\endgroup$
    – iliasfl
    Commented Jul 23, 2014 at 7:46
  • 1
    $\begingroup$ What is optimal depends on your model. Please clarify what you need it to do. $\endgroup$
    – Glen_b
    Commented Jul 23, 2014 at 10:49
  • 1
    $\begingroup$ Can you clarify what the "certain task" is that you want the SVM to do? $\endgroup$ Commented Jul 23, 2014 at 20:03
  • $\begingroup$ It doesn't really matter, but if you insist, it's predicting the rating changes in some TV shows. $\endgroup$
    – Mongo
    Commented Jul 24, 2014 at 7:49
  • $\begingroup$ Embed on circle in R^2? angle = (month-1) * pi / 6 where month: January=1, February=2, ... enc = (cos(angle), sin(angle)) $\endgroup$
    – Matthew
    Commented May 17, 2022 at 14:35

1 Answer 1

5
$\begingroup$

There are several different choices available to you. What is "optimal" depends on the specific application, both in terms of your own needs & convenience (which YOU get to choose), and in terms of the quality of response of the Neural Network, Machine Learning algorithm, or whatever it is that you are trying to train. In many cases you will only find out what works best by trying the different alternatives.

Some possibilities are:

1) 12 different binary variables, e.g. JAN = 1 if actual month = January, otherwise 0; similarly for each succeeding month, e.g. FEB = 1 or 0, etc.

2) A single variable with 12 discrete values {Month = 1, 2, ..., 12} or equivalent. This might be OK if you really want to treat each month separately, but ...

3) If you are looking at forecasting temperature or rainfall for example, the weather itself really doesn't really care if it is 30th June or 1st July, so you might be better off using a decimal fraction of the year which then becomes a continuous variable changing day-by-day.

4) As you correctly point out, there is a potential problem of modulo distance, i.e. if you use numbers 1, ... , 12 then each month differs by 1 from the previous month, except for Dec=12 & Jan=1, so you may need to use something like: IF MONTH - PREVIOUS MONTH < 0 THEN MONTH DIFFERENCE = MONTH DIFFERENCE + 12.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.