<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/dalex-stories-warsaw-apartments/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://smarterpoland.pl/index.php/2018/04/dalex-stories-warsaw-apartments/"> English – SmarterPoland.pl</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><img align="right" src="https://i0.wp.com/smarterpoland.pl/wp-content/uploads/2018/04/Screen-Shot-2018-04-12-at-2.55.18-PM.png?w=350" data-recalc-dims="1">This Monday we had a machine learning oriented meeting of Warsaw R Users. Prof <a rel="nofollow" href="https://github.com/berndbischl" target="_blank">Bernd Bischl</a> from LMU gave an excellent overview of <a>mlr</a> package (machine learning in R), then I introduced <a rel="nofollow" href="http://smarterpoland.pl/index.php/2018/04/dalex-stories-warsaw-apartments/cran.r-project.org/package=DALEX" target="_blank">DALEX</a> (Descriptive mAchine Learning EXplanations) and Mateusz Staniak introduced <a rel="nofollow" href="https://github.com/MI2DataLab/live" target="_blank">live</a> and <a rel="nofollow" href="https://github.com/pbiecek/breakDown" target="_blank">breakDown</a> packages.</p>
<p>The meeting pushed me to write down a gentle introduction to the DALEX package. You may find it here <a rel="nofollow" href="https://pbiecek.github.io/DALEX_docs/" target="_blank">https://pbiecek.github.io/DALEX_docs/</a>.<br>
The introduction is written around a story based on <a rel="nofollow" href="https://pbiecek.github.io/DALEX/reference/apartments.html" target="_blank">Warsaw apartments</a> data. </p>
<p>The story goes like that:<br>
We have two models fitted to apartments data: a linear model and a randomForest model. It happens that both models have exactly identical root mean square for errors calculated on a validation dataset.<br>
So an interesting question arise: <i>which model we should choose?</i></p>
<p><img src="https://i2.wp.com/smarterpoland.pl/wp-content/uploads/2018/04/global_explain_boxplot-1.png?w=456" data-recalc-dims="1"></p>
<p>The analysis of variable importance for both models reveals that variable <i>construction.year</i> is important for randomForest but is completely neglected by linear model.<br>
New observation: <i>something is going on with construction.year</i>.</p>
<p><img src="https://i2.wp.com/smarterpoland.pl/wp-content/uploads/2018/04/modelImportanceRaw-1.png?w=456" data-recalc-dims="1"></p>
<p>The analysis of model responses reveals that the relation between <i>construction.year</i> and price of square meter is nonlinear.<br>
At this point it looks like the random forest model is the better one, since it captures relation, which the linear model do not see.</p>
<p><img src="https://i1.wp.com/smarterpoland.pl/wp-content/uploads/2018/04/pdpRandomForestLM-1.png?w=456" data-recalc-dims="1"></p>
<p>But (there is always but) when you audit residuals from the random forest model it turns out that it heavily under predicts prices of expensive apartments.<br>
This is a very bad property for a pricing model. This may result in missed opportunities for larger profits.<br>
New observation: <i>do not use this rf model for predictions</i>.</p>
<p><img src="https://i2.wp.com/smarterpoland.pl/wp-content/uploads/2018/04/outliersML-1.png?w=456" data-recalc-dims="1"></p>
<p>So, what to do?<br>
DALEX shows that despite equal root mean squares of both models they are very different and capture different parts of the signal.<br>
As we increase our understanding of the signal we are able to design a better model. And here we go.<br>
This new liner model has much lower root mean square of residuals, as it is build on strengthens of both initial models. </p>
<p><img src="https://i0.wp.com/smarterpoland.pl/wp-content/uploads/2018/04/dal3.png?w=456" data-recalc-dims="1"></p>
<p>All plots were created with DALEX explainers. Find R code and more details <a rel="nofollow" href="https://pbiecek.github.io/DALEX_docs/" target="_blank">here</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://smarterpoland.pl/index.php/2018/04/dalex-stories-warsaw-apartments/"> English – SmarterPoland.pl</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/1_W7JPMncw8" height="1"></a></div>