<?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 Evans Doe Ocansey on Medium]]></title>
        <description><![CDATA[Stories by Evans Doe Ocansey on Medium]]></description>
        <link>https://medium.com/@eocansey?source=rss-2617ca03887d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DCmnNlbtVoezaq6eJPFyew.jpeg</url>
            <title>Stories by Evans Doe Ocansey on Medium</title>
            <link>https://medium.com/@eocansey?source=rss-2617ca03887d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 15:04:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@eocansey/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[Using Machine Learning to Predict Customers Next Purchase Day]]></title>
            <link>https://medium.com/data-science/using-machine-learning-to-predict-customers-next-purchase-day-7895ad49b4db?source=rss-2617ca03887d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7895ad49b4db</guid>
            <category><![CDATA[business-intelligence]]></category>
            <category><![CDATA[predictive-analytics]]></category>
            <category><![CDATA[deep-dives]]></category>
            <category><![CDATA[customer-engagement]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Evans Doe Ocansey]]></dc:creator>
            <pubDate>Fri, 30 Apr 2021 18:52:32 GMT</pubDate>
            <atom:updated>2021-07-04T18:18:22.319Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using Machine Learning to Predict Customers’ Next Purchase Day</h3><h4>Machine Learning model to predict whether customers will make their next purchase after a certain period.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*57y22gCTcHbOfwsy5d1iVQ.jpeg" /><figcaption>Image by <a href="https://pixabay.com/users/mediamodifier-1567646/">Mediamodifier</a> and can be accessed <a href="https://pixabay.com/photos/ecommerce-selling-online-2140603/">here</a>.</figcaption></figure><h3>Introduction</h3><p>If there is one major lesson that those in the retail business have learnt from the <a href="https://en.wikipedia.org/wiki/Severe_acute_respiratory_syndrome_coronavirus_2">SARS-CoV-2</a> pandemic, it is the demand to switch to doing business via the Internet, i.e., <a href="https://en.wikipedia.org/wiki/E-commerce">e-commerce</a>. The idea of e-commerce assists those in managerial positions to make decisions for the progress of their companies. Undoubtedly, most of these decisions are influenced by the results derived from studying the purchasing behavioural data of online customers by experts in data analysis, data science, and machine learning.</p><p>Suppose the managerial team of an online retail shop approaches you, a data scientist, with the <a href="https://www.kaggle.com/mashlyn/online-retail-ii-uci/download">dataset</a> wanting to know whether customers will make their next purchase 90 days from the day they made their last purchase. Your answer to their inquiry will help them identify which customers their marketing team need to have a focus on with regard to the next promotional offers they will be rolling out.</p><p>In this article, my goal as a data scientist is to build a model that will provide a suitable answer to the question posed by the firm&#39;s managers. More precisely, using the given <a href="https://www.kaggle.com/mashlyn/online-retail-ii-uci/download">dataset</a>, I build a machine learning model that predicts whether an online customer of a retail shop will make their next purchase 90 days from the day they made their last purchase.</p><p>It is worth mentioning that <a href="https://medium.com/@karamanbk">Barış Karaman</a>¹ has done a <a href="https://towardsdatascience.com/predicting-next-purchase-day-15fae5548027">similar work</a> that answers a different question and not this exact forecast the question we have, seeks to preempt.</p><h3>Some Information about the Dataset</h3><p>Before proceeding to answer the question of interest, I will first present some general and useful information about the <a href="https://www.kaggle.com/mashlyn/online-retail-ii-uci/download">dataset</a>.</p><p>The dataset recorded 5942 online customers from 43 different countries. Among the online customers of the retail shop, 90.8% of them were living in the United Kingdom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TGPiMZe52tKfjLpCo-e7AA.png" /><figcaption>Figure 1: Customer Country Count in Percentage — Image by <a href="https://eocansey.medium.com/">Author</a></figcaption></figure><p>With such a huge customer base in the United Kingdom, it is not surprising that 83% of the company’s revenue came from the United Kingdom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fMY1c3z5BzG8SqWoE-3qAw.png" /><figcaption>Figure 2: Revenue of Countries in Percentage — Image by <a href="https://eocansey.medium.com/">Author</a></figcaption></figure><p>Figure 3 below gives a visual representation of the monthly revenue earned by the online retail company.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GErH_MhT09Z_U6UJ8pT7nA.png" /><figcaption>Figure 3: Monthly Revenue from December 2009 until December 2011 — Image by <a href="https://eocansey.medium.com/">Author</a>.</figcaption></figure><p>Here, one can observe that the company recorded its highest revenue in the month of November 2010, followed by November 2011. In addition, there is a rise in monthly revenue after August.</p><p>From the analysis made in this section, there is the advice one can give to the managers for consideration. In the company’s bid to increase its customer base in other countries than the United Kingdom, what could be a possible advice a data scientist can suggest to the managerial team? In an answer to this, I would say that…</p><p><em>Since the company has a solid customer base in the United Kingdom, it could capitalise on that and roll out a “win-win promotion”. In implementing this rollout, specifically, for any product that an existing customer buys, he/she gets the opportunity to invite a new customer outside the United Kingdom via a web link. If the new customer buys something from the online shop using the web link he/she received from the already existing customer, the company gives both the existing customer and the new customer a cash voucher that can be used by both parties in their next purchase. By so doing we see that the company, the existing or earlier customer, and the new customer all receive a level of satisfaction in the transaction made.</em></p><h3>Predicting Customers’ Next Purchase</h3><p>In this section, I focus on the methods that I deployed to solve the problem of interest. That is, <em>to build a machine learning model that will predict whether an online customer of a retail shop will make their next purchase 90 days from the day they made their last purchase.</em></p><p>The major steps included the following:</p><ul><li><strong>Data Wrangling</strong></li><li><strong>Feature Engineering</strong></li><li><strong>Building Machine Learning Models</strong></li><li><strong>Selecting Model</strong></li></ul><p>I begin by importing the necessary Python packages, download the <a href="https://www.kaggle.com/mashlyn/online-retail-ii-uci/download">dataset</a> and then load it into my Python environment. The code snippet below summarises this step.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FNzcICngvwlgVQDktYYxp%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FNzcICngvwlgVQDktYYxp&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e8aa23b64b11f3c9b5d211d9d3ed5d3/href">https://medium.com/media/0e8aa23b64b11f3c9b5d211d9d3ed5d3/href</a></iframe><h4>Data Wrangling</h4><p>I then wrangle with the dataset to put it into good shape so as to introduce new X features.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FSKbfz5gpBJAtzy1tRMqZ%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FSKbfz5gpBJAtzy1tRMqZ&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f48eafb6f941ed9e44ab9b30850d9241/href">https://medium.com/media/f48eafb6f941ed9e44ab9b30850d9241/href</a></iframe><p>The CustomerID column of the given dataset has 243007 missing data. That represents 22.77% of the entire online customers. Moreover, the Description column has 4382missing data. How do I deal with these missing data? After talking to the company leaders, they suggested that any item that has missing CustomerID should be dropped.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FKSzz0DsIS5Hq0iWN1Dd2%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FKSzz0DsIS5Hq0iWN1Dd2&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ad5b7b39ca7ca8be326f03c3cde092e/href">https://medium.com/media/6ad5b7b39ca7ca8be326f03c3cde092e/href</a></iframe><p>The dataframe df_data is split into two pandas data frames. Namely,</p><ul><li>The first sub-dataframe, ctm_bhvr_dt, contains purchases made by customers from 01–12–2009 to 30–08–2011. From this dataset, I get the last purchase date of all online customers.</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FrcszueGI1mjA1dejapY4%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FrcszueGI1mjA1dejapY4&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/746a999d5c260cae940274265480f195/href">https://medium.com/media/746a999d5c260cae940274265480f195/href</a></iframe><ul><li>The second sub-dataframe ctm_next_quarter is used to get the first purchase date of the customers from 01–09–2011 to 30–11–2011.</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FcMgBiX3Hm498gHqIDdXl%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FcMgBiX3Hm498gHqIDdXl&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9e094a14a05ea34bfa6b98535437c25/href">https://medium.com/media/f9e094a14a05ea34bfa6b98535437c25/href</a></iframe><p>Next, I create a pandas dataframe that contains a set of features of each customer for us to build our prediction model. I begin by creating a dataset that contains the distinct customers in the dataframe ctm_bhvr_dt.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FNBw5rNVsMqVHEE6GiLwM%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FNBw5rNVsMqVHEE6GiLwM&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/24c0bfa5de6e688465e016f67414fcd8/href">https://medium.com/media/24c0bfa5de6e688465e016f67414fcd8/href</a></iframe><p>I then add a new label, <strong>NextPurchaseDay</strong> to the dataframe ctm_dt. This new label will be the number of days between the last purchase date of a customer in the dataframe the customer who has the most frequently purchased item that is with missing CustomerID the following procedure to deal with the missing values in the CustomerID column. turns out that thectm_bhvr_dt and his/her first purchase date in the dataframe ctm_next_quarter.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2F1Pxi4jKJfMwKKkwtMGW4%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F1Pxi4jKJfMwKKkwtMGW4&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ad70ee2fd7811f096b12b2d7cd10f59/href">https://medium.com/media/9ad70ee2fd7811f096b12b2d7cd10f59/href</a></iframe><p>Figure 5 below is the output of the code snippet above. It shows the first 5 entries of the dataframe object, ctm_dt .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84b41949fab41609df4cb791343818b9/href">https://medium.com/media/84b41949fab41609df4cb791343818b9/href</a></iframe><p>In the next section, I introduce some features and add them to the dataframe ctm_dt to build our machine learning model.</p><h4>Feature Engineering</h4><p>I introduce features into our dataframe ctm_dt that segments customers into groups based on their value to the company. In executing this I use the RFM segmentation method. RFM stands for</p><ul><li><strong>Recency</strong>: indicating how recent a customer made a purchase.</li><li><strong>Frequency</strong>: How often or the number of times a customer purchases.</li><li><strong>Monetary Value/Revenue</strong>: The amount of money a customer spends when making a purchase at a point in time.</li></ul><p>Using these three features being recency, frequency, and monetary value/revenue, I create an RFM score system to group the customers. Essentially, the RFM score derived is what helps to give an insight into what a customer would probably do regarding purchase decisions in the future.</p><p>After calculating the RFM score, I then apply <em>unsupervised machine learning</em> to identify different groups (clusters) for each score and add them to the dataframe ct_dt. Finally, I apply the pandas dataframe method get_dummies to ctm_dt to deal with the categorical features in the dataframe. I now make a move into coding to fish out the computation of the RFM scores and the clustering.</p><p><strong>Recency</strong></p><p>In getting to know who is likely to make a current purchase, I use the recency feature to work this out. Factoring in the length of time a customer has taken off after his or her last purchase, the recency characteristic comes in handy here. I use this feature to know which customer will be coming in for a transaction. It is relevant to also note that the sales transaction of a recent purchasing customer is of far more worth than the customer who has not bought in a while.</p><p>Let us get into the coding here below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FDkh0RCHGcStuL4TdWft0%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FDkh0RCHGcStuL4TdWft0&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7feedf5c7939c3c4e8e81487acc094af/href">https://medium.com/media/7feedf5c7939c3c4e8e81487acc094af/href</a></iframe><p>Figure 6 below gives a visual presentation of the recency data of the online customers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wBewS6ZEFI69-xT-DOWBig.png" /><figcaption>Figure 6: Histogram of the recency data of customers — Image by <a href="https://eocansey.medium.com/">Author</a>.</figcaption></figure><p>The code used to generate Figure 6 above can be accessed in the Jupyter notebook <a href="https://github.com/evansdoe/online_retail/blob/main/online_retail.ipynb">here</a>.</p><p>Next, I need to assign a recency score for the recency values. This can be achieved by applying the <em>K-means clustering algorithm.</em> However, we need to know the number of clusters before using the algorithm. Applying the <a href="https://en.wikipedia.org/wiki/Elbow_method_(clustering)"><em>Elbow Method</em></a>, one can determine the number of clusters needed for a given data. In our case, given the recency values as our data, the number of clusters computed is 4. The code used to compute the number of clusters is available in the Jupyter notebook <a href="https://github.com/evansdoe/online_retail/blob/main/online_retail.ipynb">here</a>.</p><p>I can now build 4-clusters using the <strong>Recency</strong> column in the dataframe ctm_dt and create a new column <strong>RecencyCluster</strong> in ctm_dt whose values are the cluster value predicted by the unsupervised machine learning algorithm kmeans. Using the user-defined Python function order_cluster accessible <a href="https://github.com/evansdoe/online_retail/blob/main/online_retail.ipynb">here</a>, I sort the dataframe ctm_dt in decreasing order of the values in <strong>RecencyCluster</strong>. The code snippet below outputs Figure 7 below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FkZVSljVHfWarYudMcbVd%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FkZVSljVHfWarYudMcbVd&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7039b6e6965396c1eef131fe111206f/href">https://medium.com/media/e7039b6e6965396c1eef131fe111206f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eadc49206b0fb4950010e150e755d760/href">https://medium.com/media/eadc49206b0fb4950010e150e755d760/href</a></iframe><p>Let us group the dataframe ctm_dt by the cluster values in the column labelled <strong>RecencyCluster</strong> and fetch out the statistical description of the <strong>Recency</strong> data of each of these clusters</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FGGtZDY32hjfEYT3t4K0p%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FGGtZDY32hjfEYT3t4K0p&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fapi%2Fimage%2FGGtZDY32hjfEYT3t4K0p&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/11db28f0559a2404df5e11bd95f1f799/href">https://medium.com/media/11db28f0559a2404df5e11bd95f1f799/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/563258148eca6c21a9805d8d9afe6311/href">https://medium.com/media/563258148eca6c21a9805d8d9afe6311/href</a></iframe><p>From Figure 8 above, it can be observed that cluster value 3 covers the most recent customers whereas 0 has the most inactive customers.</p><p>In the next subsections, I apply the method we have discussed in this subsection for the Frequency and Revenue features.</p><p><strong>Frequency</strong></p><p>So as earlier mentioned, in a particular frame of time, if we consider the number of times a customer has engaged in a purchasing transaction, frequency comes into play. Now, this frequency characteristic is that which helps us know a customers alliance to a specific company or trading brand. In view of this, it gives the company insight into the marketing strategies to relay and at what points in time, in order to reach out to such customers in particular.</p><p>Here, I conduct a similar procedure of analysis as I did in the previous subsection (<strong>Recency</strong>).</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FEh7heA9iDg0yTrsCulAg%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FEh7heA9iDg0yTrsCulAg&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fapi%2Fimage%2FEh7heA9iDg0yTrsCulAg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d02b195d3bbc1af51e381c1fee19d56b/href">https://medium.com/media/d02b195d3bbc1af51e381c1fee19d56b/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c7a038eb1b9a2c5848a07f9ca0e6f90/href">https://medium.com/media/4c7a038eb1b9a2c5848a07f9ca0e6f90/href</a></iframe><p>Figure 10 below illustrates the histogram of customers whose purchase frequency is less than 1200.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Zyp3lxgAalsCjP6fG18PQ.png" /><figcaption>Figure 10: Histogram of customers with purchase frequency less than 1200 — Image by <a href="https://eocansey.medium.com/">Author</a>.</figcaption></figure><p>The code snippet below assigns a cluster value for the purchase frequency of each customer and sorts the cluster values in decreasing order.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FaFCLpok27kGusPFv2rZR%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FaFCLpok27kGusPFv2rZR&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8e1d87f6b7d0d002bff237927c2c12a/href">https://medium.com/media/a8e1d87f6b7d0d002bff237927c2c12a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9de08490759375de92c7f8dfac3bb39/href">https://medium.com/media/f9de08490759375de92c7f8dfac3bb39/href</a></iframe><p>The code snippet below groups the dataframe ctm_dt by the cluster values recorded in the column labelled <strong>FrequencyCluster</strong> and fetches out the statistical description of the <strong>Frequency</strong> data of each of these <strong>FrequencyCluster</strong> values.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2F2JPbm1wWNyNNYyCCy4ZB%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F2JPbm1wWNyNNYyCCy4ZB&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdde4596e1d900579e5ef60140ecf0a4/href">https://medium.com/media/cdde4596e1d900579e5ef60140ecf0a4/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72679ba10412cf6dd725ea5d6f36a581/href">https://medium.com/media/72679ba10412cf6dd725ea5d6f36a581/href</a></iframe><p>As it was for the case of the Recency, customers with a higher frequency cluster value are better customers. In other words, they patronise the products of the retail shop very often than those with a lower frequency cluster value.</p><p><strong>Monetary Value/Revenue</strong></p><p>To give a little more detail to Monetary Value or revenue, it centres more on the money a customer spends when in for a purchase at any point in time. So here it helps to ascertain how much money a customer is likely to let out when making a purchase. Even though this feature of revenue does not expose one to predict when next there will be a purchase from the customer, knowing how much could come in when the customer comes through for a transaction is worth knowing.</p><p>I again follow a similar procedure to obtain a revenue score for each customer and assign cluster values for each customer based on their revenue score.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FSVmH8NVENZE1aAyCkt39%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FSVmH8NVENZE1aAyCkt39&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fapi%2Fimage%2FSVmH8NVENZE1aAyCkt39&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/afc471b119e5855b523cacc73fdae9e8/href">https://medium.com/media/afc471b119e5855b523cacc73fdae9e8/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/877b7b6bd2ba32a2b6a1e1dc83b5de22/href">https://medium.com/media/877b7b6bd2ba32a2b6a1e1dc83b5de22/href</a></iframe><p>The figure below illustrates a visual representation of customers whose revenue is below £10,000.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WQKkBrux5eFrACovA7mo4Q.png" /><figcaption>Figure 14: Histogram of customers with a monetary value below £10000 — Image by <a href="https://eocansey.medium.com/">Author</a>.</figcaption></figure><p>The code snippet below assigns a cluster value for the revenue of each customer and sorts the cluster values in ascending order.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2F8Qu5z6VeEkvwAlh51dpj%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F8Qu5z6VeEkvwAlh51dpj&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/901ec36b5de1f0ce752f2471fe220172/href">https://medium.com/media/901ec36b5de1f0ce752f2471fe220172/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1637f2c6600799ca5786745d64e6eba9/href">https://medium.com/media/1637f2c6600799ca5786745d64e6eba9/href</a></iframe><p><strong>Overall Score</strong></p><p>In the code snippet below, I add a new column <strong>OverallScore</strong> to the dataframe ctm_dt with values as the sum of the cluster values obtained for the Recency, Frequency and Revenue.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FS4f5mSNjVrjlfA2Azj69%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FS4f5mSNjVrjlfA2Azj69&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b089bbe24de5368f97c2abbcc617f4e/href">https://medium.com/media/3b089bbe24de5368f97c2abbcc617f4e/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37c15000d4824edfaf6d264b5384d830/href">https://medium.com/media/37c15000d4824edfaf6d264b5384d830/href</a></iframe><p>The scoring above clearly shows us that customers with an overall score of 8 are the positively outstanding customers who bring much value to the company whereas those assigned a score of 3 are supposedly unreliable and merely wandering.</p><p>As a follow-up, I group the customers into the segments based on their overall score as follows:</p><ul><li>3 to 4: Low Value</li><li>5 to 6: Mid Value</li><li>7 to 8: High Value</li></ul><p>The code snippet is as follows:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FcGXPlayitjrQ8jvPxa1o%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FcGXPlayitjrQ8jvPxa1o&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b3fc41a3d0b8ec472f967a384f80666/href">https://medium.com/media/0b3fc41a3d0b8ec472f967a384f80666/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1edb4669c59f9e4b21b1213d63b6c22/href">https://medium.com/media/d1edb4669c59f9e4b21b1213d63b6c22/href</a></iframe><p>I then create a copy of the dataset ctm_dt and apply the method get_dummies to it so as to convert all categorical column <strong>Segment</strong> to indicator variables.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FjqzAz43DzOrqc995cPkI%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FjqzAz43DzOrqc995cPkI&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e35de23b362feecc758a5b9872b7288/href">https://medium.com/media/1e35de23b362feecc758a5b9872b7288/href</a></iframe><p>In pursuance of my goal to estimate whether a customer will make a purchase in the next quarter, I create a new column <strong>NextPurchaseDayRange</strong> with values as either 1 or 0 defined as follows:</p><ul><li>If the value is 1, then it indicates that the customer will buy something in the next quarter, i.e., 90 days from his or her last purchase.</li><li>The value 0 indicates that the customer will buy something in more than 90 days from his or her last purchase.</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FSgNhBNixyNDCV0l1EUVg%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FSgNhBNixyNDCV0l1EUVg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6105f483587dc16c093f61dc2b1b0e0b/href">https://medium.com/media/6105f483587dc16c093f61dc2b1b0e0b/href</a></iframe><p>I conclude this section by computing the correlation between our features and label. I achieve this by applying the corr method to the dataframe ctm_class.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2Ff4EPTkfCfi8DHmj0o3iD%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2Ff4EPTkfCfi8DHmj0o3iD&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9a558bfbdab2a2e79d8b9abfbbc100f/href">https://medium.com/media/f9a558bfbdab2a2e79d8b9abfbbc100f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f8f5088fab16f9319a00a7f51877699/href">https://medium.com/media/9f8f5088fab16f9319a00a7f51877699/href</a></iframe><p>From Figure 18 above, it can be seen that <strong>OverallScore</strong> has the highest positive correlation of 0.97 with <strong>RecencyCluster</strong> and <strong>Segment_Low-Value</strong> has the highest negative of -0.99 with <strong>Segment_Mid-Value</strong>.</p><p>In Figure 19 below, I present a good visualisation of the coefficient matrix. The code snippet is below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FTbHKu8fRmz4qdsLEVsSt%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FTbHKu8fRmz4qdsLEVsSt&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3b5d603c353b720667f336bc1430dc3/href">https://medium.com/media/b3b5d603c353b720667f336bc1430dc3/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YmGBJjP3Lpw4c_LZPYvydw.png" /><figcaption>Figure 19: Correlation Matrix — Image by <a href="https://eocansey.medium.com/">Author</a>.</figcaption></figure><h4>Building Machine Learning Models</h4><p>In this section, I have what it takes with regard to the necessary prerequisites to build the machine learning model. The code snippet below separates the dataframe ctm_class into <strong>X</strong> features and the target variable <strong>y</strong>. Afterwards, I split <strong>X</strong> and <strong>y</strong> to get the training and test datasets and then measure the accuracy, F₁-score, recall, and precision of the different models.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FO9hbWoYRSUdPp22lwFfh%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FO9hbWoYRSUdPp22lwFfh&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/275db7f60daa75f99fade6bb0ef75d73/href">https://medium.com/media/275db7f60daa75f99fade6bb0ef75d73/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de320e5bab88ebb1249ba19dac9d982d/href">https://medium.com/media/de320e5bab88ebb1249ba19dac9d982d/href</a></iframe><p>From the results in Figure 20 above, we see that the LogisticRegression model is the best in terms of the metrics accuracy and F₁-score.</p><p>Let’s see how an improvement can be made for the existing model XGB Classifier which ranks fourth in Figure 20 above, by finding suitable parameters to control the learning process of the model. This process is called <em>hyperparameter tuning</em>. I then verify using the computation below to know if the improved XGB Classifier model outperforms the LogisticRegression model.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FfzBno63PaKq8HkDVKvS8%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FfzBno63PaKq8HkDVKvS8&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fapi%2Fimage%2FfzBno63PaKq8HkDVKvS8&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b377a63e9e13d241a222487b1240bd7/href">https://medium.com/media/3b377a63e9e13d241a222487b1240bd7/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c68b1c3c381e941c1c6ff6af2d5dfc4e/href">https://medium.com/media/c68b1c3c381e941c1c6ff6af2d5dfc4e/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FR6fft3XHgdUbYVWt3V6Q%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FR6fft3XHgdUbYVWt3V6Q&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/99a6aed431f53c6971cbf779564e1947/href">https://medium.com/media/99a6aed431f53c6971cbf779564e1947/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e0f0ece0cdefa2cca9684659bf13edd/href">https://medium.com/media/5e0f0ece0cdefa2cca9684659bf13edd/href</a></iframe><h4>Selecting Model</h4><p>Comparing the accuracy of the LogisticsRegression in Figures 20 above and that of the refined XGB classifier in Figure 22 above, it is obvious that the refined XGB classifier model is accurate than the LogisticRegression model by a margin of 0.1. How about the other metrics?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FotheF83lmGqgwAJGSljg%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FotheF83lmGqgwAJGSljg&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fapi%2Fimage%2FotheF83lmGqgwAJGSljg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3de0d3efd1878aae4cb39c8f8bd5b2e/href">https://medium.com/media/e3de0d3efd1878aae4cb39c8f8bd5b2e/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d06cc92ff11327145d421f1f00aee9a4/href">https://medium.com/media/d06cc92ff11327145d421f1f00aee9a4/href</a></iframe><p>It is obvious from the output in Figure 23 above that for each metric, accuracy, F₁-score, recall, and precision, the refined XGB classifier model outperforms the LogisticRegression model.</p><p>In forecasting the expectancy of a customer to make another purchase at the online retail shop after 90 days of one’s last purchase, there is the need to be accurate in our submission. As a result, I am interested in the model which gives the highest accuracy possible in making this pre-emption. Thus it is the best of options to make a choice to use the improved XGB classifier model over the LogisticRegression model.</p><h3>Conclusion</h3><p>From the dataset, I highlight the fact that the strong customer base of the online shop centred in the United Kingdom is a major reason for the high revenue the company profits from the United Kingdom as a region.</p><p>I also give a detailed demonstration of how to build a machine learning model to predict whether an online customer of the retail shop will make their next purchase 90 days from the day they made their last purchase. Among the models that I used, I had to further improve on the XGB classifier model by the process of hyperparameter tuning to outperform the LogisticRegression model. The initial metrics after the hyperparameter tuning of the XGB classifier model max_depthand min_child_weight both set to 3, did not outperform that of the LogisticRegression. So I had to further tweak these values heuristically in order to get the XGB classifier model to outperform the LogisticRegression model.</p><p>The above notwithstanding, it will be interesting to investigate with further work how one can again improve the model’s accuracy and F₁-score metrics. I suggest improving the dataset by introducing the “right” X features so as to avoid the usage of a hyperparameter tuning process. So then my question now stands that</p><blockquote>What X-features would be appropriate to introduce into the dataset to reach or increase the model’s hightened accuracy and F₁-score metrics without hyperparameter tuning?</blockquote><p>The Jupyter notebook used for this article is available <a href="https://github.com/evansdoe/online_retail/blob/main/online_retail.ipynb">here</a>.</p><h4>Reference</h4><p>[1] <a href="https://medium.com/@karamanbk">Barış Karaman</a>. (Accessed on April 28, 2021) <a href="https://towardsdatascience.com/predicting-next-purchase-day-15fae5548027">Predicting Next Purchase Day</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7895ad49b4db" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/using-machine-learning-to-predict-customers-next-purchase-day-7895ad49b4db">Using Machine Learning to Predict Customers Next Purchase Day</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[Which Database Environments are of interest to developers in 2021?]]></title>
            <link>https://medium.com/data-science/which-database-environments-are-of-interest-to-developers-in-2021-7482f718f47a?source=rss-2617ca03887d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7482f718f47a</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Evans Doe Ocansey]]></dc:creator>
            <pubDate>Mon, 01 Mar 2021 09:20:42 GMT</pubDate>
            <atom:updated>2021-03-03T13:17:34.726Z</atom:updated>
            <content:encoded><![CDATA[<h4>An analysis of the expected usage of database environments by developers in 2021</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*zjHW-EJvux7_eYn1bI-3_g.png" /><figcaption>Word Cloud of DBMS Usage Count in 2021 — Image by Author</figcaption></figure><h3>Introduction</h3><p>In recent years, the world has seen a rise in the usage of artificial intelligence both in industry and for research. Undoubtedly, the increased relevance for artificial intelligence has resulted in a demand for experts from diverse areas of artificial intelligence applicability. These expert demand areas include Software Developers, Machine Learning Engineers, Data Scientist, and Database Administrators. Further, the mentioned expert fields of work demand technical know-how in areas like computer programming, database management systems, statistics, and matrix algebra, which is imperative. In this article, I focus only on the usage of database management systems. More precisely, I make known the database environments expected to be popular among software developers in 2021.</p><p>In revealing how database environments are expected to be popular, I use the <a href="https://drive.google.com/file/d/1dfGerWeWkcyQ9GX9x20rdSGj7WtEpzBB/view?usp=sharing">Stack Overflow Annual Developer Survey datasets for the year 2020</a>. My reason for using these datasets is because, over the past decade, the Stack Overflow Annual Developer Survey has emerged as the world largest and most trusted community of professional software developers. Thus, it will be necessary to know what these software developers are saying concerning the database environments expected to be popular among software developers in 2021.</p><p>The conducted survey had 64,461 respondents from 182 countries and territories. The survey questions were grouped into the following sections: Basic Information, Education, Work and Career, Tech and tech culture, Stack Overflow Usage and Community and Demographics. There were 61 questions posed in the survey. Some of the questions include:</p><blockquote>Where do you live?</blockquote><blockquote>Which collaboration tools have you done extensive development work in over the past year, and which do you want to work in over the next year? (If you worked with the tool and want to continue to do so, please check both boxes in that row.)</blockquote><p>But the question I am most interested in is</p><blockquote>Which database environments have you done extensive development work in over the past year, and which do you want to work in over the next year? (If you both worked with the database and want to continue to do so, please check both boxes in that row.)</blockquote><h3>Distribution of the survey respondents according to countries and continents</h3><p>Before answering the question of interest, I want to understand</p><blockquote>How does the distribution of the respondents in the survey correspond to their countries (resp. continents) and whether the distribution well represents the population of the countries (resp. continents)?</blockquote><p>In the first subsection (Distribution of the survey respondents according to countries), I present my findings based on the countries of the survey respondents. The findings that correspond to the continents where the respondents are based are given in the second subsection (Distribution of the survey respondents according to countries).</p><h4>Distribution of the survey respondents according to countries</h4><p>In this subsection, I will present my findings to the question below.</p><blockquote>How does the distribution of the survey respondents correspond to their countries?</blockquote><p>The part of the dataset used to answer this question was the <em>Country </em>column which asked respondents where they were living?</p><p>Figure 1 below shows the percentage of the survey respondents based on their country of abode in descending order. One can see that the United States records 19.46% as the highest number of survey respondents. The next four countries in descending order are India, the United Kingdom, Germany and Canada recording, 13.11%, 6.08 %, 6.07%, and 3.42%, respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*UUonHbvApHsVba8vAAuwYQ.png" /><figcaption>Figure 1: Survey Respondent Counts and Percentage According to Countries (Only countries with at least 1% of respondents are shown) — Image by Author</figcaption></figure><p>A follow-up question is posed to find out how the distribution of the survey respondents corresponds to their countries of dwelling. This is by knowing</p><blockquote>How well does the countries with the highest number of respondents represent their respective country population?</blockquote><p>To answer the above question, I introduce a new quantity called <em>Respondent Density</em> which measures the density of the respondents given the population of their respective countries. Precisely, it is given by the formula below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*hPa4j4nBmK8nX17v-Wkcvw.png" /><figcaption>Figure 2: Respondent Density Formula — Image by Author</figcaption></figure><p>I use the <a href="https://www.kaggle.com/tanuprabhu/population-by-country-2020">2020 population dataset</a> provided by <a href="https://www.kaggle.com/tanuprabhu">Tanu N Prabhu</a> to get the population of the countries represented in the Stack Overflow Annual Survey dataset.</p><p>The visualisation of the results of my analysis is presented in Figure 3 below. From it, one can see that Sweden, the Netherlands, Israel, Canada, and the United Kingdom are interestingly the top five countries based on the respondents’ density measure. Thus, one can say that the number of survey respondents from these countries represents their country population well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*USnZ2XiQVUdHDG3Cw_ejbw.png" /><figcaption>Figure 3: Survey Respondents in Percentage and Respondent Density of Countries of Respondents (Only countries with at least 1% of respondents are shown) — Image by Author</figcaption></figure><p>On the other hand, the United States, although recorded 19.46% of the survey respondents, ranked in the 8th position by the respondents’ density measure. India which recorded 13.11% of the survey respondents ranked in the 16th position by the respondents’ density measure. In these two countries, one can assume that the software developers there did not show much interest in the survey. One could also say that from the result represented for these two countries, there were not many software developers to give a good significant representation of their respective countries in this survey. Although these could be intelligent guesses, it will be of interest to know a concise reason for the result I have. Probably in conducting further research to have a concrete answer as to why this is the obvious case I have would be the way out.</p><h4>Distribution of the survey respondents according to continents</h4><p>In this subsection, I present the findings of my analysis to a possible follow-up question discussed in the previous subsection. Namely,</p><blockquote>Which continent has the highest number of respondents?</blockquote><p>I used the <a href="https://www.kaggle.com/statchaitya/country-to-continent">country continent dataset</a> created by <a href="https://www.kaggle.com/statchaitya">Chaitanya Gokhale</a> to group the countries of the survey respondents into their respective continents.</p><p>The results of the findings are given in Figure 4 below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*6vOA2u4Krmz2K_tOAtsTWw.png" /><figcaption>Figure 4: Survey Respondent Counts and Percentages According to Continents — Image by Author</figcaption></figure><p>From Figure 4 above, one can see that the continent with the highest number of respondents of the survey is the European continent with 38.5%, followed by the Americas, Asia, Africa, and Oceania recording 29.08%, 25.59%, 4.21% and 2.44%, respectively.</p><p>In the same vein as the second question posed in the previous subsection, I introduce the <em>Respondent Density</em> measure, restricting it to the population of the various continents of the survey respondents. The question of interest here is as follows:</p><blockquote>How well does the results of the previous question represent the continent of the survey respondents?</blockquote><p>From Figure 5 below, one can see that the Oceania continent has the highest respondent density. Thus, the respondents from this continent expressed more interest in the survey than those from the other surveyed continents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*hBYZarPxiNnwSorhecglTQ.png" /><figcaption>Figure 5: Survey Respondent Percentage and Respondent Density of Continents — Image by Author</figcaption></figure><h3>Survey Respondents Usage of Database Environments</h3><p>In this section, I present my findings for the main questions of interest below:</p><blockquote>Which database environments have you done extensive development work in over the past year, and which do you want to work in over the next year? (If you both worked with the database and want to continue to do so, please check both boxes in that row.)</blockquote><p>In the survey dataset, the same question is posed for the columns labelled <em>DatabaseWorkedWith </em>and <em>DatabaseDesireNextYear. </em>The responses of the survey respondents show that on a worldwide scale, there are 14 different database management systems (DBMS) popular among software developers. These include:</p><p><a href="https://cassandra.apache.org/">Cassandra</a><br><a href="https://www.couchbase.com/">Couchbase</a><br><a href="https://aws.amazon.com/dynamodb/">DynamoDB</a><br><a href="https://www.elastic.co/">Elasticsearch</a><br><a href="https://firebase.google.com/">Firebase</a><br><a href="https://www.ibm.com/products/db2-database">IBM DB2<br></a><a href="https://mariadb.org/">MariaDB</a><br><a href="https://www.microsoft.com/en-au/sql-server/sql-server-downloads">Microsoft SQL Server<br></a><a href="https://www.mongodb.com/">MongoDB</a><br><a href="https://www.mysql.com/">MySQL</a><br><a href="https://www.oracle.com/database/">Oracle</a><br><a href="https://www.postgresql.org/">PostgreSQL</a><br><a href="https://redis.io/">Redis</a><br><a href="https://www.sqlite.org/index.html">SQLite</a></p><p>The rest of this section is put into two subsections. In the first subsection (Survey Respondents Usage of Database Environments in 2020), I present my findings on the question of interest up until the year 2020, and the second subsection focuses on findings for the year 2021.</p><h4>Survey Respondents Usage of Database Environments in 2020</h4><p>In this section, I present my findings of the question of interest for the column labelled <em>DatabaseWorkedWith. </em>In this column, the survey respondents were required to indicate the database environments they have done extensive development work in up until the year 2020. In other words, I am interested in the following question.</p><blockquote>What are the database environments that is most popular among the survey respondents?</blockquote><p>Figure 6 below shows the usage of the various DBMS among all the survey respondents up until the end of the year 2020.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*ZpeZLRgx6rrcJj_8pLuF5Q.png" /><figcaption>Figure 6: Survey Respondents Percentage Usage of Database Environments up until the end of 2020 — Image by Author</figcaption></figure><p>From Figure 6 above, one can see that the top five popular database environments that the respondents have done extensive development work in over the past year, i.e., until the end of the year 2020, are</p><p><a href="https://www.mysql.com/"><strong>MySQL</strong></a><strong> </strong>— 20.07%<br><a href="https://www.postgresql.org/"><strong>PostgreSQL</strong></a><strong> </strong>— 13.03%<strong> </strong><br><a href="https://www.microsoft.com/en-au/sql-server/sql-server-downloads"><strong>Microsoft SQL Server</strong></a><strong> </strong>— 11.90%<br><a href="https://www.sqlite.org/index.html"><strong>SQLite</strong></a><strong> </strong>— 11.24%<br><a href="https://www.mongodb.com/"><strong>MongoDB</strong></a><strong> </strong>— 9.53%</p><p>It is interesting to know that although <strong>MongoDB</strong> is among the new creations to the database community in recent times as compared to other database environments like <strong>Oracle DBMS</strong>, it has risen to the top five DBMS among the survey respondents. In the next subsection, I will explore to know how popular <strong>MongoDB </strong>is likely to be in 2021.</p><p>Further in Figure 7 below, one can see how these top five DBMS are ranked in the most represented countries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*jl07wXURUNR8Qdd22SKVUA.png" /><figcaption>Figure 7: Percentage Usage of the Top Five DBMS in the Top Countries in 2020 — Image by Author</figcaption></figure><p>From Figure 7 above, <strong>MySQL</strong> continues to be the most extensively used database environments in the top countries, except for the Russian Federation, where <strong>PostgreSQL</strong> is ranked first and its competitor, <strong>MySQL</strong> is ranked second. One can also see that <strong>MySQL</strong> is used extensively in Pakistan, India and Italy.</p><p>In all these countries, there is competition among at least two of the top five DBMS. Poland is the only country where <strong>MySQL</strong> has a competitor. Its competitor is <strong>PostgreSQL</strong>. In the United States, India, the Netherlands, Australia and Italy there is a competition between the usage of <strong>PostgreSQL</strong> and <strong>Microsoft SQL Server</strong>. <strong>MongoDB</strong> is ranked second in Israel and competes with <strong>SQLite</strong> in Canada and France.</p><h4>Survey Respondents Usage of Database Environments in 2021</h4><p>Finally, I present my findings based on the answers survey respondents gave in the column labelled <em>DatabaseDesireNextYear </em>of the dataset. The question of interest here was</p><blockquote>Which database environments would respondents want to be working in over the next year, i.e., in the year 2021?</blockquote><p>Figure 8 below shows the expected ranking of the usage of DBMS in 2021.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*NciMCE90r5KX6Huk0xXcvQ.png" /><figcaption>Figure 8: Survey Respondents Percentage Usage of Database Environments up until the end of 2021 — Image by Author</figcaption></figure><p>From Figure 8 above, the top five database environments that are expected to be popular among software developers in 2021 are:</p><p><a href="https://www.postgresql.org/"><strong>PostgreSQL</strong></a> — 14.30%<br><a href="https://www.mongodb.com/"><strong>MongoDB</strong></a><strong> </strong>— 12.96%<strong> </strong><br><a href="https://www.mysql.com/"><strong>MySQL</strong></a><strong> </strong>— 12.73%<br><a href="https://redis.io/"><strong>Redis</strong></a><strong> </strong>— 9.69%<br><a href="https://www.sqlite.org/index.html"><strong>SQLite</strong></a><strong> </strong>— 8.83%</p><p>Comparing the results for 2021 as seen here with what was discovered in the previous subsection which showed the year 2020 figures, one can see that <strong>PostgreSQL</strong> has a high likelihood of being popular in 2021 among respondents from all over the world. This conclusion is made for reason that, its usage is expected to increase by 1.27%. Thus moving upwards to take first place with a ranking of 14.30% from its year 2020 second rank after recording 13.03%.</p><p>The next is <strong>MongoDB</strong> which makes an impressive move upwards from the fifth position in the year 2020 to second place in 2021 by a margin of 3.43%. This is quite good progress to be made. A possible question to explore could also be whether <strong>MongoDB</strong> will be the most popular database environment among respondents worldwide in the coming years considering its mark of three places up in just a year gap, that is for the years 2020 and 2021.</p><p><strong>MySQL</strong> decreased by a margin of 7.36% from the first position in 2020 to the third position in 2021. Thus, on a worldwide scale, there is a high likelihood that <strong>MySQL</strong> will be less popular among the respondents in 2021.</p><p>The next is <strong>Redis</strong> which ranked sixth among the respondents in 2020. It increased by a margin of 3.09% to be ranked as the fourth DBMS expected to be popular in 2021 among software developers on a worldwide scale. It falls in second place after <strong>MongoBD</strong> with quite a huge jump expected to gain popularity in 2021 as well.</p><p>Finally, <strong>SQLite</strong> decreased by a margin of 2.41%, falling from the fourth position in the year 2020 to the fifth position in the year 2021. It is also seen as the DBMS losing popularity on a worldwide scale among the survey respondents.</p><p>It becomes evident from the results that on a worldwide scale, <strong>Microsoft SQL Server</strong> has a high likelihood of not being popular among the survey respondents. I make this conclusion for the reason that Microsoft SQL Server falls<strong> </strong>from the third position in 2020 to the seventh position in 2021 by a margin of 3.91%.</p><p>Figure 9 shows the findings to the same question restricting to the countries that were most represented in the survey.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*t0AFPCmyPkPTsurPc1nkBA.png" /><figcaption>Figure 9: Percentage Usage of the Top Five DBMS in the Top Countries in 2021 — Image by Author</figcaption></figure><p>Comparing Figure 9 above with that of Figure 7, one can observe that <strong>PostgreSQL</strong> is still going to be popular in the year 2021 in the Russian Federation. The popularity of PostgreSQL can also be predicted for the United States, the United Kingdom, Germany, Canada, France, Brazil, the Netherlands, Poland, Australia, Sweden and Turkey. That is, there is a high likelihood that <strong>PostgreSQL</strong> will be popular among the respondents from these countries in the year 2021.</p><p><strong>MongoDB </strong>is expected to be the most popular DBMS in the year 2021 among the respondents in India, Spain, Pakistan, and Israel. In Turkey, Brazil, Spain and Italy, <strong>MongoBD</strong> competes with <strong>PostgreSQL</strong>. An exception is made in India and Pakistan where one can see that <strong>MongoDB</strong> is rather in competition with <strong>MySQL.</strong></p><p>Interestingly, Italy is the only country where <strong>MySQL </strong>is expected to maintain its popularity in 2021. Comparing the differences between <strong>MySQL</strong> and <strong>PostgreSQL</strong>, and <strong>MySQL</strong> and <strong>MongoDB</strong> for the years 2020 and 2021, one can say that, in Italy, it possible that the close competitors of <strong>MySQL</strong>, namely <strong>PostgreSQL</strong> and <strong>MongoDB</strong> might take over in 2021.</p><h4>Conclusion</h4><p>Most of the respondents of the survey lived in one of the following countries: the United States, India, United Kingdom, Germany and Canada.</p><p>Using the respondents’ density measure, I observed that respondents from the following countries: Sweden, the Netherlands, Israel, Canada and the United Kingdom were most interested in the survey. That is, they represent their population fairly well. Although the United States and India have more respondents, the value for their respondents’ density indicated that they did not represent their population too well as expected.</p><p>On the continental level, Europe emerged as the continent with the highest number of respondents for the survey. On the other hand, Oceania was the only continent that was well represented based on the respondent density measure.</p><p>On a worldwide scale, <strong>MySQL</strong> stood out as the most popular database environment among the respondents up until the end of the year 2020. In spite of this record for the year 2020, there is a high likelihood that <strong>PostgreSQL </strong>will overtake <strong>MySQL </strong>in the year 2021.<strong> </strong>Also, there is a predictive rise in interest for <strong>MongoDB</strong> and <strong>Redis</strong> expected in the year 2021. The reason for the interest was not explored in this study. Nevertheless, it will be interesting to have knowledge of this cause. My result also reveals that <strong>Microsoft SQL Server</strong> is expected to be less popular among the survey respondents in 2021.</p><p>It is important to note that the findings in this study are observational and not thorough formal studies. Nevertheless, they lead to interesting business-oriented research questions which are directed not only to the software developers but also to companies who are producers of these database management systems. No matter the category you find yourself in, being either a software developer or a producer of a database management system, the question still remains:</p><blockquote>What database management system do YOU expect to be popular in the year 2021?</blockquote><p>For the technical details about these analyses and more, see the link to my Github available <a href="https://github.com/evansdoe/stackoverflow_2020_survey/blob/main/stackoverflow_2020_survey.ipynb">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7482f718f47a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/which-database-environments-are-of-interest-to-developers-in-2021-7482f718f47a">Which Database Environments are of interest to developers in 2021?</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>