<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/renthop-predicting-interest-level-for-rental-listings/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://blog.nycdatascience.com/student-works/machine-learning/renthop-predicting-interest-level/"> 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>Renthop is a New York based apartment listing website. It uses an innovative algorithm to sort and present the listings to the visitors. As part of our third project at NYCDSA, we participated in the <a target="_blank" rel="nofollow" href="https://www.kaggle.com/c/two-sigma-connect-rental-listing-inquiries">Kaggle’s Two Sigma Connect: Rental Listing Inquiries</a> machine learning competition. Our challenge was to predict the interest level in an apartment rental listing. We had 49,000 labeled entries and made predictions on 74,000. Target labels were <em>high</em>, <em>medium</em> and <em>low</em>.</p>
<p>The scope of this problem represents a typical machine learning challenge faced by many organizations. Data consisted of numerical, continuous, ordinal, and categorical variables. It had pictures, descriptions of the units and geospatial information. Distribution of the classes was also imbalanced. Considering all the above, it’s safe to conclude this problem is a much better proxy to real world situations in which Data Science can and must be employed, a somewhat uncommon characterization for Kaggle competitions, that tend to supply cleaner data and focus mainly on predictive models.</p>
<h2>Feature Engineering</h2>
<p>Our initial approach to this problem was to slice and dice the given variables in a variety of ways so that we could capture information contained within them. The almost readily available ones, that didn’t require much treatment, are the following:</p>
<ul>
<li>Price (continuous): Log transformation</li>
<li>Bedrooms (integer): Unchanged</li>
<li>Bathrooms (integer): Unchanged</li>
<li>Price/Bedrooms and Price/Bathrooms: Used by adding 1 to the denominator and taking the logarithm</li>
<li>Latitude and Longitude (continuous): After an initial analysis, it was determined that, despite not having all coordinates pointing to the New York City area, that the ones that didn’t were usually incorrect and referred to listings from NYC. Thus, we forced all coordinates into a rectangular area around the city.</li>
<li>Photos (list of urls): As a first approach, used simply the number of photos for each listing.</li>
<li>Description and Features (text, list): As a first approach, extracted simple metrics such as the length and number of words.</li>
<li>Listing creation date/time: Extracted features such as the hour of the day, day of the week and of the month.</li>
</ul>
<p>These initial features were already very informative in that it was possible to obtain cross-entropy losses below 0.6 (top score is still above 0.500 as we write this article) with certain models. From these features, the most significant one was found to be the price.</p>
<div class="wp-caption"><img sizes="(max-width: 600px) 100vw, 600px" alt="Density plot of prices for different interest levels" class="wp-image-20692" src="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/04/price-1024x768.png?w=450&ssl=1" data-recalc-dims="1">
<p class="wp-caption-text">Density plot of prices for different interest levels. Price is on a logarithmic scale.</p>
</div>
<p>The listing creation hour can also tell us something about the interest level.</p>
<div class="wp-caption"><img sizes="(max-width: 700px) 100vw, 700px" alt="Interest Levels by listing creation hour" class="wp-image-20695" src="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/04/hour.png?w=450&ssl=1" data-recalc-dims="1">
<p class="wp-caption-text">Interest levels by listing creation hour</p>
</div>
<h3>Other Categorical Variables</h3>
<p>An approach sometimes employed on categorical variables consists on encoding them (transforming to integer values) and transforming them into <a target="_blank" rel="nofollow" href="https://en.wikipedia.org/wiki/Dummy_variable_(statistics)">dummy variables</a>. The predictors in question are Manager ID, Building ID, Street Address and Display Address.</p>
<h3>Listing Features</h3>
<p>When it comes to using apartment features as a predictor, we had to start by taking a good look at the data. On our raw data, the listing features were either presented in a very structured way, such as in <code>[Elevator, Laundry in Building, Hardwood Floors]</code>, or in a very unclean way, such as in <code>[** LIFE OF LUXURY FOR NO FEE! * SPRAWLING 2BR/2BA MANSION * WALLS OF WINDOWS *<br>
ROOMY CLOSETS * FREE GYM &amp; POOL * SCENIC ROOF DECK * DOORMAN/ELEV BLDG *<br>
STEPS TO THE PARK!! **]</code>.</p>
<p>Having this, we determined the best approach to be capturing features by using regular expressions, while being careful to check that all matches were relevant to the intended feature. We extracted 56 different listing features in total. The code that achieves this can be found <a target="_blank" rel="nofollow" href="https://github.com/domingos86/renthop-kaggle/blob/master/renthop/preprocessing/features.py">here</a>.</p>
<p>Out of the features extracted, the ones that seem to have the greatest impact in terms of the interest levels, taking into consideration the amount of listings they affect, are <em>Hardwood Floors</em> and <em>No Fee</em>.</p>
<div class="wp-caption"><img sizes="(max-width: 700px) 100vw, 700px" alt="Distribution of interest levels with respect to hardwood floors" class="wp-image-20697" src="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/04/feature_hardwood_floors.png?w=450&ssl=1" data-recalc-dims="1">
<p class="wp-caption-text">Distribution of interest levels with respect to hardwood floors listings</p>
</div>
<div class="wp-caption"><img sizes="(max-width: 700px) 100vw, 700px" alt="Distribution of interest levels with respect to no fee listings" class="wp-image-20698" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/04/feature_no_fee.png?w=450&ssl=1" data-recalc-dims="1">
<p class="wp-caption-text">Distribution of interest levels with respect to no fee listings</p>
</div>
<h3>Photos</h3>
<p>After obtaining all the photos, taking in total over 80GB of storage space, we decided to extract a few useful values from them.</p>
<p>First, we looked at their dimensions and included them as predictors in our models (namely, average dimensions per listing, as well as the dimensions of the first photo).</p>
<p>We also extracted the sharpness of each image, having from them a somewhat surprising conclusion: contrary to our initial assumptions, high interest listings have slightly less sharp photos as compared to low interest listings.</p>
<div class="wp-caption"><img sizes="(max-width: 725px) 100vw, 725px" alt="Average photo sharpness for each interest level" class="wp-image-20696" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/04/avg_sharpness.png?w=450&ssl=1" data-recalc-dims="1">
<p class="wp-caption-text">Average photo sharpness per listing for each interest level</p>
</div>
<p>We also used <a target="_blank" rel="nofollow" href="https://www.clarifai.com/">Clarifai API</a> to extract top 15 labels from each image. There, convolutional neural networks are used to learn features present in the image and a probability estimate is given for each label extracted. Though under gradient boosting relative influence, image features showed some positive significance, during training and testing they showed very low signs of improving the model.</p>
<p>Finally, in order to actually make use of the photo contents, we resized all photos to 100×100 squares, to be fed into a convolutional neural network model (more details on that below).</p>
<h3>Sentiment Analysis from Description (NLP – Natural Language Processing)</h3>
<h4>An R package for the extraction of sentiment and sentiment-based plot arcs from text</h4>
<p>The name “Syuzhet” comes from the Russian Formalists Victor Shklovsky and Vladimir Propp who divided narrative into two components, the “fabula” and the “syuzhet.” Syuzhet refers to the “device” or technique of a narrative whereas fabula is the chronological order of events. Syuzhet, therefore, is concerned with the manner in which the elements of the story (fabula) are organized (syuzhet).</p>
<p>The Syuzhet package attempts to reveal the latent structure of narrative by means of sentiment analysis. Instead of detecting shifts in the topic or subject matter of the narrative (<a target="_blank" rel="nofollow" href="http://sappingattention.blogspot.com/2014/12/fundamental-plot-arcs-seen-through.html">as Ben Schmidt has done</a>), the Syuzhet package reveals the emotional shifts that serve as proxies for the narrative movement between conflict and conflict resolution.</p>
<ul>
<li>Afinn – developed by Finn Arup Nielsen as the AFINN WORD DATABASE</li>
<li>Bing – developed by Minqing Hu and Bing Liu as the OPINION LEXICON</li>
<li>NRC – developed by Mohammad, Saif M. and Turney, Peter D. as the NRC EMOTION LEXICON</li>
</ul>
<h4>Structure the Unstructured</h4>
<p><i>Syuzhet</i> is concerned with the linear progression of narrative from beginning (first page) to the end (last page), whereas <i>fabula</i> is concerned with the specific events of a story, events which may or may not be related in chronological order … When we study the <i>syuzhet</i>, we are not so much concerned with the order of the fictional events but specifically interested in the manner in which the author presents those events to readers.</p>
<h4>What is Sentiment Analysis?</h4>
<p>Opinion mining or sentiment analysis  Computational study of opinions, sentiments, subjectivity, evaluations, attitudes, appraisal, affects, views, emotions, etc., expressed in text.  Reviews, blogs, discussions, news, comments, feedback, or any other documents “Opinions” are key influencers of our behaviors.  Our beliefs and perceptions of reality are conditioned on how others see the world.  Often when we need to make a decision, we often seek out the opinions of others. In the past,  Individuals: seek opinions from friends and family  Organizations: use surveys, focus groups, opinion polls, consultants.</p>
<h4>Using NLP for Feature Extraction</h4>
<p>We used the syuzhet package to take the descriptions from the Kaggle dataset and produce a scoring mechanism that valued each description on a range of emotions:</p>
<p>Anger * Anticipation * Disgust * Fear * Joy * Sadness * Surprise * Trust</p>
<p>In addition we composed additional features for these datasets based on valence as being either:</p>
<p>Negative vs. Positive</p>
<h2>Models Implemented</h2>
<p>Several machine learning models were implemented, including XGBoost and other decision trees based models, as well as neural networks.</p>
<h3>Neural Networks</h3>
<p>Based on the fact that more than 99% of the data, in terms of size, made available to us was in the form of photos, we had to make use of it on our predictions. The challenge here is to extract from them more features than the readily available ones: number of photos per listing and their dimensions.</p>
<p>We identified four possible approaches (not mutually exclusive):</p>
<ul>
<li>Feature Engineering: extract some manually chosen <i>statistics</i>, such as brightness, sharpness, contrast, etc.</li>
<li>Train a separate convolutional neural network model that classifies the images based on what they show. Possible categories could include kitchen, bathroom, floor plan, fitness center, street view, etc.</li>
<li>Train a separate model with only the photos, then feed the results to our main model.</li>
<li>Extract <i>anonymous</i> features by training on an unified model.</li>
</ul>
<p>Initially, as a preparation step to implementing the last approach, we trained a simple neural network model with four dense layers, taking as input the basic listing features already provided to us with just a few tweaks, and gradually developed our feature engineering and saw our predictions improve.</p>
<div class="wp-caption"><img sizes="(max-width: 720px) 100vw, 720px" alt="Simple neural network model" class="wp-image-20699" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/04/simple_model.png?w=450&ssl=1" data-recalc-dims="1">
<p class="wp-caption-text">Simple neural network model</p>
</div>
<p>Ultimately, the model yielding the best results, achieving a Kaggle score of 0.58854, used the following feature transformations:</p>
<ul>
<li>Coordinates (longitude/latitude) outside the New York City area snapped to a rectangle around it,</li>
<li>Logarithm of price, price per bedroom and price per bathroom,</li>
<li>Count of words/characters in description, words and quantity of apartment features,</li>
<li>Time of day, day of month, day of week,</li>
<li>Sentiment analysis,</li>
<li>Parsed apartment features as 56 dummy variables,</li>
<li>Dimensions and sharpness (log) of first photo, as well as average dimension and sharpness (log) of all the photos per listing,</li>
<li>Manager id: encoded the top 999 managers in terms of the amount of listings, mapping all the remaining ones to a common category, and then applied an embedding to 10 activations. Similar to generating 1000 dummy variables and then applying a dense layer with 10 activations.</li>
</ul>
<div class="wp-caption"><img sizes="(max-width: 720px) 100vw, 720px" alt="Neural network embedding for Manager ID" class="wp-image-20700" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/04/managers.png?w=450&ssl=1" data-recalc-dims="1">
<p class="wp-caption-text">Neural network embedding for Manager ID</p>
</div>
<p>When it came to use the actual photos, we were faced with a few obstacles. First, the fact that they had many different sizes and aspect ratios. Second, that each listing had a different number of photos. And finally, storage restrictions on the GPU servers we used. By resizing all of them to 100×100 square thumbnails, we were able to squeeze them into about 2.3GB of storage. To deal with the fact that different listings had different amounts of photos, and also given the memory space inflated photos take as inputs to a convolutional network (100x100x3x4 ~ 120KB), we decided to only take the first photo as a first approach, and also by taking only 20 thousand training samples.</p>
<div class="wp-caption"><img sizes="(max-width: 889px) 100vw, 889px" alt="Convolutional neural network" class="wp-image-20701" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/04/convolutional.png?w=450&ssl=1" data-recalc-dims="1">
<p class="wp-caption-text">Convolutional neural network (<em>layers</em> refers to the commonly used term <em>channels</em> in this con<em>text</em>)</p>
</div>
<p>After training for a few hours, the results from the validation set didn’t seem very promising. Given that, in order to have a good predictor, having good training data is key, we decided to extract the activations from the convolutional part of the network, freezing its (trained) weights and therefore not requiring the photos for training anymore, and expand, up to validation data, to the entire training set. This did give us an improvement but, oddly, not enough to beat our previous Kaggle score that didn’t use the photos as input. This seems to go against the simple intuitive idea that, given a model more data and freedom (weights), it should be able to make better predictions if properly trained. Truth be told, almost no tuning went into perfecting our model, especially when it comes to its architecture, so there’s certainly a lot of room for improvements. We did use validation loss to drive the learning rate decay, as well as early stopping and the choice of weights to be used for the final prediction.</p>
<p>Looking forward, potential improvements can be obtained by training with photos on all listings by loading them as the training occurs (already implemented), by considering all the photos from each listing, possibly having a model training exclusively on the photos (with its activations used as an input on another model). Also, extracting more information from the descriptions and applying some transformations to the coordinates, as well as having shifted versions for time-based features (as they are all periodic), could all lead to an improvement in our predictions.</p>
<h4>Implementation</h4>
<p>These neural networks were implemented using the Keras framework over the Theano backend. All the code can be found on our <a target="_blank" rel="nofollow" href="https://github.com/domingos86/renthop-kaggle">project’s github</a>.</p>
<p>In order to have a highly automated and controlled environment for our features, where we ensure that training and test data go through the same transformations from raw data to becoming inputs for our neural networks, we developed a preprocessing framework, with many possible transformations, that delivers on that promise. After setting up the preprocessor, with all the different pipelines for the different types of data processed, getting the data is as simple as calling <code>load_and_transform(test)</code>, with <code>test</code> being <code>False</code> for train and <code>True</code> for test data.</p>
<p>With the generator module, this framework extended to data loading/generation run in parallel as the network is being trained. This is a critical functionality when all the photo data, once loaded, would exceed the memory capacity of our system.</p>
<p>The post <a target="_blank" rel="nofollow" href="https://blog.nycdatascience.com/student-works/machine-learning/renthop-predicting-interest-level/">Renthop: predicting interest level for rental listings</a> appeared first on <a target="_blank" rel="nofollow" href="https://blog.nycdatascience.com/">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="https://blog.nycdatascience.com/student-works/machine-learning/renthop-predicting-interest-level/"> 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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/-ShRjzf0qfs"></a></div>