2
$\begingroup$

I have a data set of house prices and their corresponding features (rooms, meter squared, etc). An additional feature is the sold date of the house. The aim is to create a model that can estimate the price of a house as if it was sold today. For example a house with a specific set of features (5 rooms, 100 meters squared) and today's date (28-1-2020), what would it sell for? Time is an important component, because prices increase (inflate over time). I am struggling to find a way to incorporate the sold date as a feature in the gradient boosting model.

I think there are a number of approaches:

  1. Convert the data into an integer, and include it directly in the model as a feature.
  2. Create a separate model for modelling the house price development over time. Let's think of this as some kind of an AR(1) model. I could then adjust all observations for inflation, so that we would get an inflation adjusted price for today. These inflation adjusted prices would be trained on the feature set.

What are your thoughts on these two options? Are there any alternative methods?

$\endgroup$
1
$\begingroup$

The sold date is a feature like any other. You can do this as follow. I am assuming the features are in a pandas data frame called df where the column date is called date. Easiest way is to use the pandas to_datetime function. Documentation is here.

def encode_dates(df, column):
    df = df.copy()
    df[column] = pd.to_datetime(df[column] )
    df[column + '_year'] = df[column].apply(lambda x: x.year)
    df[column + '_month'] = df[column].apply(lambda x: x.month)
    df[column + '_day'] = df[column].apply(lambda x: x.day)
    df = df.drop(column, axis=1)
    return df
df=encode_dates(df. 'date')

This function will modify the df data frame. It will create 3 new columns labeled date year, date month and date day and it will remove the date column from the data frame. Now these new columns along with the other features can be used to train your model.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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