<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ricardo Marchao on Medium]]></title>
        <description><![CDATA[Stories by Ricardo Marchao on Medium]]></description>
        <link>https://medium.com/@ricardomarchao?source=rss-aa619ebafb5e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*poQ2wDNZ1vhVK2U7YiwwpQ.jpeg</url>
            <title>Stories by Ricardo Marchao on Medium</title>
            <link>https://medium.com/@ricardomarchao?source=rss-aa619ebafb5e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 16:55:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ricardomarchao/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Evaluating where to live in Malmö using Foursquare API data]]></title>
            <link>https://medium.com/@ricardomarchao/evaluating-where-to-live-in-malm%C3%B6-using-foursquare-api-data-875c546f453?source=rss-aa619ebafb5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/875c546f453</guid>
            <category><![CDATA[malmö]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[foursquare]]></category>
            <dc:creator><![CDATA[Ricardo Marchao]]></dc:creator>
            <pubDate>Thu, 10 Oct 2019 12:20:23 GMT</pubDate>
            <atom:updated>2019-10-10T12:22:54.993Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TU8M81lVvuPWNt-Iz8n0TA.png" /></figure><h3>1. Introduction</h3><p>As part of coursera “Applied data science capstone” we need to create a project and publish it on a blogpost.</p><p>My project is a descriptive study of the Malmö boroughs: which venues can you find in each borough and relatively to the price per square meter, which ones offer value for the money.</p><p>While doing this project I got to practice some of the things we have been learning in the course, to highlight a few : scraping data from websites, making API requests, using machine learning models to make inferences and understand relationships in the data</p><p>The code is also available on github, in the blogpost I will present the results, but if you are interested in the how to, please check the link below:</p><p><a href="https://github.com/ricmarchao/Coursera_Capstone/blob/master/notebook_week_5_capstone-malmo.ipynb">https://github.com/ricmarchao/Coursera_Capstone/blob/master/notebook_week_5_capstone-malmo.ipynb</a></p><h3>1.1 Background:</h3><p>I have been living in Malmö, Sweden for the last 15 years. I am not a Swede myself. I came here as an expat due to work reasons. My company offered me a choice of staying in an apartment, and I could choose from several apartments that were available within budget.</p><p>I remember my first choice: it was the one that had the nicest furniture. Only later when I started to get to know the neighborhood did I realize that there weren’t any great restaurants around or bars, so for me it was not ideal, I was single and did not do any cooking at home. So after 6 months I moved to another apartment that was closer to the office and luckily, with plenty of restaurants and bars around, so I regret a bit the hasty choice I did at first.</p><p>I realize that the problem that I faced then is still a valid one today, for people that came today to Malmö</p><p>According to Wikipedia: ”In 2011, people from 174 countries were represented in Malmö, speaking 150 languages” <a href="https://en.wikipedia.org/wiki/Malm%C3%B6#Demographics">https://en.wikipedia.org/wiki/Malm%C3%B6#Demographics</a></p><h3>1.2 Business problem:</h3><p>For a person that comes to Sweden being single or having a family the problem we are trying to solve is which borough should they move to, given their preferences on certain categories like restaurants vs proximity to playgrounds or shops.</p><p>This study will also aim to help choosing the borough given the relative price of the square meter of an apartment versus the percentage of venues of a given category in Malmö. This is a way to help establish the “value for money” of a given borough on a given category. An area may have a high percentage of shops for example but if the price of the square meter is very high, maybe worth instead to go to a borough with lesser shops but a more affordable price per square meter</p><h3>1.3 Stakeholders interested:</h3><p>A single person maybe interested in living close to restaurants and bars to socialize, where as a a person with a family may prefer proximity to grocery shops, playgrounds.</p><p>This study well help both types of stakeholders finding a borough that best suits their preferences</p><h3>2. Data</h3><h3>2.1 Data Sources</h3><p>Following data sources were used:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*sdTNDjbTFjKRiuW5f-mfVw.png" /></figure><p>2.2 Data acquisition</p><p>Below is a summary of the data acquisition method by data source:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*0vCFmMsz56OPdDuDV-Zy7A.png" /></figure><p>2.3 Data cleaning &amp; preparation</p><p>Below is a summary of the data cleaning activities by data source:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*hNyD__H1MsSV7bWcb2n0jw.png" /></figure><p>In terms of data preparation, it is also worth mentioning the creation of auxiliary dataframes via the method “create_df_per_categ_pop”. This method creates for a given category (like shops) a relation between the percentage of the total number of venues and any given borough versus the percentage of the total population of the borough. The dataframes this method produces are later on used in the analysis section</p><p>2.4 Data Engineering</p><p>Apart from using features directly available from scraped tables, following features have been created:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*FtW5k39G4kUVZt6pGvyS8w.png" /></figure><p>Apart from features directly related to one dataframe there are also features combining two dataframes, for example combining “categ_1” with population, for example the table below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*ouPNVd6FsWA84rsKTYhKAg.png" /></figure><p>Here we are using percentages of the total venues and for each borough and looking at the percentage of the population that lives in the borough</p><h3>3. Methodology</h3><p>The previous steps allow us to gather the needed data and prepare it, so with this in place we can start analyzing the data.</p><p>In the analysis section we will we be exploring the data and the relationships:</p><p>We will start by getting an understanding of what are the possible values of the venue categories : “categ_1” and “categ_2”</p><p>We will see which are the most frequent values and we will see how they distributed between the different boroughs</p><p>We will also display on the map a heat-map that shows which boroughs have a higher concentration of venues of a particular category</p><p>A second section of the analysis is to look at relationships, namely the relationship between the percentage of venues within a category, how it is distributed by the boroughs versus the average apartment price in that same borough. The idea is to find “value for money”. If a borough contains a moderate percentage of venues of a given category, for example “shops” , but the price per square meter of an apartment is high, it may not be worth moving into that borough on the basis of this category alone.</p><p>To help this analysis we will make use of a linear regression model, the linear regression line represents fair value, values below could be considered cheap boroughs for that category and above expensive ones.</p><p>A third and last section in this analysis will be the clustering of neighborhoods by similarity of venues. The model used here is the k-means , which is an unsupervised machine learning model, meaning we don’t need to provide any labels. The way clusters are form will enable us to check if the city planning is unbalanced or not. For example if a cluster that is predominantly related to food venues contains only 1 or 2 boroughs then it means these venues are not evenly spread out and vice versa if we see clusters that contain all types of venues in multiple boroughs means that in different places of the city you can experience a multitude of venues, so the city is well planned</p><h3>3.1 Exploratory Data Analysis</h3><p>The exploratory data analysis contains pictures and charts coming from the notebook on github (link was provided in the introduction section)</p><h3>3.1.1 Getting familiar with the data</h3><h4>3.1.1.1 Boroughs</h4><p>Let’s start by identifying the boroughs in Malmö, we have a total of 10, in table “boroughs_df”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*pGT4c9LZkQ0bRamiJ_zbgQ.png" /></figure><p>The table above shows the boroughs sorted by population as of 1st Jan 2013. Largest one was the “Centrum”</p><h4>3.1.1.2 Neighborhoods</h4><p>Within these boroughs we have a total of 136 neighborhoods, stored in the table “neigh_df”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*xkB6UFhA9e8QLh231XtW8w.png" /></figure><h4>3.1.1.3 Venues</h4><p><strong>Please note: I got a different number of venues from the Foursquare API, just by running the notebook on different days. Could be due that venues are being added and removed constantly, could be some restriction on the API. So the numbers may not be the same if you re-run the notebook</strong></p><p>We have a 1425 of venues in the “details_venues_nodup” dataframe:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*d6o8UyrE2E8wp7qFkAa89g.png" /></figure><p>The top boroughs in terms of number of venues are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*-57QrjnUndXLqdYcsS0MxQ.png" /></figure><p>The top 10 neighborhoods in terms of total number of venues are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/189/1*EIevotmbHgzUiHdxnq5mFQ.png" /></figure><h4>3.1.1.3.1 Understanding the venues categories</h4><p>The “details_venues_nodup” has three category columns, we will be using mostly “categ_1” and “categ_2”</p><p>“categ_1” and “categ_2” have been retrieved from foursquare from the venue link</p><p>“categ_2” is a sub category of “categ_1”</p><p>The possible values for “categ_1” and their count are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*0O7CWCsxjr3qqkpfV7OkoA.png" /></figure><p>So most of the venues in Foursquare API are related to food and shops</p><p>Most common values in “categ_2” are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*dtoArrTuPXHfG1bWFP8kxg.png" /></figure><p>We can see that even though bus station is a top value the data is incomplete as there are more than 49 bus stations in Malmö</p><p>We can see that are the most popular food related venues:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*jRXEK8wCVnkwMlg_6W4Y1A.png" /></figure><p>and use Seaborn to display it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*6jYMQMzwXQpm2Sjlmrn85g.png" /></figure><p>Interesting to see falafel coming in the top list. Confirming the saying that “Malmö is the Swedish capital of falafel”</p><p>We can also check the total number of food related venues per borough:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*Fsr2l_WhdMnlzBJe3KME1w.png" /></figure><p>Centrum has the highest number of venues</p><p>We can also display the map of Malmö with a heat-map using Folium, with regards to food venue count:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*LZe7L9Z10jkAr2xNmpoLzw.png" /></figure><p>If we look that the shops related venues:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/1*C811JQ7fzKG1xWH4oQQt9g.png" /></figure><p>and plotting it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*b1dqq2jebhF-_SRs-fbK0Q.png" /></figure><p>“foodgrocery” are supermarkets and “default” seems to be like a “others” category that doesn’t fit into the existing ones.</p><p>Looking at the boroughs with the highest number of shop venues:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*U13fT1_tDD1ycS6nn9Od_Q.png" /></figure><p>The Centrum and Hyllie are the leaders, we can also display this on a heat-map:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*ifTVRFEy_IWwo6tCpph4iw.png" /></figure><p>Families and Singles would then likely appreciate moving to the Centrum as it offers convenient shopping</p><p>Looking the “parks_outdoors” category, we can see the most popular venues:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*G4uzbXNatpeSJaSXixTknA.png" /></figure><p>The top value is “playground” this could be interesting for families with small children,</p><p>We can also visualize it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*1H4mroL05jV4ksLjAQoKKA.png" /></figure><p>We can also check which boroughs have the highest number of venues</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*Q1r2Cu-nTJ-pK3mlMclQYw.png" /></figure><p>Quite interesting to see that Centrum has more playgrounds than any other area, specially since the Centrum of the city is usually an area crowded with business activities, restaurants. The fact that it has more playgrounds than others could be due to Foursquare missing data on other playgrounds or a deliberate effort by the city planners to make it attractive to families to move to the center and create a balanced city center.</p><p>Looking at the travel category, the top venues are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*SalJyYqq9gs5mgCqSHiCAw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*_u9yr7xdhG2arVc6g4-4_w.png" /></figure><p>so in travel the most popular item is “bus station”, and it has low count I suspect many bus stations have not been added to the venue list. There are several ways to deal with this:</p><p>- remove the “busstation” value from the df since it is incomplete</p><p>- make no inference based on the “travel” category as it is incomplete and therefore unreliable</p><p>I will go for the 2nd option</p><p>Looking at the arts&amp; entertainment category, the top venues are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*QtiOHvyzPmbRDYrJ5tRbmA.png" /></figure><p>Mostly stadiums and music venues, maybe this area could be more interesting to single persons than families, under the assumption that singles have more free time, and can go watch soccer games or music concerts</p><p>In terms of boroughs with the highest count:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*QCoR9WVPdQQBTNHWzv_hFg.png" /></figure><p>Centrum comes on top again. This could be due to people tagging mostly centrum related venues in the Fourquare API and thus we are missing data. Could also be due Malmö being a relatively small city.</p><p>If the data is accurate then a single person would probably want to move to Centrum</p><p>Looking at the category “buildings”, the top values are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*bkTj_JWDDr7Ko99OlpYoZw.png" /></figure><p>We can see that only one church has been tagged, this is also a clear sign that the foursquare data is not complete, as there are more churches in Malmö.</p><p>Last category we look at is “nightlife”, the top values are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*j3MlzjGYUBcbOHkbV0qRNA.png" /></figure><p>This category is mostly pubs and bars, only one nightclub tagged, again seems foursquare list of venues is not complete</p><h4>3.1.1.4 Apartment prices</h4><p>the “apartment_prices” dataframe has for each borough the avg price for the last 12 month in SEK (Swedish kronor).</p><p>We will be using the log of the prices per square meter:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*L4Q1n8HWXwJ9lP9CzXdklw.png" /></figure><h3>3.1.2 Looking at relationships</h3><p>Lets look at the relationship between the percentage of venues of a given category that belong to a given borough versus the log price of the square meter in that same borough</p><p>We are using here a linear regression where the independent value is the percentage of a count of a given category and the dependent variable is the log price of the square meter</p><p>The idea is to find “value for money” , the regression line should give us what is a fair value, point above are over priced and points below under priced</p><p>So lets start by looking at the category “food”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*mzXXCU9Yxwh7MP6OmZTXqQ.png" /></figure><p>from the figure above if can be seen that 9 “Västra innestraden” is above the regression line, meaning that given the percentage of food places, in relation to the total for Malmö, the price for square meter is above the average and therefore expensive.</p><p>The “Centrum” with label 0 for example even though if has a high percentage of food places with regards to the total food places in Malmö, the price per square meter is below the linear regression line, thus making it relatively cheap.</p><p>A single person that likes to go out to eat would find the “Centrum” good value for money</p><p>Regarding the category “shops”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*qORVBOEi4iiBt-xzWb49rg.png" /></figure><p>the picture above shows that “Hyllie” with label 3 has a relatively cheap square meter price versus the number of shops available in the borough. So for families it could be a good area to live as it will be convenient to go around shopping</p><p>Looking at the category parks &amp; outdoors:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*Ev8r2uSQ_WEpufTSyUFSzQ.png" /></figure><p>The picture above shows for example that “Centrum” with label 0, a high number of parks and playgrounds for children and the price for square meter is relatively cheap as it is below the linear regression line, So for families with small children this area could be a good choice according to this criteria</p><h3>3.1.3 Clustering the neighborhoods</h3><p>In a similar fashion to what was shown in the course in week 3, we will group neighborhoods by venues to find to ones that are most similar by venues.</p><p>We will be using a machine learning model called K-means, clusters together datasets based on their similarity. In this case the similarity of venues categories.</p><p>K-means is an unsupervised learning algorithm , meaning we don’t need to provide the target labels only the feature values.</p><p>We will use one hot encoding to convert the categories into binary values and calculate the average per category for each neighborhood.</p><p>We will be asking the algorithm to group the data in 5 clusters.</p><p>With these clusters we can look at their components in terms of neighborhoods and boroughs and see how broad and narrow these clusters are, this will gives an indication of how well distributed and broad are the neighborhoods and boroughs</p><p>Lets check how the boroughs are distrusted by the k-means cluster, last column (“num_borough”) has the sum of unique boroughs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*V20KLVJ09aTb88gysxNnYw.png" /></figure><p>We can display these clusters on the map:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*Nq3gnEd0bb_XLJvdhIN99Q.png" /></figure><p>Let’s look at the content of cluster 0:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*ow5st8MqjIvCoHYK62jCRg.png" /></figure><p>as per above cluster 0 seems to be broad by venue types</p><p>Cluster 1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*04Rpnf7_ll4BosU7zQPnnw.png" /></figure><p>cluster 1 seems to offer playgrounds so could be good boroughs for families with small children</p><p>Cluster 2:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*Rr_VW6vjTEAgcGsBpHKXNw.png" /></figure><p>Cluster 2, seems to be focused on transportation and it covers the peripheral areas of Malmö</p><p>Cluster 3:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*uTnbuD7ylRVGmopl763sYA.png" /></figure><p>Cluster 3 seems to be focused on food venues, maybe interesting for single people who like to eat out</p><p>Cluster 4:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*aE64_pL2qtDrr4cWsjpFEA.png" /></figure><p>cluster 4 seems to be focused on peripheral areas and food related venues</p><h3>4. Results</h3><p>After doing our data exploration we can now advise single persons and families with children to which boroughs of Malmö offer which type of venues and do so at a reasonable price:</p><p>Centrum borough seems to be good value in terms of restaurants and also playgrounds, for finding supermarkets nearby value for money can be found in Hyllie as well.</p><p>The Centrum borough seems to offer a broad variety of venues having plenty of playgrounds which is unusual for a city centrum</p><h3>5.Discussion</h3><p>The main concern with this study is its reliance on the foursquare data, which as we discussed before seems to missing data points for example bus stations, churches, discos.</p><p>Foursquare number of venues also changes on a daily basis so reproducibility of this study is an issue.</p><p>Most of the foursquare data is focused on restaurants and places to go out in the city centrum, probably tourists to Malmö make many of the updates on the site, so it is more centered on touristic relevant info.</p><p>For a more unbiases and accurate study more data sources with be needed with regards to venue details</p><h3>6.Conclusion</h3><p>So we scrapped the neighborhoods and boroughs for Malmö from Wikipedia, we got the apartment sales prices and we got the venue details from foursquare API.</p><p>While doing data cleansing and preparation and analysis it become clear that foursquare doesn’t hold a complete set of data for all categories. For a more serious analysis of the venues in Malmö a much larger effort in data cleansing and data source quality would be required.</p><p>We then did some data exploration to see what are the most common values in each category and displayed these as bar charts and heatmaps</p><p>We also did an analysis between the percentage of venues in a given category versus the average square meter price, this analysis could help determine if a neighborhood offers value per money for a potential buyer. For this we used linear regression as a tool</p><p>We looked at the perspective of value for different stakeholders: children with small families, looking for playground availability and relatively cheap price of square meters, could try the “Centrum” A single person looking to go out for food instead of cooking, could also look at “Centrum” as an area of value for money People that are interested in the convenience of having shops nearby, and have a relatively cheap price per square meter could instead look at “Hyllie”</p><p>Finally we looked at clustering neighborhoods by the similarity of venues, using k-means. We found the two largest clusters are well diversified in terms of venues, which is good it shows that the planning of the city is working so that is offers a balanced and varied set of venues</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=875c546f453" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>