Answers.Body: <p>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 <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html" rel="nofollow noreferrer">here.</a></p>
  <pre><code>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')
  </code></pre>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-27T21:05:25.053Z
Answers.LastActivityDate: 2021-01-27T21:05:25.053Z
Answers.UserDisplayName: Gerry P
Body: <p>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.</p>
  <p>I think there are a number of approaches:</p>
  <ol>
  <li>Convert the data into an integer, and include it directly in the model as a feature.</li>
  <li>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.</li>
  </ol>
  <p>What are your thoughts on these two options? Are there any alternative methods?</p>
  
Tags: <machine-learning><gradient-boosting>
Title: House price inflation modelling
UserDisplayName: Melly Donald
ThreadText: # House price inflation modelling
  
  (Asked by: username_0 on 2021-01-26)
  
  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?
  
  **Tags:** machine-learning, gradient-boosting
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-01-27. Score: 1 | Accepted answer
  
  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.](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html)
  
  ```
  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.
  
  
  ---
  
  