Pricing Airbnb Listings Optimally | by Tony Ng | Jan, 2021


This segment is the crux of all of the challenge.

I shall skip discussing Neural Network because it used to be completed in Colab as a unfavorable instance for this challenge. The key level can be that Neural Network is incessantly known as a ‘black-box’ which it isn’t fully imaginable to provide an explanation for its prediction end result. For instance, we will be able to inform an individual who has implemented for a mortgage that he’s arbitrarily rejected by our Neural Network style, however we can not give an explanation for and inform him/her what had resulted within the total ultimate determination. In this example, this system would no longer be related to our challenge as we would wish our ultimate end result to be extremely explainable and interpretable by Airbnb hosts so they may be able to be told of their ultimate pricing determination as neatly. However, the code for the ANN continues to be made to be had within the pocket book.

It could also be price discussing the train-test break up (TTS) technique as this challenge is moderately distinctive with appreciate to different system finding out tasks. Most steadily, one would carry out TTS at the dataset randomly (except time-series). However, you will need to verify that the objective variable worth is originally optimal sooner than the respective style is skilled with that example in our challenge. The implication thus of appearing a ‘blind TTS’ will be the derivation of a “garbage-in garbage-out” ultimate style. Hence, we require some type of scrutinization and filtering to our train-set the place the style derives the underlying laws of optimal pricing methods.

From the above clarification, the unfiltered dataset must have a mixture of each optimal and less-optimum costs. The obstacle of figuring out one from every other can be not to have any goal indicator to decide so in our dataset. The handiest borderline believable variable will be the selection of opinions for list. The reasoning can be that supposedly the unfastened marketplace used to be environment friendly, upper patron staying counts would suggest a better total call for or engagement and therefore upper plausibility of optimal pricing, regardless of no longer realizing concerning the nature or sentiment of the underlying overview as events have been prepared to have interaction in voluntary industry at first. As the prerequisite of a reviewer can be being an present patron, the selection of opinions is an oblique indicator of the favourability of a list to be engaged and thus optimal costs. Hence, we must practice our fashions with the highest 80% dataset of overview counts.

Machine finding out is if truth be told no longer as tricky as different non-practitioners may imagine. At a sensible stage, you wish to have no longer perceive each intricate computational element in the back of a given style and code it out for utilization. Furthermore, it could no longer a excellent coding apply to “reinvent the wheel” when others have already made this to be had. For example, I will be able to verify out nine other untuned fashions from scikit-learn (and XGBoost) with just a few traces of code:


nameList = []
cvMeanChecklist = []
cvStdList = []
for Model in [LinearRegression, Ridge, Lasso,
DecisionTreeRegressor, RandomForestRegressor, ExtraTreesRegressor,
AdaBoostRegressor, GradientBoostingRegressor, XGBRegressor]:
if Model == XGBRegressor: cv_res = rmse_cv(XGBRegressor(goal='reg:squarederror', eval_metric = 'mae'))
else: cv_res = rmse_cv(Model())
print('{}: {:.5f} +/- {:5f}'.structure(Model.__name__, -cv_res.imply(), cv_res.std()))


LinearRegression: 79.72456 +/- 10.095378
Ridge: 79.75446 +/- 10.114177
Lasso: 81.44520 +/- 8.418724
DecisionTreeRegressor: 103.70623 +/- 13.965223
RandomForestRegressor: 77.86522 +/- 13.281151
ExtraTreesRegressor: 78.39075 +/- 14.291264
AdaBoostRegressor: 120.35514 +/- 23.933491
GradientBoostingRegressor: 76.78751 +/- 11.726186
XGBRegressor: 76.69236 +/- 11.640701
CPU instances: consumer 1min 38s, sys: 614 ms, general: 1min 38s
Wall time: 1min 38s

Next to each and every style, the 1st quantity represents the 10-fold pass validation error’s imply (squared error), and the second one represents the pass validation error’s usual deviation (squared error).

  • We can see that fashions corresponding to each DecisionTreeRegressor and AdaBoostRegressor weren’t in a position to outperform the simplistic baseline style of LinearRegression.
  • However, each GradientBoostingRegressor and XGBRegressor had a decrease CV error worth relative to the record of fashions. We can try to additional track each fashions in our answer

Gradient boosting (GB) regressor can be utilized when the objective variable is constant, and GB classifier can be utilized when the objective variable is specific. AdaBoost, GB, and XGBoost all use a identical manner of boosting which will increase the efficiency of the style. A brief paraphrase from Analytics Vidhya, a unsolicited mail detection style that handiest identifies both the presence of hyperlinks or e mail from an unknown supply are each vulnerable fashions one after the other. However, by combining each laws from coaching, the style is maximum tough and would thus have higher total generalisation capacity. Hence, GB is an ensemble of a couple of determination tree fashions that has a good prediction end result.

However, tuning a style is just about trial and mistake. For example, I will be able to try to in finding the minimal imply absolute error (MAE) via checking out a couple of issues throughout a supposedly massive parameter area for the selection of estimators (n_estimators). The following plot used to be completed via checking out 7 issues:

