<?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 Abdullah Orzan on Medium]]></title>
        <description><![CDATA[Stories by Abdullah Orzan on Medium]]></description>
        <link>https://medium.com/@abdullahorzan?source=rss-bc3e4b97ee50------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Onxe9LNVG8HsMJPXtGFgbw@2x.jpeg</url>
            <title>Stories by Abdullah Orzan on Medium</title>
            <link>https://medium.com/@abdullahorzan?source=rss-bc3e4b97ee50------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 20:12:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abdullahorzan/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[Data-Backed Decision Making: A/B Testing Techniques with Python]]></title>
            <link>https://medium.com/@abdullahorzan/data-backed-decision-making-a-b-testing-techniques-with-python-2599e80b29ac?source=rss-bc3e4b97ee50------2</link>
            <guid isPermaLink="false">https://medium.com/p/2599e80b29ac</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[a-b-testing]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Abdullah Orzan]]></dc:creator>
            <pubDate>Thu, 20 Jul 2023 09:43:57 GMT</pubDate>
            <atom:updated>2023-07-31T00:26:51.898Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_5SKFmZDQihIZZapX-Gejg.png" /></figure><p>A/B testing, or split testing, is a fundamental concept that examines the relationship between two distinct features or groups. In this approach, one part or group is represented by A, while a different feature or group is represented by B. The primary objective of A/B testing is to investigate and understand the impact of changes or variations on user behavior, engagement, or other relevant metrics. By conducting controlled experiments, researchers and analysts strive to gather statistically significant evidence that supports the decision-making process.</p><p>The process of A/B testing involves several key steps. First, a clear hypothesis is formulated, outlining the expected impact or difference between the A and B groups. Then, a controlled experiment is designed, ensuring that only one variable is modified between the groups while keeping other factors constant. The investigation is typically conducted over a specific period to gather sufficient data for analysis. Statistical analysis techniques, often implemented using programming languages such as Python, are applied to evaluate the results and determine the significance of observed differences.</p><p>We will conduct A/B Testing in three stages:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XT12Jhl2SG-kHVhSDDj_PA.png" /></figure><p>Multiple hypothesis testing approaches can be used for A/B testing. In our case, we will focus on the equality hypothesis, which examines whether there is a difference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PHewQr2HGIwFjDEkrjKOhQ.png" /><figcaption>Different types of testing approaches</figcaption></figure><h3>Two-Sample Independent T-Test</h3><p>The two-sample independent t-test is a statistical test commonly used in A/B testing scenarios to compare the means of two groups. This test assesses whether there is a significant difference between the average values of a specific variable in two distinct groups.</p><p>The first step in conducting a two-sample independent t-test involves formulating the null hypothesis, which assumes no significant difference between the means of the two groups. The alternative hypothesis, on the other hand, suggests that there is indeed a considerable difference.</p><p>We can determine the difference by calculating the t-statistic and comparing it to the critical values from the t-distribution. The resulting p-value indicates the probability of observing such a difference if the null hypothesis were true.</p><p>Suppose the p-value is below a pre-defined significance level (commonly 0.05). In that case, the null hypothesis is rejected, indicating strong evidence of a significant difference between the two groups.</p><h4>Assumptions of Two-Sample Independent T-Test</h4><p>The Two-Sample Independent T-Test has two assumptions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IEuIwo-0I29mHB9Ic0Ry3Q.png" /></figure><p>Here, we will formulate hypotheses regarding the assumptions. If the p-value &lt; 0.05, we will conclude that the assumptions are not met; if the p-value &gt; 0.05, we will say that the assumptions are satisfied.</p><p>We test the normality hypothesis using the Shapiro-Wilk test and the homogeneity of variances hypothesis using the Levene test.</p><p>The following flowchart shows the hypothesis testing for assumptions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aOGbQPWL1J--wuRCf9fbDA.png" /><figcaption>Two Sample Independent T-Test Assumptions Hypothesis Testing</figcaption></figure><p>Based on the validity of the assumptions, we apply two different significance tests:</p><ol><li><strong>Parametric Test: ttest</strong></li><li><strong>Non-Parametric Test: Mann-Whitney U Test</strong></li></ol><blockquote>If the normality assumption is not satisfied, we can directly apply the non-parametric test. If normality is satisfied and homogeneity of variances is also satisfied, we provide the “equal_var = True” argument in Python to the parametric test to specify the test type.</blockquote><blockquote>If normality is satisfied, but the homogeneity of variances is not satisfied, we provide the “equal_var = False” argument in Python to the parametric test.</blockquote><h4>Step by Step application with Python</h4><p>I will use Seaborn&#39;s ‘tips’ for the A/B testing Python application. You can find detailed information about all the columns of this dataset on the GitHub page linked below:</p><p><a href="https://github.com/mwaskom/seaborn-data/blob/master/tips.csv">seaborn-data/tips.csv at master · mwaskom/seaborn-data</a></p><pre>import pandas as pd<br>import seaborn as sns<br>import statsmodels.stats.api as sms<br>from scipy.stats import shapiro, levene, ttest_ind, mannwhitneyu<br><br>######################################################<br># Two-Sample Independent T-Test<br>######################################################<br><br># 1. Formulate Hypotheses<br># 2. Check Assumptions<br>#   - 1. Normality Assumption<br>#   - 2. Variance Homogeneity Assumption<br># 3. Apply Hypothesis<br>#   - 1. If assumptions are satisfied: the parametric test<br>#   - 2. If assumptions are not satisfied: non-parametric test (Mann-Whitney U Test)<br># 4. Examine results based on the p-value<br># Important:<br># - If normality is not satisfied, we can directly apply the Mann-Whitney U Test. If variance homogeneity is not satisfied, we add an equal_var parameter.<br># - It can be beneficial to perform outlier detection and correction before conducting the normality assessment<br><br><br>############################<br># Experiment: Is there a statistically significant difference in the mean bills between smokers and non-smokers?&quot;<br>############################<br><br><br>df = sns.load_dataset(&quot;tips&quot;)<br>df.head()<br><br>df.groupby(&quot;smoker&quot;).agg({&quot;total_bill&quot;: &quot;mean&quot;})<br><br>############################<br># 1. Formulate the hypothesis<br>############################<br><br># H0: M1 = M2<br># H1: M1 != M2<br><br>############################<br># 2. Assumption Checking<br>############################<br><br># Normality Assumption<br># Variance Homogeneity Assumption<br><br>############################<br># Normality Assumption<br>############################<br><br># H0: The assumption of the normal distribution is satisfied<br># H1:.. is not satisfied.<br><br><br>test_stat, pvalue = shapiro(df.loc[df[&quot;smoker&quot;] == &quot;Yes&quot;, &quot;total_bill&quot;])<br>print(&#39;Test Stat = %.4f, p-value = %.4f&#39; % (test_stat, pvalue))<br><br># if p-value &lt; 0.05 H0 REJECT<br># if p-value &gt; 0.05 H0 FAIL TO REJECT<br><br><br>test_stat, pvalue = shapiro(df.loc[df[&quot;smoker&quot;] == &quot;No&quot;, &quot;total_bill&quot;])<br>print(&#39;Test Stat = %.4f, p-value = %.4f&#39; % (test_stat, pvalue))<br><br><br>############################<br># Variance Homogeneity Assumption<br>############################<br><br># H0: The variances are homogeneous<br># H1: The variances are not homogeneous<br><br>test_stat, pvalue = levene(df.loc[df[&quot;smoker&quot;] == &quot;Yes&quot;, &quot;total_bill&quot;],<br>                           df.loc[df[&quot;smoker&quot;] == &quot;No&quot;, &quot;total_bill&quot;])<br>print(&#39;Test Stat = %.4f, p-value = %.4f&#39; % (test_stat, pvalue))<br><br># if p-value &lt; 0.05 H0 REJECT<br># if p-value &gt; 0.05 H0 FAIL TO REJECT<br><br>############################<br># 3 ve 4. Application of the Hypothesis<br>############################<br><br># 1. If the assumptions are satisfied, the two-sample independent t-test is applied (parametric test)<br># 2. If the assumptions are not satisfied, the Mann-Whitney U test is used (non-parametric test)<br><br>############################<br># 1.1 If the assumptions are met, the two-sample independent t-test is conducted (parametric test)<br>############################<br><br>test_stat, pvalue = ttest_ind(df.loc[df[&quot;smoker&quot;] == &quot;Yes&quot;, &quot;total_bill&quot;],<br>                              df.loc[df[&quot;smoker&quot;] == &quot;No&quot;, &quot;total_bill&quot;],<br>                              equal_var=True)<br><br>print(&#39;Test Stat = %.4f, p-value = %.4f&#39; % (test_stat, pvalue))<br><br># if p-value &lt; 0.05 H0 REJECT<br># if p-value &gt; 0.05 H0 FAIL TO REJECT<br><br>############################<br># 1.2 If the assumptions are not met, the Mann-Whitney U test is conducted (non-parametric test)<br>############################<br><br>test_stat, pvalue = mannwhitneyu(df.loc[df[&quot;smoker&quot;] == &quot;Yes&quot;, &quot;total_bill&quot;],<br>                                 df.loc[df[&quot;smoker&quot;] == &quot;No&quot;, &quot;total_bill&quot;])<br><br>print(&#39;Test Stat = %.4f, p-value = %.4f&#39; % (test_stat, pvalue))</pre><p>After examining the p-value obtained from the Two-Sample Independent T-Test, we determine whether to reject or fail to reject our hypothesis. With this final step, we conclude the testing process.</p><h3>Two Independent Proportions Test</h3><p>Previously, we compared the means between the two groups. Now, to reach two proportions, we will use the proportion test.</p><p>The Two Independent Proportions test is a statistical test used to compare the proportions of two independent groups or samples. This test examines whether a significant difference exists between the proportions of a specific characteristic or outcome in each group. The test is typically applied when the data consists of categorical variables or binary results. The first step in conducting the Two Independent Proportions test involves formulating the null hypothesis, which assumes no significant difference in the proportions between the two groups. The alternative theory, on the other hand, suggests that there is indeed a considerable difference.</p><h4>Assumption of Two Independent Proportions Test</h4><p>This test assumes that the sample size (n) should exceed 30. We typically have many samples in data science studies, so this assumption will already be valid for our analysis.</p><h4>Step by Step application with Python</h4><p>I will use the well-known ‘titanic’ dataset available in Seaborn. You can find detailed information about all the columns of this dataset on the GitHub page linked below:</p><p><a href="https://github.com/mwaskom/seaborn-data/blob/master/titanic.csv">seaborn-data/titanic.csv at master · mwaskom/seaborn-data</a></p><pre>import seaborn as sns<br>import numpy as np<br>import pandas as pd<br>from statsmodels.stats.proportion import proportions_ztest<br><br>######################################################<br># Two Independent Proportions Test<br>######################################################<br><br># When applying this test, we input the total number of successes and the total number of observations<br># as separate numpy arrays in the function, respectively.<br><br>############################<br># Example                                       <br>############################<br><br>total_num_of_success = np.array([300, 250])<br>total_num_of_observations = np.array([1000, 1100])<br><br>proportions_ztest(count=total_num_of_success, nobs=total_num_of_observations)<br><br><br>############################<br># Application: Is there a statistically significant difference in the survival rates between males and females?<br>############################<br><br># H0: p1 = p2<br># There is no statistically significant difference in the survival rates between males and females<br><br># H1: p1 != p2<br># .. there is a statistically significant difference<br><br>df = sns.load_dataset(&quot;titanic&quot;)<br>df.head()<br><br>df.loc[df[&quot;sex&quot;] == &quot;female&quot;, &quot;survived&quot;].mean()<br><br>df.loc[df[&quot;sex&quot;] == &quot;male&quot;, &quot;survived&quot;].mean()<br><br># The sum of the survivors gives us the total number of successes<br>female_succ_count = df.loc[df[&quot;sex&quot;] == &quot;female&quot;, &quot;survived&quot;].sum()<br>male_succ_count = df.loc[df[&quot;sex&quot;] == &quot;male&quot;, &quot;survived&quot;].sum()<br><br># To obtain the total number of observations, we apply filtering and<br># then retrieve the row count, which provides us with the total number of observations that meet the condition within the variable<br>test_stat, pvalue = proportions_ztest(count=[female_succ_count, male_succ_count],<br>                                      nobs=[df.loc[df[&quot;sex&quot;] == &quot;female&quot;, &quot;survived&quot;].shape[0],<br>                                            df.loc[df[&quot;sex&quot;] == &quot;male&quot;, &quot;survived&quot;].shape[0]])<br><br>print(&#39;Test Stat = %.4f, p-value = %.4f&#39; % (test_stat, pvalue))</pre><h3>ANOVA (Analysis of Variance)</h3><p>The topic of variance analysis is a comprehensive subject that requires a dedicated course at the undergraduate level and encompasses a wide range of areas. Here, we will only be addressing it within the framework of A/B testing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*UolmB6KIJbjyss6jwMsxdw.png" /><figcaption>H0 Hypothesis for ANOVA</figcaption></figure><p>ANOVA (Analysis of Variance) is a statistical technique used to compare the means of three or more groups or treatments. It is a powerful tool that helps identify whether there are significant differences among the means of multiple groups. ANOVA assesses the variation between groups and within groups to determine if the observed differences in standards are more important than what would be expected due to random chance. By partitioning the total variability into different sources, ANOVA enables us to understand the extent to which the observed differences can be attributed to the treatment effects or other factors.</p><h4>Assumptions of ANOVA</h4><p>Since this is a test for means, we still consider the assumptions of <em>Normality</em> and <em>Homogeneity of Variances</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t2YBqvdkrzwFz2Dh39osPw.png" /><figcaption>Assumptions of ANOVA</figcaption></figure><p>When applying ANOVA to 2 or more samples for A/B testing with a single variable, we can determine the significance of our test based solely on the assumption of normality. If normality is satisfied, we will use the One-Way ANOVA test; if it is not, we will use the Kruskal-Wallis test.</p><h4>Step by Step application with Python</h4><p>We will perform a statistical analysis using ANOVA by utilizing the ‘tips’ dataset available in Seaborn to examine whether there is a significant difference among the types given for the days of the week. You can find detailed information about all the columns of this dataset on the GitHub page linked below:</p><p><a href="https://github.com/mwaskom/seaborn-data/blob/master/tips.csv">seaborn-data/tips.csv at master · mwaskom/seaborn-data</a></p><pre>import seaborn as sns<br>import pandas as pd<br>from scipy.stats import f_oneway, kruskal, shapiro, levene, mannwhitneyu<br><br>######################################################<br># ANOVA (Analysis of Variance)<br>######################################################<br><br><br>df = sns.load_dataset(&quot;tips&quot;)<br>df.head()<br><br>df.groupby(&quot;day&quot;)[&quot;total_bill&quot;].mean()<br><br>############################<br># 1. Formulate the hypothesis<br>############################<br><br># HO: m1 = m2 = m3 = m4<br># There is no significant difference among the group means<br><br># H1: .. there is a difference<br><br>############################<br># 2. Checking assumptions<br>############################<br><br># Normality assumption<br># Variance homogeneity assumption<br><br># If the assumption is satisfied, we apply the One-Way ANOVA test<br># If the assumption is not satisfied, we use the Kruskal-Wallis test<br><br># H0: The assumption of the normal distribution is satisfied<br><br>for group in list(df[&quot;day&quot;].unique()):<br>  #We select the first index element, which is the p-value, as the Shapiro test function returns both the test statistic and the p-value<br>    pvalue = shapiro(df.loc[df[&quot;day&quot;] == group, &quot;total_bill&quot;])[1] <br>    print(group, &#39;p-value: %.4f&#39; % pvalue)<br><br><br># H0: The assumption of homogeneity of variances is satisfied<br><br>test_stat, pvalue = levene(df.loc[df[&quot;day&quot;] == &quot;Sun&quot;, &quot;total_bill&quot;],<br>                           df.loc[df[&quot;day&quot;] == &quot;Sat&quot;, &quot;total_bill&quot;],<br>                           df.loc[df[&quot;day&quot;] == &quot;Thur&quot;, &quot;total_bill&quot;],<br>                           df.loc[df[&quot;day&quot;] == &quot;Fri&quot;, &quot;total_bill&quot;])<br>print(&#39;Test Stat = %.4f, p-value = %.4f&#39; % (test_stat, pvalue))<br><br>############################<br># 3. Hypothesis testing and interpretation of the p-value<br>############################<br><br># HO: There is no statistically significant difference among the group means<br><br># Parametric ANOVA test:<br>f_oneway(df.loc[df[&quot;day&quot;] == &quot;Thur&quot;, &quot;total_bill&quot;],<br>         df.loc[df[&quot;day&quot;] == &quot;Fri&quot;, &quot;total_bill&quot;],<br>         df.loc[df[&quot;day&quot;] == &quot;Sat&quot;, &quot;total_bill&quot;],<br>         df.loc[df[&quot;day&quot;] == &quot;Sun&quot;, &quot;total_bill&quot;])<br><br># Non-parametric ANOVA test:<br>kruskal(df.loc[df[&quot;day&quot;] == &quot;Thur&quot;, &quot;total_bill&quot;],<br>        df.loc[df[&quot;day&quot;] == &quot;Fri&quot;, &quot;total_bill&quot;],<br>        df.loc[df[&quot;day&quot;] == &quot;Sat&quot;, &quot;total_bill&quot;],<br>        df.loc[df[&quot;day&quot;] == &quot;Sun&quot;, &quot;total_bill&quot;])</pre><p>Although we concluded that there is a significant difference among the groups based on the ANOVA result (rejecting H0), we face a new problem. Which group is responsible for this difference?</p><p>For this purpose, we utilize the multiple comparison method and the Tukey test from the <em>statsmodels</em> module.</p><pre>from statsmodels.stats.multicomp import MultiComparison<br><br>comparison = MultiComparison(df[&#39;total_bill&#39;], df[&#39;day&#39;])<br>tukey = comparison.tukeyhsd(0.05)<br><br>print(tukey.summary())</pre><p>Looking at the entire group from the perspective of ANOVA and the pairwise comparison, results differ. Therefore, even if we obtain a significant impact indicating a difference through ANOVA, we may not observe a substantial difference in p-values among the groups in pairwise comparisons.</p><p>If we cannot identify a dominant group during the pairwise comparison stage, we can conclude that there is no significant difference.</p><p>Another approach is to modify the alpha value, which represents the significance level or p-value, in the Tukey test. However, since 0.05 is a widely accepted and commonly used threshold in the literature, it is generally recommended to proceed with this value without modifying it.</p><h3>Conclusion</h3><p>I have discussed A/B testing using Python in this article. By conducting test studies on sample datasets, we can examine the statistical impact of advancements in various areas, such as feature engineering, customer segmentation, and machine learning optimization.</p><p>Thank you for taking the time to read this article. I hope you have found it enjoyable and informative.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2599e80b29ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data-Driven Customer Segmentation: RFM and CLTV Analysis Using Python]]></title>
            <link>https://medium.com/@abdullahorzan/data-driven-customer-segmentation-rfm-and-cltv-analysis-using-python-4238b11bd740?source=rss-bc3e4b97ee50------2</link>
            <guid isPermaLink="false">https://medium.com/p/4238b11bd740</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[crm]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[customer-lifetime-value]]></category>
            <dc:creator><![CDATA[Abdullah Orzan]]></dc:creator>
            <pubDate>Wed, 12 Jul 2023 14:26:48 GMT</pubDate>
            <atom:updated>2023-07-12T14:26:48.374Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0MyyNzRpOWUfRW21fJCl5g.png" /></figure><h3>1.0 RFM Analysis with Python</h3><p>RFM analysis is a powerful technique widely employed in customer segmentation to gain valuable insights into customer behavior. It leverages three key parameters: Recency, Frequency, and Monetary value.</p><p>Recency refers to the time elapsed since a customer’s last transaction or interaction with the business. It helps identify whether customers are active, dormant, or at risk of churning. Frequency measures how often customers engage with the company within a specific timeframe, indicating customer loyalty and engagement levels. The monetary value represents each customer&#39;s total amount as a proxy for their lifetime value to the business.</p><p>When performing RFM analysis, a database-driven segmentation approach is commonly used. This involves organizing customer data within a database, extracting the necessary RFM metrics, and applying algorithms or techniques to group customers based on their RFM scores. These scores assign numerical values to each customer based on recency, frequency, and monetary matters.</p><h4>1.1 Dataset</h4><p>I will use the Online Retail dataset for the RFM segmentation. You can reach the dataset from the following Kaggle link:</p><p><a href="https://www.kaggle.com/datasets/mathchi/online-retail-ii-data-set-from-ml-repository">Online Retail II Data Set from ML Repository</a></p><p>Dataset column descriptions:</p><p><strong>InvoiceNo:</strong> Invoice number. Nominal. A 6-digit integral number is uniquely assigned to each transaction. If this code starts with the letter ‘c’, it indicates a cancellation.<br><strong>StockCode</strong>: Product (item) code. Nominal. A 5-digit integral number is uniquely assigned to each distinct product.<br><strong>Description:</strong> Product (item) name. Nominal.<br><strong>Quantity:</strong> The quantities of each product (item) per transaction. Numeric.<br>InvoiceDate: Invoice date and time. Numeric. The day and time when a transaction was generated.<br><strong>UnitPrice:</strong> Unit price. Numeric. Product price per unit in sterling (Â£).<br><strong>CustomerID:</strong> Customer number. Nominal. A 5-digit integral number is uniquely assigned to each customer.<br><strong>Country:</strong> Country name. Nominal. The name of the country where a customer resides.</p><h4>1.2 Calculation of RFM Metrics</h4><p><strong>For Recency</strong>, we find the last purchase activity date of the end user within the data frame and add 1–2 days to it to use it as the analysis date in the format of ‘today date. Then, by subtracting the user’s last purchase date from the ‘today date’ value, we obtain the Recency value in terms of days.</p><p><strong>Frequency</strong> is essentially the transaction count for each user. The sum of transaction counts for users provides us with their frequency.</p><p>Lastly, the <strong>Monetary</strong> metric represents the total amount of money each user spends. The sum of the user’s payments will be sufficient to obtain this metric.</p><pre># Create analysis date for Recency metric<br>invoice_date = df[&quot;InvoiceDate&quot;].max() <br><br>today_date= dt.datetime(2010, 12, 11)<br><br># Create RFM data frame with groupby, use lambda functions for calculating Recency, Frequency, and Monetary metrics<br>rfm_df = df.groupby(&quot;Customer ID&quot;).agg({&#39;InvoiceDate&#39;: lambda date: (today_date - date.max()).days,<br>                                        &quot;Invoice&quot;: lambda invoice: invoice.nunique(),<br>                                        &quot;TotalPrice&quot;: lambda totalp: totalp.sum()})<br><br># Rename columns for appropriate use<br><br>rfm_df.columns = [&quot;recency&quot;, &quot;frequency&quot;, &quot;monetary&quot;]</pre><p>When applying RFM segmentation with Python, we convert the RFM metrics into scores because it is impossible to compare these metrics directly.</p><p>When converting RFM values into scores, we use the qcut() function to transform the metric values into RFM label values of 1–2–3–4–5.</p><pre>rfm_df[&quot;monetary_score&quot;] = pd.qcut(rfm_df[&quot;monetary&quot;], 5, labels=[1, 2, 3, 4, 5]) </pre><p>When scoring the Frequency value, we encounter a problem. In the defined label intervals, there can be cases where a frequency value falls into multiple intervals when it occurs very frequently.</p><p>Therefore, in the frequency calculation step, we use the rank(method=”first”) method to select the first occurrence and assign it as the value for that quartile, thus resolving the issue.</p><pre>rfm_df[&quot;frequency_score&quot;] = pd.qcut(rfm_df[&quot;frequency&quot;].rank(method=&quot;first&quot;), 5, labels=[1, 2, 3, 4, 5])</pre><p>It is important to remember that the qcut() function performs a division from the smallest to the most significant values. In the case of the Recency metric, a smaller value represents a more recent date and should therefore have a higher score.</p><pre>rfm_df[&quot;recency_score&quot;] = pd.qcut(rfm_df[&quot;recency&quot;], 5, labels=[5, 4, 3, 2, 1]) <br><br># Create final RFM score<br>rfm_df[&quot;RFM_SCORE&quot;] = (rfm_df[&quot;recency_score&quot;].astype(str) + rfm_df[&quot;frequency_score&quot;].astype(str))</pre><h4>1.3 Creating RFM Segments</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HdmEBrAdy9XxJg12xiJbYg.png" /><figcaption>RFM Segments</figcaption></figure><p>In CRM analytics studies, the frequency of customer interactions, in other words, transactions, is more important. This is because a customer who engages with us can generate more revenue by implementing strategies that lead to increased sales. Looking at the monetary value becomes less meaningful for a customer with no frequency or low probability of transactions.</p><p>Therefore, <strong>we perform the segmentation process by focusing on two dimensions: Recency and Frequency.</strong></p><p>In this final step, we input the intervals of RFM segments as ‘regex.</p><p>Then, we apply the replace() method to the variable containing the obtained scores, replacing them with the corresponding segments and saving them to the variable where the segments are located, completing our process.</p><pre>seg_map = {<br>    r&#39;[1-2][1-2]&#39;: &#39;hibernating&#39;,<br>    r&#39;[1-2][3-4]&#39;: &#39;at_Risk&#39;,<br>    r&#39;[1-2]5&#39;: &#39;cant_loose&#39;,<br>    r&#39;3[1-2]&#39;: &#39;about_to_sleep&#39;,<br>    r&#39;33&#39;: &#39;need_attention&#39;,<br>    r&#39;[3-4][4-5]&#39;: &#39;loyal_customers&#39;,<br>    r&#39;41&#39;: &#39;promising&#39;,<br>    r&#39;51&#39;: &#39;new_customers&#39;,<br>    r&#39;[4-5][2-3]&#39;: &#39;potential_loyalists&#39;,<br>    r&#39;5[4-5]&#39;: &#39;champions&#39;<br><br>rfm_df[&#39;segment&#39;] = rfm_df[&#39;RFM_SCORE&#39;].replace(seg_map, regex=True)</pre><p>The resulting customer segments generated by RFM analysis can be precious for businesses. Organizations can tailor their marketing strategies, product offerings, and customer experiences&#39; specific needs by grouping customers with similar purchasing patterns, preferences, and behaviors.</p><p>For example, high-value customers who recently purchased may receive personalized offers to encourage repeat purchases. Dormant customers with low monetary value may be targeted with re-engagement campaigns to regain their interest.</p><h3>2.0 CLTV Customer Segmentation with Python</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*f7bYuwD4u0RLYZrbjLzudQ.jpeg" /></figure><p>CLTV (Customer Lifetime Value) is a crucial metric that quantifies a customer&#39;s monetary worth to a company over the entire duration of their relationship and communication. It encompasses not only the immediate revenue generated from individual purchases but also factors in the potential for future transactions and customer loyalty.</p><p>By calculating CLTV, businesses gain insights into the value and profitability of each customer. This knowledge allows them to identify high-value customers that contribute significantly to the company’s revenue. With this understanding, businesses can focus their resources and efforts on nurturing and retaining these valuable customers, maximizing long-term profitability.</p><h4>2.1 The Calculations Underlying CLTV Segmentation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Trj6TnM5rkip8B0Ko71PCA.jpeg" /></figure><p>CLTV can be calculated with the following formula:</p><p><em>CLTV = (Customer Value / Churn Rate) * ProfitMargin</em></p><p>Let’s break down the values in this formulation and closely examine their statistical calculations.</p><pre># Customer Value = Average Order Value * Purchase Frequency<br><br># Average Order Value = Total Price / Total Transaction<br><br># Purchase Frequency = Total Transaction / Total Number of Customers<br><br># Number of Customers with Multiple Purchases / Total Customers<br><br># Churn Rate = 1 - Repeat Rate</pre><p>When the obtained CLTV values are used to rank and divide customers into groups at specific points, a segmentation occurs, and customers are categorized into segments.</p><h4>2.2 Dataset</h4><p>I will also use the Online Retail dataset for the CLTV segmentation. You can reach the dataset and my whole CLTV segmentation work from the following Kaggle link:</p><p><a href="https://www.kaggle.com/code/abdullahorzan/customer-segmentation-with-cltv">Customer Segmentation with CLTV</a></p><h4>2.3 CLTV Calculations</h4><pre># Find the total price for CLTV calculation<br><br>df[&quot;Total_Price&quot;] = df[&quot;Quantity&quot;] * df[&quot;UnitPrice&quot;]<br><br># Create cltv_df with the total price, total transaction, and total unit for calculation<br><br>cltv_df = df.groupby(&quot;CustomerID&quot;).agg({&quot;InvoiceNo&quot;: lambda x: x.nunique(),<br>                             &quot;Quantity&quot;: &quot;sum&quot;,<br>                             &quot;Total_Price&quot;: &quot;sum&quot;})<br><br># Rename columns for CLTV calculation<br><br>cltv_df.columns = [&quot;Total_Transaction&quot;, &quot;Total_Unit&quot;, &quot;Total_Price&quot;]</pre><p>Once we create the CLTV data frame, we can calculate all other values using it.</p><pre># Calculate the average order value<br><br>cltv_df[&quot;Average_Order_Value&quot;] = cltv_df[&quot;Total_Price&quot;] / cltv_df[&quot;Total_Transaction&quot;]<br><br># Calculate purchase frequency<br><br>cltv_df[&quot;Purchase_Frequency&quot;] = cltv_df[&quot;Total_Transaction&quot;] / cltv_df.shape[0]<br><br># Calculate customer value<br><br>cltv_df[&quot;CV&quot;] = cltv_df[&quot;Average_Order_Value&quot;] * cltv_df[&quot;Purchase_Frequency&quot;]<br><br># Calculate churn rate<br><br>Repeat_Rate = cltv_df[cltv_df[&quot;Total_Transaction&quot;] &gt; 1].shape[0] / cltv_df.shape[0]<br><br>Churn_Rate = 1 - Repeat_Rate<br><br># Calculate profit margin<br><br>cltv_df[&quot;Profit_Margin&quot;] = cltv_df[&quot;Total_Price&quot;] * 0.10<br><br># Calculate the customer lifetime value<br><br>cltv_df[&quot;CLTV&quot;] = (cltv_df[&quot;CV&quot;] / Churn_Rate) * cltv_df[&quot;Profit_Margin&quot;]</pre><h4>2.4 Analyzing the Segments and Finalizing the Segmentation Criteria</h4><pre># Segmentation based on CLTV<br><br>cltv_df[&quot;segments&quot;] = pd.qcut(cltv_df[&quot;CLTV&quot;], 5, labels= [&quot;D&quot;, &quot;C&quot;, &quot;B&quot;, &quot;A&quot;, &quot;S&quot;])<br><br># Descriptive stats for segments<br><br>cltv_df.groupby(&quot;segments&quot;).agg({&quot;count&quot;, &quot;mean&quot;, &quot;sum&quot;})</pre><p>After completing the segmentation process, our next step should be to analyze the segments to reach the optimal number of features and obtain segment averages aligned with our business objectives. This stage can be challenging without a deep understanding of business knowledge and project details, as making the best decisions becomes difficult. Therefore, if we are not well-versed in this information, we aim to perform a logical segmentation process by utilizing statistical approaches and data visualization to gather as much information as possible from the data.</p><p>For instance, I complete the segmentation process by using a radar chart to visualize the distribution of segments across the data.</p><pre># Radar chart<br><br>r_segment_stats = cltv_df.groupby(&quot;segments&quot;)[[&quot;Average_Order_Value&quot;, &quot;Total_Transaction&quot;, &quot;Profit_Margin&quot;]].mean()<br><br># Normalize the data<br>segment_stats_normalized = (r_segment_stats - r_segment_stats.min()) / (r_segment_stats.max() - r_segment_stats.min())<br><br># Create a radar chart to visualize the statistics by segments<br>angles = np.linspace(0, 2 * np.pi, len(r_segment_stats.columns), endpoint=False).tolist()<br>angles += angles[:1]  # Close the plot<br>plt.figure(figsize=(8, 8))<br>for segment in segment_stats_normalized.index:<br>    values = segment_stats_normalized.loc[segment].tolist()<br>    values += values[:1]  # Close the plot<br>    plt.polar(angles, values, marker=&#39;o&#39;, label=segment)<br>plt.xticks(angles[:-1], r_segment_stats.columns)<br>plt.yticks([0.25, 0.5, 0.75, 1.0])<br>plt.title(&#39;Segment Comparison&#39;)<br>plt.legend(title=&#39;Segments&#39;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*tAevNs-C-M-VoGQc9tbZ5A.png" /><figcaption>Radar chart for segments</figcaption></figure><h4>Appreciation and Acknowledge</h4><p>While this article provides the core steps for performing RFM and CLTV customer segmentation using Python, it does not include the Python code for data preprocessing, exploratory data analysis, and other actions that may be part of these processes to keep the article concise. RFM and CLTV segmentation studies highly depend on the available data&#39;s the analysis&#39;s specific goals. Nevertheless, I have shared the fundamental steps involved in these processes.</p><p>I hope you have found this article on customer segmentation using CLTV and RFM with Python helpful.</p><p>Please don’t hesitate to reach out with any questions or suggestions, and if you liked it, feel free to give it a clap. Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4238b11bd740" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make a drone from beginning: Part 1]]></title>
            <link>https://medium.com/@abdullahorzan/make-a-drone-from-beginning-part-1-60cfe5d36c5a?source=rss-bc3e4b97ee50------2</link>
            <guid isPermaLink="false">https://medium.com/p/60cfe5d36c5a</guid>
            <category><![CDATA[uav]]></category>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[quadcopter]]></category>
            <category><![CDATA[drones]]></category>
            <dc:creator><![CDATA[Abdullah Orzan]]></dc:creator>
            <pubDate>Sat, 29 Feb 2020 13:29:02 GMT</pubDate>
            <atom:updated>2023-07-20T11:44:36.959Z</atom:updated>
            <content:encoded><![CDATA[<h3>Make a drone from beginning</h3><p>Last year my team and I started a new quadcopter project for a competition. This article or guide will mostly lean on my own experience from there. I am going to use quadcopter or quads abbreviation instead of drones because I made a quadcopter and think it is the best choice for starting. However, you can easily apply all of the information for all kinds of drones if you wish to make a different one. First of all, I am aware there are a lot of guides or tutorials on the internet, and people can reach them easily. However, this article is not about only to share my experience; it is about to check my learning way and see my knowledge about drones/quadcopters help people who are going to start or wish to make one. As a result, this will be two side challenge. Let’s start!</p><p>This guide continue with these parts:</p><ol><li>How do we begin this?</li><li>ESC, motors and the main body essentials</li><li>Battery and charge</li></ol><h3>How do we begin this?</h3><p>After learning about basic flight mechanics, make a drone is mostly puzzle in the first step if you are a beginner in this journey. It is about creating accurate calculations and chooses the best electronic parts for your aim.</p><p>The first thing you should learn about quads is flight dynamics, not many details but enough for the know what we do. Like all flight vehicles, quads also have a pitch, roll, and yaw. These are basic terminologies, but you will use them to choose the right props, motors, etc.</p><h3>ESC, motors and the main body essentials</h3><p><strong>Frame: </strong>Firstly, we need to decide our quads frame. Quadcopters frames are named by their wingspread long. When you start to search or make a frame for your quad, you will see frames with the name F450-F500, etc. This name comes from the frame size and clarifies that frame 450mm or 500mm. For standard usage, F450 or F500 most suggest frame size. But if you are going to make some smaller quads or drone-like a racer quad, pick smaller ones. For the frames, just Goit and find your frame to your aim.</p><p>After picking a frame for the quad, we will continue with the motors. Their motor numbers name drones, so quadcopter, as you guess about its name, has four motors. Usually, make a quad start from the choose right motors and then build everything around them. ESC’s for your motors and chooses the right battery to support them.</p><p><strong>Motors: </strong>Drones and so does quadcopters use brushless motors. Brushless motors are thin, durable, and give us the power that we need. So brushless motors are the most effective option for now. There are some things you should know about the brushless motor when you will choose one. Brushless motors separate for their KV’s but their thrust, efficiency, amps, and volts essential pieces of information. You should always read data sheets of motors and check these pieces of information to see if they are proper for you. Let me explain these terms shortly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dzzCfIXtDWguEMc_eyLOBw.png" /><figcaption>Data sheet of a motor.</figcaption></figure><p><strong>KV: </strong>No, it is not kV. It is far removed kilovolt. KV is referring to the constant velocity of a motor. It is measured by the number of revolutions per minute (rpm) that a motor turns when one volt is applied with no load attached to that motor.</p><p><strong>Thrust: </strong>Thrust is the determine how much weight our quad will be lift and how powerful our motors. For example, if your motor has an 800G thrust, that means your quads can lift 4x800 = 3.2 kg weight.</p><p><strong>Amps: </strong>Amps is an abbreviation of amperes, so it determines how many amperes our motor use.</p><p><strong>Volts: </strong>Volts determine how many volts we need to work our motors. We will choose our battery according to volts and amps. Likewise, motors work with different power on different voltages.</p><p><strong>Efficiency:</strong> It is what it is. Determine the motor’s effectiveness, if it is quite low, do not pick that motors for your good.</p><p>Weight, length, and diameter of a motor are also essential things you should care about when you pick one. For example, you should choose a lighter motor if you want to make a lifter quad. Because lifting part and lift is massive, heavy motor brings thrust lost for you.</p><p>Length and diameter are also crucial for what do you expect your motor if you want to heavy lift and make a slower drone choose a motor that has a big width but a short length. If you’re going to make a faster drone, pick the long and short width motor.</p><p><strong>Propellers:</strong> The first thing about a propeller is its length — the length in inches. Propellers come from different lengths and not many but different shapes. If this is going to be your first time making a drone and want to make your propellers with a 3D printer or something you need to know, you must be careful. Calculate and regulate propellers balance is much harder than it looks, so if you take, I will say buy it for your first time as a piece of advice. Generally, propellers have numbers like 1045, 1150, etc.</p><p>First, two-digit is a determined inch of propellers, and the last two-digit is to determine the pitch. Propellers have turning direction and that as clockwise and counterclockwise. Usually, their direction writes on it. When you put a propeller on a motor, you need to make it according to the direction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*ml2qhiDdVlLjGTGW6hwPuw.jpeg" /><figcaption><a href="https://ardupilot.org/copter/docs/connect-escs-and-motors.html">https://ardupilot.org/copter/docs/connect-escs-and-motors.html</a></figcaption></figure><p>The pitch is another property of the propeller. Pitch of propeller dictates how far propeller travel in a single revolution. Propellers with the lower pitch will conserve more energy. If you want to fast and agile quadcopter, your propellers must have a small diameter with a higher pitch. If you’re going to lift a weight with your quadcopter, for example, a camera or something, you should use bigger propellers. I guess enough ‘’if’’ for propellers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*lPwF2dAAo-zy4l61IND0kA.jpeg" /><figcaption><a href="https://www.propellor.com/performance">https://www.propellor.com/performance</a></figcaption></figure><p><strong>Electronic Speed Controller (ESC):</strong> An ESC is arranging your quads motors speed and help you to control them as per your request. The most important thing about finding the right ESC for your motor is their amperes. ESC’s separate according their amper such as 20A, 30A, etc.</p><p>You should choose ESC’s amount of amper that your motors need. For example, if your motors work with max 25 amper properly, you should select a 30A ESC. You can think that your motors are working space.</p><h3>Battery and charge</h3><p>The battery will be one of the most massive parts of our quadcopter. In quadcopters, we will use LiPo batteries. LiPo batteries vary by their cells. Every cell in a LiPo battery supply 3.7 voltage. So it would be best if you chose a battery which has enough voltages for your motors. Batteries are named by their cells and connections type. If you check, you can quickly see 3S1P, 3S2P, 4S1P batteries. 3S2P means 3 cells, and 2 of them parallel. Another vital thing about batteries is knowing the C-Rating. Every battery has a C-Rating on it. That C rating is an indicator of the continuous discharge rate of a LiPo. If we want to calculate:</p><p>Max Current Draw = Capacity x C-Rating</p><p>A 3S 2200maH 40C LiPo pack will get you this: 2200mAh x 40C = 88.000 mAh discharge rate 88.000 mAh / 1000 = 88 Ampere constant discharge rate. A constant current draw of 20A from a 2200mAh LiPo will get you:( 2200mAh /1000) / 20A = 0.11 x 60 = 6.6 minutes flying time. There are a lot of websites you can calculate easily flying time, max current and voltages, etc. I highly recommended for every drone maker<a href="https://www.ecalc.ch/"> ecalc.ch</a>. On the ecalc.ch, give your motors, battery, frame, and ESC information easily enough to see what will be waiting for you and it has really chip subscription.</p><p><strong>Charge: </strong>Charging and recharging your battery is also very important because cells are sensitive things. LiPo batteries have more than one cell, and they are connected as serial. So charging every cell with the same voltages is very important to provide balance. You should use a charging tool for making this job instead of you. Before the charge your battery always checks its nominal voltage and does not charge too much of that value.</p><p>Lastly, <a href="http://ardupilot.org/">Ardupilot.org</a> and the ecalc.ch are your best friends in your quadcopter journey. Do not ignore them.</p><p>If I will be have time to complete, the second part will be about the flight controllers, transmitters, receivers, and communication between them.</p><p>Thanks for reading and companionship to my challenge.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60cfe5d36c5a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>