<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/a-data-scientists-guide-to-predicting-housing-prices-in-russia/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.nycdatascience.com/student-works/data-scientists-guide-predicting-housing-prices-russia/"> R – NYC Data Science Academy Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><span><b>Sberbank Russian Housing Market</b></span></p>
<p><span><em><span>A Kaggle Competition on Predicting Realty Price in Russia</span></em></span></p>
<p><i><span><span>Written by</span> </span></i><a rel="nofollow" href="https://www.linkedin.com/in/mohammad-haseeb-durrani-7756a83a/" target="_blank"><i><span>Haseeb Durrani</span></i></a><i><span>, </span></i><a rel="nofollow" href="https://www.linkedin.com/in/chen-trilnik-171a02110/" target="_blank"><i><span>Chen Trilnik</span></i></a><i><span>, <span>and </span></span></i><a rel="nofollow" href="https://www.linkedin.com/in/jackyip/" target="_blank"><i><span>Jack Yip</span></i></a></p>
<p> </p>
<p><span><b>Introduction</b></span></p>
<p><span><span>In May 2017, Sberbank, Russia’s oldest and largest bank, challenged data scientists on </span><a rel="nofollow" href="https://www.kaggle.com/c/sberbank-russian-housing-market" target="_blank"><span>Kaggle</span></a><span> to come up with the best machine learning models to estimate housing prices for its customers, which includes consumers and developers looking to buy, invest in, or rent properties. This blog post outlines the end-to-end process of how we went about tackling this challenge.</span></span></p>
<p> </p>
<p><span><b>About the Data</b></span></p>
<p><span>The </span><a rel="nofollow" href="https://www.kaggle.com/c/sberbank-russian-housing-market/data" target="_blank"><span>datasets</span></a><span> provided consist of a training set, a test set, and a file containing historical macroeconomic metrics. </span></p>
<ul>
<li><span>The training set contains ~21K realty transactions spanning from August 2011 to June 2015 along with information specific to the property. This set also includes the price at which the property was sold for.</span></li>
<li><span>The test set contains ~7K realty transactions spanning from July 2015 to May 2016 along with information specific to the property. This set does not include the price at which the property was transacted.</span></li>
<li><span>The macroeconomic data spans from January 2010 to October 2016.</span></li>
<li><span>There are a combined total of ~400 features or predictors.</span></li>
</ul>
<p><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle1.png?ssl=1" target="_blank"><img sizes="(max-width: 582px) 100vw, 582px" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle1.png?w=450&ssl=1" alt="" class="wp-image-22237" data-recalc-dims="1"></a></p>
<p><i><span>The train and test datasets spans from 2011 to 2016.</span></i></p>
<p> </p>
<p><span><b>Project Workflow</b></span></p>
<p><span>As with any team-based project, defining the project workflow was vital to our delivering on time as we were given only a two-week timeframe to complete the project. Painting the bigger picture allowed us to have a shared understanding of the moving parts and helped us to budget time appropriately.</span></p>
<p><span>Our project workflow can be broken down into three main parts: 1) Data Assessment, 2) Model Preparation, and 3) Model Fitting. This blog post will follow the general flow depicted in the illustration below.</span></p>
<p><span><a rel="nofollow" href="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggl2.png?ssl=1" target="_blank"><img sizes="(max-width: 976px) 100vw, 976px" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggl2.png?w=450&ssl=1" alt="" class="wp-image-22236" data-recalc-dims="1"></a></span></p>
<p><span><i><span>The project workflow was vital to keeping us on track under a two-week constraint.</span></i></span></p>
<p> </p>
<p><span><b>Approach to the Problem</b></span></p>
<p><span>Given a tight deadline, we had to limit the project scope to what we can realistically complete. We agreed that our primary objectives are to learn as much as we can and to apply what we have learned in class. To do so, we decided to do the following:</span></p>
<ul>
<li><span><span>Focus on applying the </span><b>Multiple Linear Regression</b><span> and </span><b>Gradient Boosting </b><span>model, but to also spend some time with </span><b>XGBoost</b></span><span><span> for learning purposes</span> (</span><a rel="nofollow" href="https://github.com/dmlc/xgboost" target="_blank"><span>XGBoost</span></a><span> is a relatively new machine learning method, and it is oftentimes the model of choice to win Kaggle competitions).</span></li>
<li><span>Spend more time working and learning together as a team instead of working in silos. This meant that each of us has an opportunity to work in each of the domains in the project pipeline. While this is not reflective of the fast-paced environment of the real world, we believe that it can help us better learn the data science process.</span></li>
</ul>
<p> </p>
<p><span><b>Understanding the Russian Economy (2011 to 2016)</b></span></p>
<p><span>In order to better predict Russian housing prices, we first need to understand how the economic forces impact the Russian economy, as it directly affects the supply and demand in the housing market. </span></p>
<p><span>To understand how we can best apply macroeconomic features into our models, we researched for Russia’s biggest economic drivers and also any events that may have impacted Russia’s economy during the time period of the dataset (i.e. 2011 to 2016). Our findings show that:</span></p>
<ul>
<li><span>The oil industry is Russia’s largest industry. In 2012, oil, gas, and petroleum contributed to over </span><a rel="nofollow" href="http://www.connaissancedesenergies.org/sites/default/files/pdf-pt-vue/analysis_report_on_russia.pdf" target="_blank"><span>70% of the country’s total export</span></a><span>.<span> Russia’s economy was hurt badly when oil</span>  </span><a rel="nofollow" href="https://en.wikipedia.org/wiki/Russian_financial_crisis_(2014%E2%80%932017)" target="_blank"><span>dropped by over 50% in a span of six months in 2014</span></a><span>.</span></li>
<li><span>There were international </span><a rel="nofollow" href="http://europe.newsweek.com/russian-sanctions-could-cost-europe-100-billion-328999?rx=us" target="_blank"><span>trade sanctions</span></a><span> in response to Russia’s military interference with Ukraine’s politics. This had a negative effect on Russia’s economy as there is a rise of instability.</span></li>
</ul>
<p><span>These two factors initiated a “snowball.” negatively impacting the following base economic indicators:  </span></p>
<ul>
<li><span>The Russian ruble</span></li>
<li><span>The Russian Trading System Index (RTS Index)</span></li>
<li><span>The Russian trade balance</span></li>
</ul>
<p><span><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle3.png?ssl=1" target="_blank"><img sizes="(max-width: 976px) 100vw, 976px" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle3.png?w=450&ssl=1" alt="" class="wp-image-22235" data-recalc-dims="1"></a></span></p>
<p><span><i><span>Labels for the chart: Blue – RTS Index, Green – Global Oil Price, Purple – USD/Ruble Exchange Rate,  </span></i><i><span>Red – Russia’s Trade Balance</span></i></span></p>
<p> </p>
<p><span>The poorly performing Russian economy manifested a series of changes in Russia’s macroeconomic indicators, including but not limited to:</span></p>
<ul>
<li><span>Significant increase in Russia’s Consumer Price Index (CPI)</span></li>
<li><span>Worsened salary growth and unemployment rate</span></li>
<li><span>Decline in Gross Domestic Product (GDP)</span></li>
</ul>
<p><span>The change in these indicators, led us to the understanding that Russia is facing a financial crisis.</span></p>
<p><span><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle4.png?ssl=1" target="_blank"><img sizes="(max-width: 976px) 100vw, 976px" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle4.png?w=450&ssl=1" alt="" class="wp-image-22234" data-recalc-dims="1"></a></span></p>
<p><span><i><span>The first chart measures CPI, the second chart measures GDP growth, and the third chart measures unemployment rate (blue) and salary growth (red)</span></i></span></p>
<p> </p>
<p><span>As we continued to explore the macroeconomic dataset, we were able to further confirm Russia’s financial crisis. We observed that the Russian Central Bank had increased the banking deposit rate by over 100% in 2014 in an attempt to bring stability to the Russian economy and the Russian ruble.</span></p>
<p><span><a rel="nofollow" href="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle5.png?ssl=1" target="_blank"><img sizes="(max-width: 976px) 100vw, 976px" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle5.png?w=450&ssl=1" alt="" class="wp-image-22233" data-recalc-dims="1"></a></span></p>
<p><span><i><span>In the chart above, the red data points represent banking deposit rates, and the blue data points represent mortgage rates.</span></i></span></p>
<p> </p>
<p><span>Next, we looked for the effect of the Russian Central Bank’s move on the Russian housing market. When raising banking deposit rates, the Russian Central Bank encouraged consumers to keep their savings in the banks and minimize the public’s’ exposure to financial risk. That was seen clearly in the Russian housing market following the raise in deposit rates. We noticed that rent prices increased, and the growth of commercial investment in real estate dropped in the beginning of 2015. </span></p>
<p><span><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle6.png?ssl=1" target="_blank"><img sizes="(max-width: 976px) 100vw, 976px" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle6.png?w=450&ssl=1" alt="" class="wp-image-22232" data-recalc-dims="1"></a></span></p>
<p><span><i><span>The first chart above represents the index of rent prices, and the second chart shows the level of investment in fixed assets.</span></i></span></p>
<p> </p>
<p><span>This analysis led us to the understanding that the Russian economy was facing a major financial crisis, which significantly impacted the demand in the Russian housing market. This highlights the importance of the usage of the macroeconomic features in our machine learning model to predict the Russian housing market.</span></p>
<p><span><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle7.png?ssl=1" target="_blank"><img sizes="(max-width: 976px) 100vw, 976px" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle7.png?w=450&ssl=1" alt="" class="wp-image-22231" data-recalc-dims="1"></a></span></p>
<p><span><i><span>The illustration on the left shows the count of transactions by product type. The illustration on the right provides a more detailed view of the same information.</span></i></span></p>
<p> </p>
<p><span><b>Exploratory Data Analysis</b></span></p>
<p><span>The first step to any data science project is simple exploration and visualization of the data. Since the ultimate purpose of this competition is price prediction, it’s a good idea to visualize price trends over the time span of the training data set. The visualization below shows monthly average realty prices over time. We can see that average prices have seen fluctuations between 2011 and 2015 with an overall increase over time. There is, however, a noticeable drop from June to December of 2012.  </span></p>
<p><span><a rel="nofollow" href="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle8.png?ssl=1" target="_blank"><img sizes="(max-width: 599px) 100vw, 599px" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle8.png?w=450&ssl=1" alt="" class="wp-image-22230" data-recalc-dims="1"></a></span></p>
<p><span>It is important to keep in mind that these averaged prices include apartments of different sizes; therefore, a more “standardized” measure of price would be the price per square meter over the same time span. Below we see that the average price per square meter shows fluctuations as well, though the overall trend is quite different from the previous visualization.</span></p>
<p><span><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle9.png?ssl=1" target="_blank"><img sizes="(max-width: 618px) 100vw, 618px" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle9.png?w=450&ssl=1" alt="" class="wp-image-22229" data-recalc-dims="1"></a></span></p>
<p><span>The data set starts off with a decline in average price per square meter, which sees somewhat of an improvement from late 2011 to mid 2012. Again we see a price drop from June to December of 2012.</span></p>
<p><span>Some other attributes to take into consideration when evaluating the price of an apartment are the size of the apartment and the size of the building.  </span></p>
<p><span>Our intuition tells us that price should be directly related to the size of an apartment, and the the boxplot below shows that the median price does go up relative to apartment size, with the exception of “Large” apartments having a median price slightly lower than apartments of “Medium” size. Factors such as neighborhood might help in explaining this anomaly.</span></p>
<p><span><a rel="nofollow" href="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle10.png?ssl=1" target="_blank"><img sizes="(max-width: 653px) 100vw, 653px" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle10.png?w=450&ssl=1" alt="" class="wp-image-22228" data-recalc-dims="1"></a></span></p>
<p><span>Apartment price as a function of building size shows similar median prices for low-rise, medium, and high-rise buildings. Larger buildings labelled “Sky” with 40 floors or more show a slightly higher median apartment price.</span></p>
<p><span><a rel="nofollow" href="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle11.png?ssl=1" target="_blank"><img sizes="(max-width: 582px) 100vw, 582px" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle11.png?w=450&ssl=1" alt="" class="wp-image-22227" data-recalc-dims="1"></a></span></p>
<p><span>Another interesting variable worth taking a look at is the type of transaction or “product type” mentioned in the data set. This feature of the data categorizes each transaction as being either an Investment or an Owner Occupied purchase. The barplot below gives a breakdown of the transactions for the top sub-areas (by frequency) based on the product type. </span></p>
<p><span><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle12.png?ssl=1" target="_blank"><img sizes="(max-width: 770px) 100vw, 770px" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle12.png?w=450&ssl=1" alt="" class="wp-image-22226" data-recalc-dims="1"></a></span></p>
<p><span>This visualization clearly shows that certain areas are heavily owner occupied while other areas are very attractive to investors. If investment leads to increasing prices, this trend will be important for making future predictions. </span></p>
<p><span>If we shift our focus to transactions related to the building’s build year based on product type, we see that older buildings generally are involved in investment transactions, possibly due to better deals, while newer constructions are predominantly owner occupied. </span></p>
<p><span><a rel="nofollow" href="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle13.png?ssl=1" target="_blank"><img sizes="(max-width: 787px) 100vw, 787px" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle13.png?w=450&ssl=1" alt="" class="wp-image-22225" data-recalc-dims="1"></a></span></p>
<p><span>Simple exploration and visualization of the data outlines important considerations while training our machine learning model. Our model must consider the factors behind the price dips in 2012 and learn to anticipate similar drops in future predictions. The model must also understand that low prices attract investors, as can be seen with older buildings. However, if investment leads to an increase in price for a particular building, the model must be able to adjust future predictions for that building accordingly. Similarly. the model must be able to predict future prices for a given sub-area that has seen an increase in average price over time as a result of investment.</span></p>
<p> </p>
<p><span><b>Feature Selection</b></span></p>
<p><span>To simplify the feature selection process, we fitted an XGBoost model containing all of the housing features (~290 features) and called its feature importance function to determine the most important predictors of realty price. XGBoost was very efficient in doing this; it took less than 10 minutes to fit the model.</span></p>
<p><span>In the illustration below, XGBoost sorts each of the housing features by its Fscore, which is a measure of variable importance in its predictive power of the transaction price. Among the top 20 features identified with XGBoost, a Random Forest was used to further rank their importance. The %IncMSE metric was preferred over IncNodePurity as our objective was to identify features that can minimize the mean squared errors of our model (i.e. better predictability).</span></p>
<p><span><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle14.png?ssl=1" target="_blank"><img sizes="(max-width: 976px) 100vw, 976px" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle14.png?w=450&ssl=1" alt="" class="wp-image-22224" data-recalc-dims="1"></a></span></p>
<p><span>In order to determine which macroeconomic features were important, we joined the transaction prices in the training set with the macroeconomics by the timestamp and then repeated the process above. The top 45 ranking features are outlined below. In this project, we have used experimented with different subsets of these features to fit our models.</span></p>
<p><span><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle15.png?ssl=1" target="_blank"><img sizes="(max-width: 976px) 100vw, 976px" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle15.png?w=450&ssl=1" alt="" class="wp-image-22223" data-recalc-dims="1"></a></span></p>
<p> </p>
<p><span><b>Feature Engineering</b></span></p>
<p><span>Often times it is crucial to generate new variables from existing ones to improve prediction accuracy. Feature engineering can serve the purpose of extrapolating information by splitting variables for model flexibility or dimension reduction by combining variables for model simplicity. </span></p>
<p><span>The graphic below shows that by averaging our chosen distance-related features into an average-distance feature, we yield a similar price trend as the original individual features. </span></p>
<p><span><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle16.png?ssl=1" target="_blank"><img sizes="(max-width: 976px) 100vw, 976px" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle16.png?w=450&ssl=1" alt="" class="wp-image-22222" data-recalc-dims="1"></a></span></p>
<p> </p>
<p><span>For simpler models sub areas were limited to the top 50 most frequent with the rest classified as “other.” The timestamp variable was used to extract date and seasonal information into new variables, such as day, month, year, and season. The apartment size feature mentioned earlier during our exploratory data analysis was actually an engineered featured using the living square meter area of the apartment to determine apartment size. This feature served very valuable during the imputation of missing values for number of rooms in an apartment. Similarly building size was generated using the maximum number of floors in the given building.</span></p>
<p> </p>
<p><span><b>Data Cleaning</b></span></p>
<p><span>Among 45 features selected, outliers and missing values were corrected as both the multiple linear regression and gradient boosting models do not accept missing values.</span></p>
<p><span>Below is a list of the outlier corrections and missing value imputations.</span></p>
<p><span>Outlier Correction</span></p>
<ul>
<li><span>Sq-related features: Imputed by mean within sub area</span></li>
<li><span>Distance-related features: Imputed by mean within sub area</span></li>
</ul>
<p><span>Missing Value Imputation</span></p>
<ul>
<li><span>Build Year: Imputed by most common build year in sub area</span></li>
<li><span>Num Room: Imputed by average number of rooms in similarly sized apartments within the sub area</span></li>
<li><span>State: Imputed using the build year and sub area  </span></li>
</ul>
<p> </p>
<p><span><b>Model Selection</b></span></p>
<p><span>Prior to fitting models, it is imperative to understand their strengths and weaknesses.</span></p>
<p><span>Outlined below are some of the pros and cons we have identified, as well as the associated libraries used to implement them.</span></p>
<p><span>Multiple Linear Regression (R: lm, Python: statsmodel)</span></p>
<ul>
<li><span>Pros: High Interpretability, simple to implement</span></li>
<li><span>Cons: Does not handle multicollinearity well (especially if we would like to include a high number of features from this dataset)</span></li>
</ul>
<p><span>Gradient Boosting Tree (R: gbm &amp; caret) </span></p>
<ul>
<li><span>Pros: High predictive accuracy</span></li>
<li><span>Cons: Slow to train, high number of parameters</span></li>
</ul>
<p><span>XGBoost (Python: xgboost)</span></p>
<ul>
<li><span>Pros: Even higher predictive accuracy, accepts missing values</span></li>
<li><span>Cons: Relatively fast to train compared to GBM, but higher number of hyperparameters</span></li>
</ul>
<p> </p>
<p><span><b>Multiple Linear Regression</b></span></p>
<p><span>Despite knowing that a multiple linear regression model will not work well given the dataset’s complexity and the presence of multicollinearity, we were interested to see its predictive strength.</span></p>
<p><span>We began by validating the presence of multicollinearity. In the illustration below, green and red boxes indicate positive and negative correlations between two features. One of the assumptions of a multiple linear regression model is that its features should not be correlated.</span></p>
<p><span><b>Violation of Multicollinearity</b></span></p>
<p><span><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle17.png?ssl=1" target="_blank"><img sizes="(max-width: 976px) 100vw, 976px" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle17.png?w=450&ssl=1" alt="" class="wp-image-22221" data-recalc-dims="1"></a></span></p>
<p><span>We continue to examine other underlying assumptions of a multiple linear regression model. When examining scatterplots among predictors and the target value (i.e. price), it is apparent that many predictors do not share a linear relationship with the response variable. The following plots are one of many sets of plots examined during the process.</span></p>
<p> </p>
<p><span><span><b>Violation of Linearity</b></span></span></p>
<p> <a rel="nofollow" href="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle18-e1497273160597.png?ssl=1" target="_blank"><img alt="" src="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle18-e1497273160597.png?w=450&ssl=1" class="wp-image-22240" data-recalc-dims="1"></a></p>
<p><span>The Residuals vs Fitted plot does not align with the assumption that error terms have the same variance no matter where they appear along the regression line (i.e. red line shows an increasing trend).</span></p>
<p><span><span><b>Violation of Constant Variance</b></span></span></p>
<p><a rel="nofollow" href="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle19-1-e1497273191189.png?ssl=1" target="_blank"><img alt="" src="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle19-1-e1497273191189.png?w=450&ssl=1" class="wp-image-22239" data-recalc-dims="1"></a></p>
<p> </p>
<p><span>The Normal Q-Q plot shows severe violation of normality (i.e. standardized residuals are highly deviant from the normal line).</span></p>
<p> </p>
<p><span><span><b>Violation of Normality</b></span></span></p>
<p><span><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle20.png?ssl=1" target="_blank"><img alt="" src="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle20-e1497273204800.png?w=450&ssl=1" class="wp-image-22218" data-recalc-dims="1"></a></span></p>
<p><span>The Scale-Location plot shows a violation of independent errors as it is observed that the standardized residuals are increasing along with increases in input variables</span></p>
<p><span><b>Violation of Independent Errors</b></span></p>
<p><span><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle21.png?ssl=1" target="_blank"><img alt="" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle21-e1497273217448.png?w=450&ssl=1" class="wp-image-22217" data-recalc-dims="1"></a></span></p>
<p><span>Despite observing violations of the underlying assumptions of multiple linear regression models, we proceeded with submitting our predictions to see how well we can score.</span></p>
<p><span><span>Our first model A1 was trained using the top 12 property-specific features identified in the feature selection process. Submitting predictions using this model gave us a Kaggle score of 0.39544 on the public leaderboard (this score is calculated based on the</span> </span><a rel="nofollow" href="https://www.kaggle.com/wiki/RootMeanSquaredLogarithmicError" target="_blank"><span>Root Mean Squared Logarithmic Error</span></a><span>). <span>Essentially, the lower the score, the more accurate the model’s predictions are. Nevertheless, it is possible to</span> “</span><a rel="nofollow" href="http://blog.kaggle.com/2012/07/06/the-dangers-of-overfitting-psychopathy-post-mortem/" target="_blank"><span>overfit the public leaderboard</span></a><span>”, as the score on the public leaderboard is only representative of the predictions of approximately 35% of the test set.</span></p>
<p><span>Models A2 and A3 were fitted by removing features from model A1 that showed VIFs (Variance Inflation Factors) greater than 5. Generally, features with VIFs greater than 5 indicate that there is multicollinearity present among the features used in the model. Removing these did not help to improve our Kaggle scores, as it is likely that we have removed features that are also important to the prediction of price.</span></p>
<p><span>Models B1, B2, and B3 were trained with the features in A1 with the addition of identified important macro features. These models did not improve our Kaggle scores, likely for reasons mentioned previously.</span></p>
<p><span><a rel="nofollow" href="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle22.png?ssl=1" target="_blank"><img alt="" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle22.png?w=450&ssl=1" class="wp-image-22216" data-recalc-dims="1"></a></span></p>
<p> </p>
<p><span><b>Gradient Boosting Model</b></span></p>
<p><span>The second machine learning method we used was the Gradient Boosting Model (GBM), which is a tree-based machine learning method that is robust in handling multicollinearity. This is important as we believe that many features provided in the dataset are significant predictors of price.</span></p>
<p><span>GBMs are trained using the bootstrapping method; each tree is generated using information from previous trees. To avoid overfitting the model to the training dataset, we used cross-validation with Caret package in R. Knowing that this model can handle complexity and multicollinearity well, we added more features for the first model we fitted.</span></p>
<p><span>In Model A1, we chose 47 features from the original training dataset, which gave us a Kaggle score of 0.38056. Next, we wanted to check if reducing the complexity of the model gives better results. We decided to run another model (A2) with only 20 features. This model performed better than Model A1.</span></p>
<p><span>In Model A3, we added to the previous model, 5 macro features that were chosen using XGBoost feature importance. As expected, the macro features improved our results. The model gave us the best Kaggle score of all the gradient boosting models we trained.</span></p>
<p><span><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle23.png?ssl=1" target="_blank"><img alt="" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle23.png?resize=414%2C563&ssl=1" class="wp-image-22215" data-recalc-dims="1"></a></span></p>
<p><span>For each of the GBM models, we used cross-validation to tune the parameters (with R’s Caret package). GBM models on average provided us better prediction results compared with those using the multiple linear regression models.</span></p>
<p><span><a rel="nofollow" href="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle24.png?ssl=1" target="_blank"><img alt="" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle24-e1497273239127.png?w=450&ssl=1" class="wp-image-22214" data-recalc-dims="1"></a></span></p>
<p> </p>
<p><span><b>XGBoost</b></span></p>
<p><span>An extreme form of gradient boosting, XGBoost, is the preferred tool for Kaggle competitions due to it’s accuracy of predictions and speed. The quick speed in training a model is a result of allowing residuals to “roll-over” into the next tree. Careful selection of hyperparameters such as learning rate and max-depth, gave us our best Kaggle prediction score. Fine tuning of the hyperparameters can be achieved through extensive cross-validation; however, caution is recommended when fitting too many parameters as it can be computationally expensive and time consuming. Below is an example of a simple grid search cross validation.</span><a rel="nofollow" href="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle25-1.png?ssl=1" target="_blank"><img sizes="(max-width: 976px) 100vw, 976px" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle25-1.png?w=450&ssl=1" alt="" class="wp-image-22242" data-recalc-dims="1"></a></p>
<p> </p>
<p><span><b>Prediction Scores</b></span></p>
<p><span>The table below outlines the best public scores we have received using each of the different models, along with the features used.</span></p>
<p><a rel="nofollow" href="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle26.png?ssl=1" target="_blank"><img sizes="(max-width: 976px) 100vw, 976px" src="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/06/kaggle26.png?w=450&ssl=1" alt="" class="wp-image-22241" data-recalc-dims="1"></a></p>
<p> </p>
<p><span><b>Future Directions</b></span></p>
<p><span>This two-week exercise provided us the opportunity to experience first-hand what it is like to be working in a team of data scientists. If given the luxury of additional time, we would dedicate more to engineering new features to improve our model predictions. This would require us to develop deeper industry knowledge of Russia’s housing economy.</span></p>
<p> </p>
<p><span><b>Acknowledgement</b></span></p>
<p><span>We thank the entire team of instructors at NYCDSA for their guidance during this two-week project and also our fellow Kagglers who published kernels with their useful insights.</span></p>
<p>The post <a rel="nofollow" href="http://blog.nycdatascience.com/student-works/data-scientists-guide-predicting-housing-prices-russia/" target="_blank">A Data Scientist’s Guide to Predicting Housing Prices in Russia</a> appeared first on <a rel="nofollow" href="http://blog.nycdatascience.com/" target="_blank">NYC Data Science Academy Blog</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://blog.nycdatascience.com/student-works/data-scientists-guide-predicting-housing-prices-russia/"> R – NYC Data Science Academy Blog</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/-aswUirGmqQ" height="1"></a></div>