hpipy.extensions.RandomForestIndex#

class hpipy.extensions.RandomForestIndex(**kwargs)[source]

Bases: HedonicIndex

Random forest house price index.

Estimates the relationship between independent and dependent variables using a random forest model. Extracts the coefficients of temporal variables to represent the marginal contribution of each time period. Explainability methods are used to assess the conditional marginal impact of each time period on price changes, which are converted into an index.

Methods

__init__

Initialize base house price index.

coef_to_index

Convert coefficients to an index.

create_index

Create the index.

create_series

Create a series from the index.

from_model

Create an index from a house price model.

get_data

Get hedonic transaction data.

get_model

Get a random forest house price model.

smooth_index

Smooth the index.

smooth_series

Apply smoothing to all indices.

Attributes

Parameters:

kwargs (Any)

static get_model()[source]

Get a random forest house price model.

Return type:

type[BaseHousePriceModel]

__init__(**kwargs)

Initialize base house price index.

Parameters:

kwargs (Any)

Return type:

None

static coef_to_index(coef_df, log_dep, base_price=1)

Convert coefficients to an index.

Parameters:
  • coef_df (pd.DataFrame) – Coefficients.

  • log_dep (bool) – Log dependent variable.

  • base_price (float, optional) – Base price. Defaults to 1.

Returns:

Index and imputed values.

Return type:

tuple[np.ndarray, np.ndarray]

classmethod create_index(trans_data, prop_id=None, trans_id=None, price=None, seq_only=True, max_period=None, smooth=False, periodicity=None, min_date=None, max_date=None, adj_type=None, **kwargs)

Create the index.

Parameters:
  • trans_data (TransactionData | PeriodTable | pd.DataFrame) – Input transaction data.

  • prop_id (str | None, optional) – Property identifier. Defaults to None.

  • trans_id (str | None, optional) – Transaction identifier. Defaults to None.

  • price (str | None, optional) – Price column name. Defaults to None.

  • seq_only (bool, optional) – Sequential only. Defaults to True.

  • max_period (int | None, optional) – Maximum index period. Defaults to None.

  • smooth (bool, optional) – Smooth the index. Defaults to False.

  • periodicity (str | None, optional) – Periodicity of the index. Defaults to None.

  • min_date (str | None, optional) – Minimum date for the index. Defaults to None.

  • max_date (str | None, optional) – Maximum date for the index. Defaults to None.

  • adj_type (str | None, optional) – Adjustment type. Defaults to None.

  • **kwargs – Additional keyword arguments.

Returns:

Index object.

Return type:

Self

create_series(train_period=12, max_period=None, **kwargs)

Create a series from the index.

Parameters:
  • train_period (int, optional) – Train period for the series. Defaults to 12.

  • max_period (int | None, optional) – Maximum period for the series. Defaults to None.

  • **kwargs – Additional keyword arguments.

Returns:

Index object.

Return type:

Self

classmethod from_model(model, trans_data=None, max_period=None, smooth=False, **kwargs)

Create an index from a house price model.

Parameters:
  • model (BaseHousePriceModel) – House price model object.

  • trans_data (TransactionData | None, optional) – Transaction data object. Defaults to None.

  • max_period (int | None, optional) – Maximum period for the index. Defaults to None.

  • smooth (bool, optional) – Smooth the index. Defaults to False.

  • **kwargs – Additional keyword arguments.

Returns:

Index object.

Return type:

Self

static get_data()

Get hedonic transaction data.

Return type:

type[TransactionData]

smooth_index(order=3, in_place=False)

Smooth the index.

Parameters:
  • order (list[int] | int, optional) – Smoothing order. Defaults to 3.

  • in_place (bool, optional) – Smooth in place or return new object. Defaults to False.

Returns:

Smoothed index or new smoothed index object.

Return type:

Self | pd.Series

smooth_series(order=3)

Apply smoothing to all indices.

Parameters:

order (int) – Defaults to 3.

Returns:

Index object.

Return type:

Self

data: TransactionData
model: BaseHousePriceModel
name: pd.Series
periods: pd.Series
value: pd.Series
index: Any
imputed: np.ndarray
smooth: Any
accuracy: pd.DataFrame
accuracy_smooth: pd.DataFrame
volatility: pd.DataFrame
volatility_smooth: pd.DataFrame
revision: pd.DataFrame
revision_smooth: pd.DataFrame