n_estimators = [5, 25, 50, 100, 250, 500, 1000]

The native minimal must be approximating 220 n_estimators.

Unlike Neural Network, each GB and XGBoost will also be extremely explainable. For example, we will be able to inform which variables have been essential in explaining prediction effects for worth. In basic, there are 2 alternative ways to inform significance in options the usage of tree-based fashions:

  1. Feature Importance from Mean Decrease in Impurity (MDI)
  • Impurity is quantified by the splitting criterion of the verdict bushes (Gini, Entropy or Mean Squared Error).
  • However, this system can provide top significance to options that might not be predictive on unseen knowledge when the style is overfitting.

2. Permutation Importance

  • Permutation-based function significance, however, avoids this factor, since it may be computed on unseen knowledge.

From this, we will be able to see that each room_type_Private room and calculated_host_listings_counts are constantly ranked on the best as maximum essential in explaining variable worth.

6.three eXtreme Gradient Boosting

Extreme Gradient Boosting (XGBoost) is a moderately fresh system finding out manner (making an allowance for Neural Networks used to be conceptualized within the 1940s and SVM used to be presented by Vapnik and Chervonenkis within the 1960s) that isn’t handiest each speedy and environment friendly however could also be among the most efficient appearing fashions lately.

xgboost is an to be had package deal for import in Colab. Furthermore, the XGB style can utilise Colab’s unfastened GPU to be extra successfully tuned as neatly.

The similar parameter on the lookout for Learning Rate used to be implemented to the XGB style just like the n_estimators in GB prior to now.

Although on the lookout for 1 parameter will also be simply carried out with a easy for-loop, a extra complete seek can be to specify a suite of parameter grid and both use GridSearchCV or RandomSearchCV.

  • GridSearchCV iterates throughout the made of all imaginable mixtures (Pros: very thorough parameter seek, Cons: doubtlessly very lengthy operating time e.g. Five hyperparameters for five parameters = 5*5*5*5*5=5⁵=3125 fashions.
  • RandomSearchCV run time is decided by n_iter which will also be specified conversely.

In this example, RandomSearchCV of n_iter=50 used to be specified for the next parameter grid:

param_grid = {
"learning_rate": [0.032, 0.033, 0.034],
"colsample_bytree": [0.6, 0.8, 1.0],
"subsample": [0.6, 0.8, 1.0],
"max_depth": [2, 3, 4],
"n_estimators": [100, 500, 1000, 2000],
"reg_lambda": [1, 1.5, 2],
"gamma": [0, 0.1, 0.3],

From the former point out of TTS, the test-set end result must no longer be our center of attention as it’s most probably that we’re coaching on rows with optimal costs and therefore we must no longer be expecting it to generalise neatly to check set with cases of much less optimal costs. However, the extra essential purpose of the challenge is to provide an explanation for the numerical worth in the back of each and every prediction end result.

We can visualize predictions with element the usage of SHapley Additive exPlanations (SHAP) library for each GB and XGBoost fashions. In this example, I will be able to speak about handiest the XGBoost because of redundancy. Variables ‘pushing’ prediction upper and decrease are proven in crimson and blue respectively.

For example, the first-row prediction worth is defined the usage of SHAP. Firstly, the bottom worth 135.Five is the imply of all worth values which might the similar for all cases. However, variables in crimson larger the prediction worth whilst the only real variable room_type_Private room lowered which decided the general prediction worth to be 146.52. From this chart, we will be able to almost definitely interpret {that a} shared as in comparison to a non-public room can not justify a better room worth than the latter.

Additionally, if we have been to rotate the determine above anti-clockwise by 90 levels the place the 1st row can be at first of the X-axis, we will be able to stack the rest predictions side-by-side to the precise and acquire the determine under. We can see that almost all prediction values hover round 135 from roughly index zero to 1600 the place each upward and downward push are calmly matched. Thereafter, there have been a couple of variables that switched facets to push the prediction decrease from index 1600 to 2800. The ultimate slices have been met by little resistance by blue variables to pressure the prediction values downwards.

For SHAP variable significance, it’ll no longer be decided by impurity values as mentioned in GB however merely how a lot a variable has total defined (or driven) in all predictions. We can see that room_type_Private room has been constantly maximum essential in predicting worth values (similar with GB MDI and Permutation Importance), the place both zero or 1 pushes a prediction downwards and upwards respectively.

The above plot isn’t that helpful in case you’re bored stiff within the route driven by each and every variable however about total variable significance, plotting absolutely the SHAP worth can be extra useful.

We can simply create a internet utility (app) with streamlit and deploy this the usage of a PaaS supplier Heroku to percentage our SHAP effects. We can create the app the usage of Heroku-CLI the usage of:

heroku login
git init
heroku create airbnb-sg
git far off upload heroku
heroku git:far off -a airbnb-sg
git upload .
git devote -m "Add adjustments to each Heroku and Github"
git push heroku HEAD:grasp

Link to:

Note that the app makes use of cache predictions as Heroku dynos for free-tier is terribly restricted.


Please enter your comment!
Please enter your name here