I have a "year" variable but I don't know which is the best way to handle it for a ML model, as it is a numerical variable, giving some sequence. Should I treat it as a categorical variable?
Thanks in advance,
I have a "year" variable but I don't know which is the best way to handle it for a ML model, as it is a numerical variable, giving some sequence. Should I treat it as a categorical variable?
Thanks in advance,
Year or indeed any time dimension is a hard thing to include into a ML model because it begs one question:
Are we looking at a time series or not?
Time series behave categorically different than data that is not ordered sequentially and we have to model them differently.
You could treat year/time like any other dimension and use it as a predictor in a regression-based model. But that would not be ideal!
Instead try to use models that are suited to time series analysis like ARIMA or even deep learning models like LTSTM.
A straight-forward way to treat this would be to model a simple prediction based on a time-series model like ARIMA and then build a second model on top that takes in all the other predictors and tries to predict the residuals from the time series model.
First of all I would suggest you to analyze the data. Do you really need the year? Have you studied the correlation with the other variables? I mean, study the domain of the model you intend to create before create any model.
You can treat year as categorical variable and use some of the techniques such as One Hot Ecoding or Dummy Variables for better performance. You could also perform a normalization of the years, treating them as numerical variables, which are between 0 and 1.
The most important thing is to know what we are going to do to make good use of the information or data.
Your problem statement is not really clear but from what I have read seems that you could use Year as the index in order to do time series validation splitting. You can read a bit about it here and use the implementations of sktime by Alan Turing Institute or classic scikit learn.
This will allow you to evaluate the performance of your model in a production environment since given the nature of your problem (real state) you will want to predict the prices for next given year.
So, rather than using it as a feature, indexing by it and then splitting.
If you are interested in using it as a feature you can calculate elapsed time from the first year and this will help the model to see if there is a trend over time. Or as categorical and do target encodings.