<?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 Thijs Bressers on Medium]]></title>
        <description><![CDATA[Stories by Thijs Bressers on Medium]]></description>
        <link>https://medium.com/@tbressers88?source=rss-48bba4460823------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*U0FDCuHIHhSEyy3pI6jzfg.jpeg</url>
            <title>Stories by Thijs Bressers on Medium</title>
            <link>https://medium.com/@tbressers88?source=rss-48bba4460823------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 22:21:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tbressers88/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[Road Trip Fever]]></title>
            <link>https://medium.com/data-science/road-trip-fever-460a2627f0c4?source=rss-48bba4460823------2</link>
            <guid isPermaLink="false">https://medium.com/p/460a2627f0c4</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[travel]]></category>
            <category><![CDATA[clustering]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[tsp]]></category>
            <dc:creator><![CDATA[Thijs Bressers]]></dc:creator>
            <pubDate>Sun, 14 Apr 2019 18:27:24 GMT</pubDate>
            <atom:updated>2019-04-15T00:23:12.146Z</atom:updated>
            <content:encoded><![CDATA[<h4>Ep. 4 : Solving TSP to derive efficient routes in our destinations</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8AJoZqf7UB8Z6nGrlBTUcg.png" /><figcaption>Our output today; All our efficient road-trip destinations on globe; connected linearly</figcaption></figure><p>Imagine yourself, going up winding roads through the mountains with new idyllic images popping up around each corner. Or feeling the sea breeze flowing through your hair, while steering your cabriolet besides endless summer waves at that scenic ocean drive. Or maybe parking your camper van at a spot that seems like no person ever had witnessed it before. Road trips come in many forms, and often immediately spark the interest in many of us.</p><p>For the larger clusters that we have seen in <a href="https://towardsdatascience.com/clustered-globe-e5c54b42de16">episode 3</a>, road trips are inevitable in order to make the most out of our holiday period. That’s why in today’s post we will try to answer for all of our holiday destinations on how to travel within them: Is a road-trip required? If so, how to most efficiently drive through the cluster?</p><p>For the latter, we will be trying to solve a micro version of the <a href="https://en.wikipedia.org/wiki/Travelling_salesman_problem">TSP</a> for each of our holiday destination that requires a road trip!</p><blockquote>The <strong>travelling salesman problem </strong>(<strong>TSP</strong>) asks the following question: “Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city and returns to the origin city?” <em>— Wikipedia</em></blockquote><h3>Our Approach</h3><ol><li><strong>Establish smaller clusters</strong> within our holiday destinations for staying overnight; These will define the locations for which to solve TSP.</li><li><strong>Separate the destinations</strong> that require TSP analysis from those that consist of one or two sub-clusters only</li><li><strong>Explore </strong>which<strong> TSP solving algorithm</strong> is best for our problem <strong>and apply</strong> on our road-trip holiday destinations</li><li><strong>Visualize</strong> our newly created<strong> road trips on the globe</strong></li></ol><h3>The Data</h3><p>The data we need today is the geodata in terms of the Longitude and Latitude for each activity. As we have already derived these using <a href="https://developers.google.com/maps/documentation/geocoding/intro">Google Maps’ Geocoding API</a> in <a href="https://towardsdatascience.com/planet-beehive-aeca53ba0326">episode 1</a>.</p><p>However in order to calculate the optimized route between our road-trip destinations, we will extract data on driving distances (in time) from:</p><ul><li><a href="http://www.google.com/">Google</a> :<em> To retrieve the distances between overnight locations within our destinations, we will leverage on </em><a href="https://developers.google.com/maps/documentation/distance-matrix/start"><em>Google’s Distance Matrix API</em></a><em>.</em></li></ul><h3>Defining Overnight Locations</h3><p>In chapter three we have clustered our touristic activities together into holiday destinations. But at the same time we also noticed that some of these holiday destinations still have activities included that spread very far apart in distance (i.e. one US cluster included activities all the way from Chicago to New Orleans). That means that we cannot base ourselves at a single location within the cluster and be able to visit all activities with day trips. We will have to create a new hierarchical layer in between our activities and destinations: The overnight locations.</p><p>What we are looking for is a single location from which we can get to as much activities from the cluster as possible within a distance that is reasonable to travel in a day (so distance as a constraint). Sounds familiar? That’s because its a very similar problem as we covered in the <a href="https://towardsdatascience.com/clustered-globe-e5c54b42de16">previous episode</a>! So, let’s not reinvent the wheel and use the same clustering process that we used there (the DBSCAN clustering) to create sub-clusters which will function as our overnight locations.</p><p>As we want to be able to drive to the activity and back to our overnight location, while still being able to enjoy the activity as well, we will go for an <strong>epsilon parameter </strong>based on a linear distance of <strong>200 km</strong> <em>maximum</em>. And as we want to visit all the activities within the cluster, we will select a <strong>minimum population of 1</strong>. Ensuring there will be no outliers (i.e. if there is 1 activity in a sub-cluster, we will visit the activity and stay there 1 night before continuing to the next sub-cluster).</p><p>So after applying this approach, we now have created three touristic hierarchical layers throughout our episodes so far:</p><ul><li>Activities - the places to visit</li><li>Sub-clusters - the locations to sleep</li><li>Clusters -the holiday destinations</li></ul><p>Visually, going back to the US example, these layers look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*-kruTvz2A3TlgIlcvH5XNQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*nzRYDWiDc_T4smBBXvhNVA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*vjXXZoFLqiBAzVuabMmEaQ.png" /><figcaption>Fig. 1, 2, 3: Mapped activities, <strong>sub-clusters</strong> and clusters respectively, grouped by the 7 clusters in the US</figcaption></figure><p>What is instantly clear from this is that not all clusters have multiple sub-clusters. Some of the holiday destinations have a single overnight location from which we can visit all activities. Perfect for travelers that are less keen on a road trip.</p><p>Let us have a look of the distribution of our clusters with the number of overnight locations and as well as to the road trip vs non-road trip clusters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*srVKzA1CmpQKpAWeaAuyRA.png" /><figcaption>Fig. 4 distributions of the holiday destinations (clusters) by the number of overnight locations (sub-clusters)</figcaption></figure><p>Most of the holiday destinations have only a single overnight locations. And we can see that most of the other clusters have between 2 and 10 sub clusters, with the majority in the lower numbers. Then there are three destinations with more than 10 sub clusters, but these seem to be rather exceptions.</p><p>When it comes to the distribution of non-road-trip vs road-trip (&gt;2 overnight locations) destinations, we have quite a number of options for both. Which is good, because we want to have options for when we prefer a road-trip as well as when we prefer a more fixed base from which to explore the destination. With more than 100 destinations for each (104 and 143 respectively), there are plenty to chose from with either preference.</p><h3>Choosing the right TSP solving algorithm</h3><p>For the 143 destinations that have multiple overnight locations, we will need to define what is the most efficient route to drive through them. While starting and ending in the same location.</p><p>For destinations with two and three overnight locations this easy, any route will be the most efficient route. However for all routes with more than 3 overnight locations we will have to derive the most efficient route by solving a micro version of the<strong> travelling salesperson problem</strong>, also known as TSP.</p><p>A big inspiration has been <a href="http://www.randalolson.com/2015/03/08/computing-the-optimal-road-trip-across-the-u-s/">this article</a> from <a href="https://medium.com/u/79a76605c902">Randy Olson</a>. His findings definitely reached a far wider audience than those that ever heard of TSP before. His <a href="https://en.wikipedia.org/wiki/Genetic_algorithm">Genetic Algorithm</a> is especially interesting to us as we don’t need to derive the absolute best route, generating a very efficient route in a proper performance is more important.</p><p>Our goal is to implement the most efficient algorithm to optimize the route within a <em>single cluster. </em>As we observed in fig. 4, the majority of our destinations have only 10 or less locations to stay overnight.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*9-slIYZU9VTUj0mGrd34rg.png" /><figcaption>Fig. 5 Time complexity comparison for a brute force vs genetic algorithm approach</figcaption></figure><p>With those very few locations to consider, we might as well compare the time complexity of the Genetic Algorithm with a <a href="https://guide.freecodecamp.org/algorithms/brute-force-algorithms/">Brute Force</a> TSP algorithm to see whether the latter will already be sufficient to implement within our solution.</p><p>In figure 5 on the left, you see the average time to complete route optimization with a growing number of overnight locations within our clusters. In this way we can quickly test the overall time to complete as well as the impact from a growing number of locations potentially in the future or for longer holidays.</p><p>The brute force approach is clearly growing exponentially with a linearly growing number of overnight locations; while the genetic algorithms’ time complexity is more or less growing linear, an already much more preferred solution for stability in performance.</p><p>For our algorithm, even though we are limited in locations per destination, we want to create a sustainable solution. Therefore the best way forward is to incorporate a version derived from the genetic algorithm into our solution.</p><h3>Creating efficient road-trips</h3><p>Finally! Time for the fun stuff: let’s actually create some road-trips!</p><p>Now that we have finalized our algorithm of choice, we can start looking into our data and looking how our road-trips look like in practice. Being still intrigued by Randall’s initial article, as well as trying to test our TSP solving ability, I am going to create road-trips on two levels: one route through ALL activities within a country, as well as routes separated for each of our destinations within the country (our final goal).</p><p>Important to grasp here is that:</p><ul><li>country-wide routes travel through all cities containing our activities, while cluster routes only travel through our overnight locations.</li><li>Only road-trip destinations are displayed. Locations that are not visited by the road-trip clusters’ route are either single location destinations or outliers.</li></ul><p>Let’s look at the TSP solutions for 4 larger countries on 4 different continents: United States, Brazil, India and Australia:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q3ck1jol59bXMT6u5BdM3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*dnUyVCBgoRN_23VPFqLvcQ.png" /><figcaption>Fig. 6, 7 Efficient road-trips through our relevant locations in the <strong>United States</strong>; country-wide and for all road-trip destinations separated, respectively</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*1paZuNqv0Gk7SOvcg3N5Aw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*Wd-EZMVkRk3t6vqOtZqcpw.png" /><figcaption>Fig. 8, 9 Efficient road-trips through our relevant locations in <strong>Brazil;</strong> country-wide and for all road-trip destinations separated, respectively</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*VPqKiN1XBX3cIYY-Nl1ngw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*LgsM0_8koLR2noWRo_zJKQ.png" /><figcaption>Fig. 10, 11 Efficient road-trips through our relevant locations in <strong>India</strong>; country-wide and for all road-trip destinations separated, respectively</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*DB9w0cLZ9H4bNu1a_5fgvw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*5Tl7DkZO_bOrp38VXYdhKg.png" /><figcaption>Fig. 12, 13 Efficient road-trips through our relevant locations in <strong>Australia</strong>; country-wide and for all road-trip destinations separated, respectively</figcaption></figure><p>Overall these look like quite impressive road-trips to me! They also look pretty efficient from the eye, and while it would most likely be possible to optimize these routes even more, the added efficiency would be limited compared to the additional required complexity to do so. And in our case, it would be absolute overkill to further enhance these routes.</p><p>Looking at the different destinations separately, we see road-trips in all shapes and forms. And guess what, the very large road-trip in north-west India is our outlier destination with 24 overnight locations (see fig. 4).</p><p>Talking about a sabbatical trip!</p><h3>The concluding map</h3><p>So today we managed to sub-cluster our destinations into overnight locations. And we added a TSP solving algorithm to our code that can calculate an efficient route between these overnight location when there are more than 3 in a destination.</p><p>To conclude, the following interactive chart will give show all of the road-trips destinations through our touristic activities, with their efficient route in linear connections (not the actual way to drive). This interactive map is created using <a href="https://plot.ly/">Plotly</a>. Happy browsing your next road-trip!</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fplot.ly%2F%7EThijsB%2F110%2F&amp;src=https%3A%2F%2Fplot.ly%2F%7EThijsB%2F110.embed%3Fautosize%3Dtrue&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=plot" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e1051c3cd51e8ff583a62cbce8679ec/href">https://medium.com/media/1e1051c3cd51e8ff583a62cbce8679ec/href</a></iframe><blockquote>Reading this and happen to be an expert in Django/Web Development? Send me a DM if you’re interested in giving my code a bit more shape.. literally.</blockquote><p><em>For more information about myself feel free to checkout my </em><a href="https://www.linkedin.com/in/thijs-bressers-a793bb19"><em>LinkedIn</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=460a2627f0c4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/road-trip-fever-460a2627f0c4">Road Trip Fever</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clustered Globe]]></title>
            <link>https://medium.com/data-science/clustered-globe-e5c54b42de16?source=rss-48bba4460823------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5c54b42de16</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[travel]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Thijs Bressers]]></dc:creator>
            <pubDate>Thu, 07 Feb 2019 21:19:34 GMT</pubDate>
            <atom:updated>2019-02-07T22:22:25.918Z</atom:updated>
            <content:encoded><![CDATA[<h4>Ep. 3 : Clustering our activities into holiday destinations</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3oOE7tqZ10OoyrH6yCfzMw.png" /><figcaption>Our output today; clustered holiday destinations all over the globe; Read below for the clustering details</figcaption></figure><p>Previously we have <a href="https://towardsdatascience.com/planet-beehive-aeca53ba0326">measured</a> and <a href="https://towardsdatascience.com/playground-earth-238f8253b030">categorized</a> our activities and now we have a rough idea of what would be the best activity to visit from our personal interests. But is a single activity worth for our scarce holiday time to be dependent on it? What should we tell our family members to do on the other days of our two week holiday? Indeed, a single activity might not just be enough yet to decide our next holiday destination. In order to really establish destinations, <strong>we will have to establish groups of activities that are within reasonable travelling time from each other</strong>. In other words: time for a Cluster Analysis on our geodata!</p><blockquote><strong>Cluster analysis</strong> or <strong>clustering</strong> is the task of grouping a set of objects in such a way that objects in the same group (called a <strong>cluster</strong>) are more similar (in some sense) to each other than to those in other groups (clusters) <em>— Wikipedia</em></blockquote><h3>Our Approach</h3><ol><li><strong>Explore </strong>the different <strong>clustering algorithms</strong> and it’s pros vs cons in relation to our problem</li><li><strong>Set constraints and variables</strong> to be used in the clustering process (i.e. distance, min/max activities, etc.)</li><li><strong>Apply clustering algorithm</strong> to our data, to be stored as a one to one relation between each activity and one cluster</li><li><strong>Visualize our clusters</strong> on the map and<strong> combine with our scored measure </strong>to be able to compare clusters to each other</li></ol><h3><strong>The Data</strong></h3><p>The data we need for clustering today is the geodata in terms of the Longitude and Latitude for each activity. As we have already derived these using <a href="https://developers.google.com/maps/documentation/geocoding/intro">Google Maps’ Geocoding API</a> in <a href="https://towardsdatascience.com/planet-beehive-aeca53ba0326">episode 1</a>, there is no further data to be extracted to complete our task.</p><h3>Clustering Algorithms</h3><p>The biggest pitfall in applying any clustering analysis to your data is choosing the wrong clustering algorithm. There are numerous different algorithms with different properties used in the way to calculate groups of data points that form a cluster. Each problem is different, and each algorithm will yield different results. Therefore whenever starting a clustering analysis its important to start by evaluating the pros and cons of the most common clustering algorithms. <em>Don’t apply the algorithm that you are most familiar with for each problem as it will not necessarily give you the optimized solution.</em></p><p>In this article I will not go in depth on each clustering algorithm, only analyzing which is best for our problem. For a good read on the subject, and the algorithms we will explore today, I recommend <a href="https://towardsdatascience.com/the-5-clustering-algorithms-data-scientists-need-to-know-a36d136ef68">this article</a> by <a href="https://medium.com/u/e2af5c8737ec">George Seif</a>.</p><p>Personally I like schematic comparisons, so as a first step, in Fig. 1, you’ll find a very simplified comparison of the key properties of our problem, for the following algorithms: <a href="https://en.wikipedia.org/wiki/K-means_clustering">K-Means</a>, <a href="https://en.wikipedia.org/wiki/Mean_shift">Mean-Shift</a>, <a href="https://en.wikipedia.org/wiki/DBSCAN">DBSCAN</a>, <a href="https://en.wikipedia.org/wiki/Expectation%E2%80%93maximization_algorithm">Expectation-Maximization</a> and <a href="https://en.wikipedia.org/wiki/Hierarchical_clustering">Agglomerative Hierarchical</a> clustering. please note:</p><ul><li>Only comparing on characteristics that are a direct requirement to solve our problem (not comparing many other cluster algorithm attributes).</li><li>Please do let me know if you think we overlooked an essential clustering algorithm that would be a perfect fit for our problem.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*BgqETFrNQsFfsM0n6s7KiA.png" /><figcaption>Fig. 1 Comparing our requirements against clustering algorithms</figcaption></figure><p>Let’s breakdown and explain our requirements one by one:</p><ul><li><strong>Number of clusters:</strong> Some clustering algorithms require the number of clusters to be known beforehand and will then allocate all data points to the given number of clusters. However, at this point in our analysis, we have no valuable estimate of the number of clusters that could be derived from our activities.<em> </em>Therefore we are looking for an algorithm that will derive the number of clusters from the data. <em>Matching algorithms: Mean-Shift, DBSCAN, Agglomerative Hierarchical</em></li><li><strong>Noise Handling:</strong> Not necessary all data points are to be considered part of a cluster. For some algorithms its better to remove noise from the data-set before applying the clustering, while others have a way of defining noise in the process. In our case, we do not want to delete noise but want it flagged instead. We can have a great stand alone activity in the middle of nowhere that will not be part of any holiday destination, but still want it flagged as an outlier destination. For this we need an algorithm with noise handling. <em>Matching algorithms: Mean-Shift, DBSCAN</em></li><li><a href="https://en.wikipedia.org/wiki/Time_complexity"><strong>Time Complexity</strong></a><strong>: </strong>Of lesser importance at this stage, as we will only execute the clustering in a very low frequency and our data-set is not estimated to grow in a very fast pace. However still we want to prevent having to refactor everything in a later stage if our data-set of activities does grow and an O(n²) algorithm has become unmanageable. In our case we would aim for the best possible time complexity possible. From an O(n²) algorithm (or worse) we deem the clustering unfit for our problem. <em>Matching algorithms: K-Means, Expectation-Maximization, DBSCAN</em></li><li><strong>Thresholds: </strong>The nature of some clustering algorithms provide for parameters with which to steer the clustering process and to set some boundaries for the cluster edges. Very important in our case, as we would like to set some thresholds on how large a cluster can get to be manageable in an holiday period. For example, looking at the scatter plot on coordinates in chapter 1, it is easy to see that most clustering algorithms will cluster the whole of Europe in a single cluster. Quite hard to do in just a single holiday. So we will need to be able to set some guidelines as in what thresholds we consider for a single cluster to be formed. <em>Matching algorithms: Mean-Shift, DBSCAN, Expectation-Maximization</em></li></ul><p>Out of these five options, only the <strong>DBSCAN</strong> clustering algorithm ticks all the boxes for our problem (although still scoring only medium on time complexity) and on top of that, its required parameters are an excellent fit to our desired clustering. Therefore, we are going to continue with DBSCAN and if we cannot get to the desired clustering results, we can always proceed with exploring the runner up algorithm: the Mean-Shift.</p><h3><strong>Setting Constraints &amp; Variables</strong></h3><p>First, we’re gonna set the boundaries of what detail we are going to cluster. At this stage I want to keep countries separated and only cluster activities within a single country. Therefore, by the nature of clustering, small countries will probably become a single cluster. And although there could be cross-border holiday destinations in the <em>“real world”</em>, we will still be able to form these at a later step in the process by combining neighboring clusters.</p><p>Further, specifically for DBSCAN we have to define two <strong>variables. </strong>As DBSCAN is a density-based clustering algorithm, it requires an epsilon and the minimum population of a cluster, to define exactly what is the density that it should be looking for.</p><p><strong><em>Epsilon</em>:</strong> In our case we can use this epsilon variable to define the range in travel distance that we are willing to travel between activities within one full holiday. However, since the distance will be extracted from coordinates, the actual input value required will be the linear distance instead of the travel distance.</p><p>Let’s be very pragmatic on this one and say that we do not want to waste a full day driving to the next holiday activities and that the maximum we are willing to cover is roughly half a day. Assuming that it translates into an maximum amount of 500 km; and considering <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3835347/">a 1.4 benchmark</a>, this will result in 357 km of linear distance that we will enter as our initial epsilon variable.</p><p><strong><em>Minimum population of activities:</em></strong><em> </em>The minimum number of activities that we wish in a single cluster is directly related to the actual duration of the holiday (which will be a required parameter at a later stage). But the number of activities we can filter later at the moment of executing the algorithm. Therefore for the clustering process we should go for the minimum number of activities that would fill the minimum possible duration of a holiday.</p><p>This minimum possible duration that we’ll consider, is a weekend get-away; three days and an equal minimum amount of activities. Automatically meaning that if there are only two or less activities, within the epsilon distance, these will be considered an outlier and not part of any holiday destination.</p><h3>Applying clustering algorithm</h3><p>Finally time to get to the fun stuff and apply the DBSCAN clustering to our data-set. We will use python and the <a href="https://scikit-learn.org/stable/modules/clustering.html">scikit learn</a> clustering package for the actual implementation.</p><p>As an example of clustering we will pick the USA. A large country with major activities scattered all around:</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fplot.ly%2F%7EThijsB%2F92%2Factivities-us-hover-for-activity-names%2F&amp;src=https%3A%2F%2Fplot.ly%2F%7EThijsB%2F92.embed%3Fautosize%3Dtrue&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=plot" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a4c12682c950dee23a13965ecd97798/href">https://medium.com/media/5a4c12682c950dee23a13965ecd97798/href</a></iframe><p>Now let’s apply the DBSCAN clustering algorithm, with the 500 km travel distance as an epsilon requirement and three activities as the minimum required population within a cluster.</p><p>The cluster name starts with the country ISO code, then the number of the cluster within that country and last the number of activities in the cluster. Please note that ‘<em>-1</em>’ refers to an outlier.</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fplot.ly%2F%7EThijsB%2F90%2Fclustered-activities-us-hover-for-activity-names-cluster%2F&amp;src=https%3A%2F%2Fplot.ly%2F%7EThijsB%2F90.embed%3Fautosize%3Dtrue&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=plot" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/68b749c4d415f8ae1eafcd47f99047ba/href">https://medium.com/media/68b749c4d415f8ae1eafcd47f99047ba/href</a></iframe><p>That’s looking a lot more structured into actual destinations that we can travel to! The clustering resulted in this case in 7 destination clusters:</p><ul><li><em>Mid-East</em> with 27 major activities (from Chicago to New Orleans(!))</li><li><em>North-East</em> with 26 major activities (from Boston to Washington DC)</li><li><em>Florida </em>with 22 major activities</li><li><em>South-West</em> with 17 major activities (from LA to Bruce Canyon NP)</li><li><em>Hawaii Islands</em> with 5 major activities</li><li><em>San Francisco</em> with 4 major activities</li><li><em>Colorado </em>with 3 major activities</li></ul><p>Another 7 activities did not make it into any cluster and are considered outliers. Some great and exciting looking road-trips! The size of the clusters is of lesser importance at the moment as this will still be fine-tuned at a later stage, when holiday duration comes into play.</p><p>Curious to how the variables influence the clustering? Please see below a matrix with three different travel distances as epsilon variables (250, <strong>500</strong> and 700) and three minimum population requirements (1, <strong>3</strong>, 5):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*uYeDpQQyt-jbzPb2D2YpcQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*ikFP1EtYkFAdTaAjzoCz2w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*nDB07H3R1UHW2JX1YRx9JA.png" /><figcaption>Minimum Population Requirement: 1 ; Travel Distance for Epsilon: 250, 500, 750 km respectively ; No outliers</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*2X2mGGJL04B594TEQCqncA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*jdHEOW4rvRYe4jfFMqUr1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*nHlw-4ErswuAtBPkkLSRYw.png" /><figcaption>Minimum Population Requirement: <strong>3</strong>; Travel Distance for Epsilon: 250, <strong>500</strong>, 750 km respectively ; Outliers in green, green and orange respectively</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*XxeOHq4W47I1cci5T_NXrw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*SsLRlOUXcG2vflZO29wKLQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*1rc9ji6MRYxy04BfG3MbYQ.png" /><figcaption>Minimum Population Requirement: 5; Travel Distance for Epsilon: 250, 500, 750 km respectively ; Outliers in green, green and orange respectively</figcaption></figure><p>In general the trend is clear: less travel distance means more and smaller clusters as well as more outliers. While more travel distance means larger clusters and less of them. Also, less minimum population means less outliers and thus more (small) clusters, while a higher minimum population automatically leads to many more outliers and less clusters.</p><p>Our choices of variables (the middle one) seems a very reasonable outcome for exploring holiday destinations in the US; Well balanced between number of clusters, cluster sizes and the number of outliers.</p><p>But what about the rest of the world? Let’s explore it in the interactive chart below. Be sure to zoom in to explore clusters and find a gem within these <strong>248</strong> different holiday destinations!</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fplot.ly%2F%7EThijsB%2F98%2Fclustered-activities-global-hover-for-activity-names-cluster%2F&amp;src=https%3A%2F%2Fplot.ly%2F%7EThijsB%2F98.embed%3Fautosize%3Dtrue&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=plot" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/0066276519c5b0c9201f63a989bc6130/href">https://medium.com/media/0066276519c5b0c9201f63a989bc6130/href</a></iframe><p>As per our logic, much of the smaller countries (so basically everything in western and southern Europe) will be one cluster per country (except for island destinations), but larger countries have been separated into multiple destinations nicely. Overall it is exactly the result that we aimed for at this stage; giving us the ability to start analyzing destinations instead of single activities.</p><h3>Adding the score and visualize</h3><p>Now that we have our holiday destinations, we can add back our scoring measure that we created in chapter 1 based on its activities’ reviews. Let’s start with diving into the top 10 holiday destinations and their main city (in number of activities):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*eBXdYDDOjRGLTODxux8n9g.png" /><figcaption>Chart #1 Top 10 cluster with their main city based on weighted scoring measure</figcaption></figure><p>Well, it seems we definitely have to put Colorado on the top of our bucket list! Also interesting to see the neighboring clusters in Brazil and Argentina, around the Iguazu Falls, both in the top 5. Lastly, also Easter Island is scoring very high as a holiday destination. Probably not the first place that came to mind?</p><p>Finally, we would like to see the weighted average score per holiday destination mapped out on the globe in a similar way that we mapped out all activities in <a href="https://towardsdatascience.com/planet-beehive-aeca53ba0326">chapter 1</a>. Please note that the size of the cluster refers to the number of activities included and the darkness of the color fill to the scoring measure (the darker, the better):</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fplot.ly%2F%7EThijsB%2F104%2F&amp;src=https%3A%2F%2Fplot.ly%2F%7EThijsB%2F104.embed%3Fautosize%3Dtrue&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=plot" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/186c6c78643b53c5f0f43bf0fc4c360f/href">https://medium.com/media/186c6c78643b53c5f0f43bf0fc4c360f/href</a></iframe><p>Going forward we will consider these holiday destinations as our analysis objects and no longer talk in detail about single activities and / or countries as a destination.</p><p>Thank you for reading today’s article, next time we are going to tackle the TSP problem and create optimized road trips for each destination!</p><p><em>For more information about myself feel free to checkout my </em><a href="https://www.linkedin.com/in/thijs-bressers-a793bb19"><em>LinkedIn</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5c54b42de16" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/clustered-globe-e5c54b42de16">Clustered Globe</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Playground Earth]]></title>
            <link>https://medium.com/data-science/playground-earth-238f8253b030?source=rss-48bba4460823------2</link>
            <guid isPermaLink="false">https://medium.com/p/238f8253b030</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[travel]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Thijs Bressers]]></dc:creator>
            <pubDate>Fri, 28 Dec 2018 01:51:46 GMT</pubDate>
            <atom:updated>2018-12-28T01:57:04.433Z</atom:updated>
            <content:encoded><![CDATA[<h4>Ep. 2 : Categorizing the activities using categorical data mining</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I_tudrfXbPcmeJeEIuyXDA.png" /><figcaption>Part of our output today; Network chart visualizing the co-occurrences between our categorical data</figcaption></figure><p>Do you like waterfalls, beaches, museums, food, mountains, nature, amusement parks, aquariums and city landmarks <em>equally </em>or do you have some preferences on your holiday? Probably you do. However, in <a href="https://towardsdatascience.com/planet-beehive-aeca53ba0326">episode 1</a> we objectively established the number 1 and 2 activities in the world to be waterfalls.. but what if you don’t like waterfalls? You probably finished the post and disagreed completely with anything we derived.</p><p>In order to manage our subjective preferences, we will need our algorithm to be able to deal with the input of a<em> </em><strong><em>limited subset</em></strong><em> </em>of categories as desired by the user. As descriptions of activities come in many varieties, our main objective today will be to generalize all these varieties into a subset of ‘core’ activities. Such as those described above.</p><p>Nice, sounds like we get to dive into textual categorical data mining today!</p><h3>Our Approach</h3><ol><li>First we will have to create the relation between categories from our source data into a <strong><em>co-occurrence matrix. </em></strong>This will help us establish the most mentioned activities.</li><li><strong><em>Visualize</em></strong><em> </em>this matrix into a <strong><em>network chart</em></strong><em> </em>and retrieve the weight per co-occurrence combination.</li><li><strong><em>Retrieve the root category subset </em></strong>by looking at the highest weighted categories and (if required) manual interference</li><li><strong><em>Transform into parent-child hierarchy </em></strong>and derive the parent root category for each child category that exists. By going from each child, every time to its most weighted parent, till we reach a root category variable.</li></ol><h3>The Data</h3><p>For today’s exercise we can fully rely on the data already staged and prepared in <a href="https://towardsdatascience.com/planet-beehive-aeca53ba0326">Episode 1</a>. Both the data from TripAdvisor and Google include one or multiple categorical values for each activity. These combined into a list, make our total set of categories per activity.</p><p>At this point there is no need to further enrich this data from other external data sources, we can perfectly start from where we left off at episode 1.</p><h3>Generalizing our Categories</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*0amKBSo9PHbXYr9cmX7GrA.jpeg" /><figcaption>Fabrica La Aurora, San Miguel de Allende, Mexico — image source <a href="http://fabricalaaurora.com/">http://fabricalaaurora.com</a></figcaption></figure><p>Let’s start with an example of why our categorical data is in need of generalization: the <a href="http://fabricalaaurora.com/">Fabrica La Aurora</a> in San Miguel de Allende, Mexico. From the pictures (above) and information on the website, a great looking art center, that consists of multiple galleries, some stores to purchase art related attributes as well as some places to eat and drink in between. Sounds like something I definitely would want to visit on my holiday, but how does it categorize in our data:</p><blockquote>art galleries; art gallery; cafe; jewelry store; furniture store; home goods store; store; restaurant; food;</blockquote><p>These are a lot of different categories, a lot of overlapping categories (i.e. art galleries vs art gallery), and way too broad categories to suffice as an input filter for our algorithm. And there is the need for generalization!</p><p>In total we have 14&#39;806 mentions of 235 different categories spread out over our 7&#39;044 activities. That means that on average each activity has 2.1 different categories. With these figures we can also very safely assume that multiple combinations of these 235 categories will co-occur on multiple activities (i.e. most likely <em>art galleries</em> will often co-occur with <em>art gallery</em>)</p><p>In order to explore the relation between the current categories, we will use a hobbyist approach to <a href="https://en.wikipedia.org/wiki/Network_theory">Network Theory</a>. With the ultimate goal to derive the root values (most occurring activities) and their link to lesser occurring activities (mapping them as a leaf to their root).</p><p>For this, we first need to create a co-occurrence matrix. As the name reveals, this means we create a matrix of the number of occurrences for all possible combinations of two out of our 235 categories.</p><p>This co-occurrence matrix is best visualized in a network graph that will show the connections between our categories and will also show the most co-occurring activities and connections:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hGrk8Q0ScSKvED7UQu6aqQ.png" /><figcaption>Fig. 1 Network chart of all our activities’ mentioned categories; Created with G<a href="https://gephi.org/">ephi</a></figcaption></figure><p>From this chart we can see immediately some of the key categories that are occurring most often: Food, park, museum, store, restaurant, historic site, natural feature and some more.</p><p>Also some connections are quite clear: ‘<em>Place of Worship</em>’ is clearly linked with ‘<em>Church</em>’, ‘<em>Mosque</em>’, <em>‘Hindu Temple’</em> and ‘<em>Sacred &amp; Religious site</em>’ but also with ‘<em>Architectural Building</em>’; while ‘<em>Store</em>’, ‘<em>Restaurant</em>’, ‘<em>Cafe</em>’, ‘<em>Bar</em>’ and ‘<em>Food</em>’ also often go hand in hand.</p><p>The goal is to define a manageable subset of root categories to which all other categories can be related back to, through these co-occurrences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*v88GWTK4vBze4Kl_6eFWxQ.png" /><figcaption>Fig. 2 Root categories</figcaption></figure><p>To establish these initial root categories, we will use the returned related table behind the chart that includes the weight of occurrence for each possible combination of categories.</p><p>Looking at the distribution of this weight value aggregated per activity, we will start by filtering on categories where the weight &gt; 200. This will be leading us to the root activities displayed in fig. 2 on the left.</p><p>The friendly name to which we mapped each of these categories gives us 12 distinct categories that we will now consider our root category subset for further analysis.</p><p>The next step is to derive the related root category for all of the 235 categories that are <strong>not</strong> in the above list. For this we can build a parent-child hierarchy and loop through all the categories based on the weight, till we reach the first root value.</p><p>In other words, lets look for each category that is not in the above list, to which category its most co-occurring by weight, if that activity is not in the root, we will again look its most co-occurring category and continue until we find the category that is in the root.</p><p>The below example will show you how this works. In this case we want to find the root category for the category ‘<em>Campground</em>’. Which turns out to be ‘<em>Park</em>’ (note that when equal weight apply, the alphabetic order prevails):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*hJIpQw2iZ-sIeXQCM91teA.png" /><figcaption>Fig. 3 relation tree for category ‘Campground’ ending into root category ‘Park’</figcaption></figure><p>Applying this transformation to each category, will give us one (or multiple) root categories for each activity.</p><p>So back to <em>Fabrica la Aurora</em> as an example; initially we saw the following categories from Google/TripAdvisor combined:</p><blockquote>art galleries; art gallery; cafe; jewelry store; furniture store; home goods store; store; restaurant; food;</blockquote><p>The result from are above implement transformation generalized these to the following root categories respectively:</p><blockquote>museum &amp; gallery; museum &amp; gallery; food &amp; drinks; shopping; shopping; shopping; shopping; food &amp; drinks; food &amp; drinks;</blockquote><p>or, when uniqueness is applied: <strong>Museum &amp; Gallery, Shopping </strong>and<strong> Food &amp; Drinks</strong>. Not bad! Meaning that this activity will be included in the algorithms’ output whenever <em>any (or all) </em>of the above three categories are given as an input.</p><p>After this step, let’s make up the balance of the number of activities that will be filtered for each of these automatically derived root activities:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*lneBKjMITOkhuklgie6nBA.png" /><figcaption>Fig. 4 number of activities per root category, produced with Seaborn</figcaption></figure><h3><strong>Manual Interference</strong></h3><p>This approach is obviously not waterproof, so here I would like to manually interfere in some categories. Lets have a more detailed look into what subcategories make up the four main categories and the ‘<em>Other</em>’ category (which we want to be as small as possible).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*PKlXYckadvcMdSqbiuOlug.png" /><figcaption>Fig. 5 Overview of all remaining categories to be mapped</figcaption></figure><p>On the left we see these subcategories; the ones that I want to amend manually, I have highlighted here.</p><p>First of all, lets separate subcategories: ‘beaches’ and ‘mountains’ from ‘Nature’ into new root categories for each of them. Although the allocation can be considered accurate (to nature), they are such significant features of holidays that they should be root categories on their own.</p><p>Secondly, we see some categories wrongly allocated that can be categorized together into a new category ‘<em>Landmark</em>’ containing of subcategories: ‘<em>Points of interest &amp; landmark</em>’, ‘<em>architectural building</em>’, ‘<em>castle</em>’ and ‘<em>monuments &amp; statue</em>’</p><p>And lastly, the subcategory ‘<em>neighborhood</em>’ in ‘<em>other</em>’ has enough weight to be a category on its own instead of other. So we will map it separately as well.</p><p>Having made these adjustments, we end up with 16 final root categories leading to the following numbers of activities that are linked to them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*trNLVnHrxT4r9XT0fZG81g.png" /><figcaption>Fig. 6 final number of activities per root category, produced with Seaborn</figcaption></figure><p>So from our 235 distinct categories that where derived for our activities, we have managed to generalize them to 16 distinct categories. And we only had to interfere with 7 out of these 235 activities manually! Quite happy with the results, giving our final algorithm the ability to easily filter touristic activities on categories as input.</p><h3>Adding our Score into the mix</h3><p>Now that we have our activities, we can go back to our scoring measure that we created in <a href="https://towardsdatascience.com/planet-beehive-aeca53ba0326">episode 1</a> and combine the two. We have already looked at the weighted average score by region, country and individual activities, now lets look at what are the best rated categories:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*adqHoA_2geMSMgMa_bnhnw.png" /><figcaption>Fig. 7 score per category barplot produced with Seaborn</figcaption></figure><p><em>Mountains </em>are our absolute top favorite (and I personally couldn’t agree more). Followed at a slight distance by <em>Bodies of Water, Historic Site and Nature.</em></p><p>Since pictures say more than a thousand words, let’s have a look at the top 3 activities in each of these categories:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3_VRw72tgVSdu5ET.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CQKycGC8hz0femg_.JPG" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zThYUVh1Otcuxlwu.jpg" /><figcaption><strong>Top 3 mountains: </strong>#1 Table Mountain, Capetown, South Africa | #2 Serra de Tramuntara, Mallorca, Spain | #3 Aguille du Midi, Chamonix, France</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Pj-A6f5HMPRBNFre.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KZUwQ9oD8nEUua4D.JPG" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JA4nCFhG2lxOI-zT.JPG" /><figcaption><strong>Top 3 bodies of water</strong>: #1 Jokulsarlon Lagoon, Iceland | #2 Lagunas Miscanti y Miniques, San Pedro de Atacama, Chile | #3 Moraine Lake, Lake Louise, Canada</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8GQQlU81ziIrW8if.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*beS2bnwizbCyQ1QU.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8qPQvpCcM5d0ell2.jpg" /><figcaption><strong>Top 3 historic sites: </strong>#1 Jerusalem Old City, Jerusalem, Israel | #2 Angkor Wat, Siem Reap, Cambodia | #3 St. Peter’s Basilica, Vatican City, Italy</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*pUtTUETlsFJxAtPu.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0lrmcoEU9iI5PK0F.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3_VRw72tgVSdu5ET.jpg" /><figcaption><strong>Top 3 nature: </strong>#1 Niagara Falls, Canada | #2 Iguazu Falls, Foz do Iguacu, Brazil | #3 Table Mountain, Capetown, South Africa (yes, again)</figcaption></figure><p>Well, I just updated my bucket list with some of these finds!</p><p>Very pleasantly surprised about the accuracy of the outcome of our generalization at first sight. As well as the large diversity within the top of the categories in terms of regions and continents.</p><h3>Conclusion</h3><p>Today we have succeeded in using a basic form of network theory to generalize all our 235 different categories into just 16. Very important in order to filter activities in a simplified way, while still being able to have the algorithm only select relevant activities.</p><p>Next post we will be looking into <strong>clustering</strong> our activities in actual holiday destinations!</p><p>To explore a bit further, please find below a heat-map comparing the best scoring activities per regions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y2Twi00WMj6WuN90MwRzPg.png" /><figcaption>Fig. 8 Heat map produced with Seaborn in Python</figcaption></figure><p><em>For more information about myself feel free to checkout my </em><a href="https://www.linkedin.com/in/thijs-bressers-a793bb19"><em>LinkedIn</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=238f8253b030" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/playground-earth-238f8253b030">Playground Earth</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Planet Beehive]]></title>
            <link>https://medium.com/data-science/planet-beehive-aeca53ba0326?source=rss-48bba4460823------2</link>
            <guid isPermaLink="false">https://medium.com/p/aeca53ba0326</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[exploring]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[travel]]></category>
            <dc:creator><![CDATA[Thijs Bressers]]></dc:creator>
            <pubDate>Wed, 19 Dec 2018 15:06:00 GMT</pubDate>
            <atom:updated>2018-12-28T01:53:24.222Z</atom:updated>
            <content:encoded><![CDATA[<h4>Ep. 1 : Exploring our planets’ touristic activities</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*41MmoadVFokXyCkTnj6UZQ.png" /><figcaption>Our output for today; Make sure to read below how we get there; Calculate our measures and for a interactive visualization</figcaption></figure><p>Close your eyes for a second, ignore the rain dripping outside, the beep from a new incoming email and deeply think about ten global activities that are on the top of your To Do list ..</p><p>Now be honest, how many of those are on the <a href="https://www.lovehomeswap.com/blog/latest-news/the-50-most-visited-tourist-attractions-in-the-world"><em>most visited</em> activities</a> in the world? No harm in that, they are visited for a reason. However, are they actually worth the limited resources we have to travel there? Or might there be alternatives that don’t come to mind immediately?</p><p>Those questions are among those we wish to answer today. Can we objectively create a measure that represents not only the most visited but also the <em>best rated</em> global activities and can we visualize these into an, easy to detect new pearls, map?</p><h3>Our Approach</h3><ol><li>We will have a look at the current measures available and <strong><em>transform data</em></strong> if required for enhanced downstream analysis and visualization</li><li><strong><em>Create</em> </strong>a formula that combines number of reviews as well has their user rating into <strong><em>a new measure</em></strong> that we will use in our algorithm in follow up episodes</li><li>Perform <strong><em>exploratory data analysis</em></strong> on regional, country as well as individual activity level to verify our newly created measure</li><li><strong><em>Visualize </em></strong>our data into a interactive chart that we will be amending during the next episodes into an interactive dashboard</li></ol><h3>The Data</h3><p>The data that we will be using today includes: the activity metadata, their number of reviews, their user rating and some additional geodata. These we will derive from the following sources initially:</p><ul><li><a href="http://www.tripadvisor.com/">TripAdvisor</a> : <em>To collect </em><strong><em>the</em></strong><em> </em><strong><em>activities, number of user reviews and their rating</em></strong><em>, their collection of activities will be our starting point. Here we focus only on activities that are featured on each country’s ‘top things to do’ list OR activities that have more than 750 reviews.</em></li><li><a href="http://www.google.com/">Google</a> :<em> By using the Google Places and Geocoding API we enrich our activity data from TripAdvisor to collect </em><strong><em>geodata</em></strong><em> (i.e. coordinates) as well as the </em><strong><em>average rating</em></strong><em> from google users.</em></li><li><a href="https://www.cia.gov/library/publications/resources/the-world-factbook/">CIA World Factbook</a> : <em>For reference data about countries (size, citizens, etc.) we will use the comprehensive database from the CIA World Factbook. We start with 174 countries in scope</em></li></ul><h3>Data Transformation</h3><p>Our data-set starts with 7&#39;044 activities, of which for 5&#39;971 we could also derive the google user rating. An okay start for today’s exercise.</p><p>Let’s see what the data looks like by creating two scatter plots with the 4 measures we care about the most: one with the <strong>latitude </strong>and <strong>longitude </strong>and another one with the <strong>number of reviews</strong> and the <strong>average rating per activity</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*wyFxMgFF65xDJOpURuUKUw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*eUv0jSnvuJACrSOrh_eMXA.png" /><figcaption>Fig. 1, 2 Scatter plots created with Matplotlib in Python</figcaption></figure><p>Some initial key take away’s here:</p><ul><li>It seems awfully crowded with activities in Europe. Which might be caused by a user bias of using TripAdvisor. However in general our geodata looks clean and we have a proper global diversification.</li><li>We love to give high ratings! There is hardly any rating lower than 6/10 and clearly the majority of the ratings are higher than a 8/10. The simple average combined rating is even an amazing 8.98/10!</li><li>When it comes to number of reviews, it seems that the majority of activities have 20&#39;000 or less reviews. While at the same time there are quite some outliers, and a definite highlight activity with way over 120&#39;000 reviews! (can you guess which highlight this is?)</li><li>Both the number of reviews as well as the average rating measures are not normally distributed</li></ul><p>And the latter is our key point here. As it is our goal today to use these measures for comparison reasons, we want to achieve an as much as possible normally distributed measure set in both cases. <em>Fig. 2</em> tells us a bit about both measures and how they are distributed.</p><p>Looking at the <strong>number of reviews</strong> first, it seems that we are dealing with a log-normal distribution, given the large amount of smaller values ad the very limited amount of very high values. To confirm this observation we will plot two QQ plots, one with a normal axis and another one with a logarithmic axis, a straight diagonal line would confirm a normal distribution:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zjGc-S6ziMVj-MJbP3UazA.png" /><figcaption>Fig. 3, 4 QQ plots with regular y-axis (left) and log y-axis (right) produced with <a href="https://matplotlib.org/mpl-probscale/api/probscale.html">Probscale</a> in Python</figcaption></figure><p>As expected, the logarithmic scale gives us a much better fit to a normal distributed data-set than the regular scale. Therefore we will apply a LOG10 transformation to the number of review measures. This new measure is what we will use for comparing the reviews going forward.</p><p>Then over to the distribution of the <strong>average rating.</strong> Here the problem does not necessary seem to represent a skewness in the data, but more a less a problem of users giving too high ratings. When simply looking at the rating above an 8, the distribution seems to be rather close to normal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*6PbAYtShKxHZmuDVtUDNBw.png" /><figcaption>Fig. 5 Boxplots produced with Pandas in Python</figcaption></figure><p>This observation we can confirm with the boxplots on the left. Looking at each of the rating value, and the average of both sources, we can see that the distribution can be considered normal between an 8 and 10 with outliers at any rating below 8.</p><p>As a result we will transform the data into a new measure that will have a bottom threshold of 0.8 (meaning that 0.8 equals ≤ 0.8)</p><p>As a final step we will apply a MinMax normalization to both measures.</p><p>Now we can compare our transformed measures’ distribution with the original measures’ distribution in the jointplot comparison below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*d4ATU0t_KFAnQ75-lUTqhQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*8ZboBn6zZ6dFdDV7D5FKpw.png" /><figcaption>Fig. 6, 7 Combined distribution plots Before and After respectively created with Seaborn in Python</figcaption></figure><p>From this we can create a new measure that should represent the best combination of both measures. Multiplying them will give us a value that represent the weighted score over the number of reviews (i.e. the more reviews, the more reliable its rating):</p><blockquote><strong>Activity Score:</strong></blockquote><blockquote>norm. floored avg. visitor rating *</blockquote><blockquote>(norm. log10 review count / avg(norm. log10 review count))</blockquote><h3>Exploring our Activities</h3><p>Now that we have created our Scoring Measure, we can start exploring the data.</p><p>Let’s start by comparing global regions’ activity rating with the average number of reviews per activity:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*76oCJDhMSA7SSQs5SJCIUA.png" /><figcaption>Fig. 8 Scatter plot generated with Seaborn in Python</figcaption></figure><p>Now this is getting interesting! Some very particular facts here that might just go against your preconceptions.</p><p>First of all, at a high level, there is clearly a positive relation between these two variables. Which would naturally make sense, the better the activity is rated, the more people that will visit. Until of course you reach a the point where the number of visitors become a negative variable in the rating:</p><blockquote>Nobody goes there anymore. It’s too crowded.</blockquote><p>Secondly, looking at the top 3 regions in average number of reviews, these seem in an order many of us could have guessed them. Western-, Southern Europe and Northern America contain many well known touristic hot spots receiving many visitors and therefore also many reviews on average per activity.</p><p>The same goes for the top 3 average rated regions: Australia &amp; New Zealand, Central America and Northern America are often praised regions. The most surprising region from my personal opinion is Eastern Europe that takes the fourth place, ahead of any other European region!</p><p>Finally, looking at it from a continent perspective: the Americas and Europe are performing at the top of the list, while Asia, Oceania and Africa show much more divided continents. Especially Western and Middle Africa are at the absolute bottom of both measures, while Southern and Northern Africa are not too far behind the rest.</p><p>Let’s move down towards a country view and plot the top 10 and bottom 10 countries based on their weighted average rating and see what we can make of it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fMd9s35EIEEIkBFvQYzzDQ.png" /></figure><p>Russia claims the top spot! Probably quite unexpected for some of us, but at the same time we see Ukraine up there in the top 5 as well, completely in line with regional overview before, and another 2 Eastern European coutries in the remaining top 15 (Belarus and Slovenia)</p><p>I guess all the other countries in the top 15 will be quite obvious for most of us, each one of them are very well known holiday destinations. Probably most surprising is to see is Chili beating all other Southern American countries.</p><p>It’s good to see that the top 15 is represented with countries from 5 out of 7 continents. But the bottom 15 is looking a lot less diversified and is almost completely dominated by African countries (mainly west- and middle Africa to be more precise). North Korea is the only country from another continent that is able to blend into this not so prestigious list.</p><p>To make these country hot spots a bit more visible on a global scale, we can create a global heatmap, plotting the weighted average activity score on a country by country basis:</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fplot.ly%2F%7EThijsB%2F86%2F&amp;src=https%3A%2F%2Fplot.ly%2F%7EThijsB%2F86.embed%3Fautosize%3Dtrue&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=plot" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/1257119051cd3509e14ec068d09f42a3/href">https://medium.com/media/1257119051cd3509e14ec068d09f42a3/href</a></iframe><p>This plot confirms largely what we already discovered before. There are clear <strong>hot spots </strong>including Europe (especially Eastern and South-Western Europe), North-America (especially Canada and Central America), Oceania and South America, although Paraguay and some smaller nations in the north are negative outliers there.</p><p>The ‘cold’ spots are most obvious in middle and western Africa. While Southern, Northern and as well some parts in Eastern Africa get rated slightly better. Asia is showing a very mixed picture with some countries belonging to the absolute cold spots (North Korea, Papua new Guinea, Kyrgyzstan) while other countries are rated very high (Thailand, Turkey, Yemen).</p><p>So far we have quite a good pictures how regions as well as countries get rated from fellow travelers, now it is time to look at individual activities. After all our goal today is to map out each activity on the map and making it comparable on the average rating it receives as well as the number of reviews it got.</p><p>Therefore in the following plot we see the top 15 activities purely based on <em>number of reviews</em> and then the top 15 activities based on our newly created scoring measure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p07FA251hbhzi73kMRN4uw.png" /></figure><p>What an interesting differences! Some key takeaways:</p><ul><li>None of the activities in the top 15 in <strong>number of reviews </strong>are probably very surprising to anyone; completely dominated by the famous activities in Europe and North America (actually New York).</li><li>While the top 15 activities in our newly created <strong>weighted score measure</strong> reflect a high diversity of continents present (again 5 out of 7) and definitely include some new bucket list entries for me personally.</li><li>It surprises me that none of the top activities based on number of reviews also made it to weighted score top list. This must mean that their average rating received online is significant less than the top 15 of the weighted score activities.</li><li>While the top chart is dominated with European activities, the second chart only has two activities from Europe included. So while they receive a lot of reviews (and visitors), their ratings falls a bit behind other (less visited) activities.</li></ul><h3>The concluding chart</h3><p>Now it’s time to enable all of us to explore all activities ourselves while being able to clearly distinguish the rating as well as the number of reviews for each of them. We will now plot all activities with a marker fill being the floored average rating while we will make the size of the marker the number of reviews. All detail for each activity will be in the label when you hover over.</p><p>Also below you will find the top 100 activities based on our newly created measure for further reference.</p><blockquote>Be sure to zoom into your home country (don’t blame the map for having a bit less details) or your next travel destination as you just might find some real great catches!</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fplot.ly%2F%7EThijsB%2F84%2F&amp;src=https%3A%2F%2Fplot.ly%2F%7EThijsB%2F84.embed%3Fautosize%3Dtrue&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=plot" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/da78d7606b9aba3e13173eeb7dda59cc/href">https://medium.com/media/da78d7606b9aba3e13173eeb7dda59cc/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I-2b5BdM6AyImoqmiNOJtg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aeca53ba0326" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/planet-beehive-aeca53ba0326">Planet Beehive</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>