<?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 Simge Erözel on Medium]]></title>
        <description><![CDATA[Stories by Simge Erözel on Medium]]></description>
        <link>https://medium.com/@simgeerozel?source=rss-69d619126dc3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*up7uE4GjmiIafp-Li6qcMg.jpeg</url>
            <title>Stories by Simge Erözel on Medium</title>
            <link>https://medium.com/@simgeerozel?source=rss-69d619126dc3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 23:03:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@simgeerozel/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[RFM Analysis]]></title>
            <link>https://medium.com/@simgeerozel/rfm-analysis-48f0940a936e?source=rss-69d619126dc3------2</link>
            <guid isPermaLink="false">https://medium.com/p/48f0940a936e</guid>
            <category><![CDATA[crm]]></category>
            <category><![CDATA[rfm-analysis]]></category>
            <category><![CDATA[segmentation]]></category>
            <dc:creator><![CDATA[Simge Erözel]]></dc:creator>
            <pubDate>Tue, 17 May 2022 05:27:56 GMT</pubDate>
            <atom:updated>2022-05-17T05:27:56.674Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello everyone,</p><p>Today, I’m going to talk about RFM analysis, why it’s needed. Later in the article, I will do segmentation work, but you will not see much code, but more details of how I approach the data and the inferences.</p><figure><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.omniconvert.com%2Fblog%2Frfm-analysis%2F&amp;psig=AOvVaw3cZfRlsQoPJrgsFjxfJ28B&amp;ust=1652831395678000&amp;source=images&amp;cd=vfe&amp;ved=0CAwQjRxqFwoTCNjK2fia5fcCFQAAAAAdAAAAABAD"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8clY2YGlKnWIzhvp.png" /></a><figcaption><a href="https://www.omniconvert.com/blog/rfm-analysis/">https://www.omniconvert.com/blog/rfm-analysis/</a></figcaption></figure><p>For codes, you can visit my <a href="https://github.com/simgeerozel/RFM_Segmentation.git"><strong>Github </strong></a>account.</p><p>Let’s get started if we’re ready:</p><p>Before talking about RFM analysis, it is useful to briefly mention the concept of CRM.</p><p>What is CRM? These are technologies that aim to increase sales profitability with efficient and effective approaches by acting customer-oriented. The most important point here is to understand what the customer needs and to be able to develop solutions suitable for this need.</p><p>At this point, there is no standard form that can be applied to every customer. For example, let’s say that the company wants to organize various campaigns as a marketing strategy to increase sales profitability. Customer behavior should be defined so that we can deliver the right campaigns to the right target audience.</p><p>Let’s say we’re asking basic questions:</p><p>What is out target audience?</p><p>How can we regain the mass that has been dormant for a long time?</p><p>How can I run campaigns for the audience I’m about to lose / need to increase attention?</p><p>There are many questions that will enable us to increase our sales profitability and the answers are hidden under RFM analysis. What is RFM? It is the score obtained by combining the Recency, Frequency and Monetary metrics after calculating. RFM analysis, on the other hand, segments customers based on their calculated scores and enables the development of sales and marketing methods and action to be taken on the basis of customers in each segment.</p><p><strong>Recency, Frequency and Monetary Metrics</strong></p><p>When calculating these metrics, they are expressed on a scale of 1 to 5. The reason for doing this is that, as we mentioned when defining RFM concepts, an overall score is obtained after combining the metrics. With the conversion process, all metrics can be combined as they can be expressed in a single format.</p><p><strong>Recency:</strong> Gives information about when the customer last received service. It is usually obtained by subtracting from the date of analysis the date when the client last traded. Unlike the Frequency and Monetary metrics on a scale of 1 through 5, 5 refers to the most recently arrived customers and 1 refers to customers who have not arrived in a long time.</p><p><strong>Frequency:</strong> Refers to the frequency of the customer’s purchase. The number of purchases on a customer basis can be based on the number of invoices. A scale of 1–5 , 1 refers to the customers with the lowest shopping frequency, 5 refers to the customers with the highest shopping frequency.</p><p><strong>Monetary:</strong> Refers to the total spend made by the customer. 1 refers to the customers who spend the least, while 5 refers to the customers who spend the most.</p><p>Then, segmentation is finalized over these scores. Customers are divided into classes such as champions, need_attention, loyal_customers, etc.</p><p>So far we have talked about CRM and RFM. Let’s continue with the data.</p><p><strong>Data:</strong> Within the scope of the study, we will segment the customers of FLO, an online shoe store, and determine their marketing strategies. Our dataset contains 19945 rows and 12 variables.</p><p><strong>The variables contained in the data are as follows:</strong></p><p><strong>master_id:</strong> Unique customer number</p><p><strong>order_channel: </strong>Shopping platforms (Android, iOS, Desktop, Mobile)</p><p><strong>last_order_channel:</strong> Latest shopping channel</p><p><strong>first_order_date / last_order_date:</strong> First shopping date / Last shopping date</p><p><strong>last_order_date_online / last_order_date_offline:</strong> Last shopping date on the online/offline platform</p><p><strong>order_num_total_ever_online / order_num_total_ever_offline:</strong> Total number of purchases on the online/offline platform</p><p><strong>customer_value_total_ever_offline / customer_value_total_ever_online:</strong> Total spending on the online/offline platform</p><p><strong>interested_in_categories_12:</strong> A list of categories that customers shopped in 12 months</p><p><strong>Step 1:</strong> Importing libraries</p><p><strong>Step 2:</strong> Reading the dataset</p><p><strong>Step 3:</strong> Data Understanding. We need inferences before segmentation.</p><p>I mentioned that the dataset contains 19945 rows and 12 variables. For a quick look: <em>Head(), shape, info()</em></p><p>Then, the observation of missing values is among the important details. It seems that there are no missing values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*U6YLqAgEOMLqur0hxEEhJQ.png" /></figure><p>Let’s consider the interested_in_categories_12 variable. What is the number of unique categories shopped in the last 12 months? With <em>unique()</em> we can obtain this information. There are 32 different categories.</p><p>What about the distribution of these categories? We got to that with <em>value_counts(). </em>There are 2135 rows in this column consisting of only “[]”. In the missing value section, this is not reflected on the screen because it is perceived as a filled column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*XFCP4JAkgSpdGndWcQU5QQ.png" /></figure><p>I want to eliminate these rows. After applying the filter operation, I pulled the rows whose content is greater than 2 with the help of the map function, after performing the elimination process, I check the shape information again and from here I will continue with 17810 rows.</p><p>On the other hand, when we consider the order_channel variable, there is information that 4 different channels are used (Android,ios,Desktop,Mobile). When I examine the usage base of these categories: We can say that the Android App has the highest usage in channel usage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*x86kfbTlmJeLuEcvvSKwYg.png" /></figure><p>At this point, I will then add the omnichannel variable to the data. Omnichannel refers to customers who shop both online and offline. I do this because I don’t want to evaluate the online and offline platform separately.</p><p><strong>Omnichannel_total:</strong> Total number of purchases made online and offline platforms</p><p><strong>Omnichannel_total_cost:</strong> Total spending for purchases made on online and offline platforms</p><p>In the graph below, there are the top 5 categories with the highest number of purchases on the basis of the categories of interest in 12 months.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*TkcMe5_geKU1zNH5qPNUeA.png" /></figure><p>In the graph below, when examined in terms of total spending, it is seen that the amount of expenditure in the [AKTIFSPOR] category is very high compared to other categories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*ERT3t5GTrEjHlfheBoaflg.png" /></figure><p><strong>Step 4: </strong>RFM Metrics</p><p>The important point here is this:</p><p>I mentioned that the recency value is usually calculated by subtracting the last analysis/invoice date from the specified analysis date. At this point, the format of the type information of the date variables should be: datetime64[ns]. Otherwise, you will not be able to perform the operation</p><p><em>RFM metrics,</em></p><p>The last order date is 30 May 2021 and the analysis date is set as 2 days and the Recency values are calculated.</p><p>Frequency metric over Omnichannel_total variable ,</p><p>The Monetary metric was also calculated over Omnichannel_total_cost.</p><p>If we observe:</p><p>Although the average time of customers online or offline visits is 143 days ago, we see that the average number of purchases is 5.19 and the average amount they spend is 777 TL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*20GjrSJwKRLWbkW83oY_2Q.png" /></figure><p><strong>Step 5: </strong>RFM Scores</p><p>After this step, we need to return the RFM scores to the 1–5 scale. At this point , the qcut() function can be used.</p><p>Another important point: Then to combine these variables:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*vaVp6ZlmBb8B-WRk7pQ9Ig.png" /></figure><p>What have we achieved as a result of the transactions so far? For example, we want to see customers with the highest number of recent purchases and the highest spend, you can easily observe and duplicate examples:</p><p><em>rfm[rfm[“RFM_SCORE”]==”555&quot;].head()</em></p><p><strong>Final Step: </strong>Creating Segments</p><p>We’re going to use a regular expression here, and we’re basically going to say: For example, we’re going to include those with a Recency value of 5 and a Frequency value of 1 in segmentation as new_customer.</p><p>The seg_map we created as a dictionary:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*NHoiyW94IZUENanfz6y70Q.png" /></figure><p>At this point, I prefer to create the segmentation process through Recency and Frequency, and the Monetary part can also be added. We add the Segment column to the dataframe to include the classes in the seg_map.</p><p>After adding the segment column, if we examine the final version,</p><p>There are 738 people in the New_customers group, they arrived an average of 20 days ago, their shopping frequency is 2 and their average expenditure is 370 TL. There are 2723 people in the At_Risk group, their average expenditure is around 667 TL, but they have not shopped for more than 6 months. Actions can be taken by examining points such as this and thus, since we now have the target audience information, it is ensured that different actions are taken for the customer that can provide retention or prevent the churn factor.</p><p>After adding the segment column, if we examine the final version,</p><p>There are 738 people in the New_customers group, they arrived an average of 20 days ago, their shopping frequency is 2 and their average expenditure is 370 TL. There are 2723 people in the At_Risk group, their average expenditure is around 667 TL, but they have not shopped for more than 6 months. Actions can be taken by examining points such as this and thus, since we now have the target audience information, it is ensured that different actions are taken for the customer that can provide retention or prevent the churn factor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*TUO5siDi6hu6vOIslJeI9w.png" /></figure><p>Graphical representation of segmentation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*9h3JVKJgwFXwQFLJO_-bUw.png" /></figure><p>So we came to the end of segmentation. We talked about the concept of taking continuous action. For example, let’s say that the company wants to organize a campaign. We need to solve 2 cases.</p><figure><a href="https://tenor.com/view/michael-scott-wink-yes-no-problem-gif-16355545"><img alt="" src="https://cdn-images-1.medium.com/max/498/0*EnVSEUxGa6c1N_su.gif" /></a><figcaption><a href="https://tenor.com/view/michael-scott-wink-yes-no-problem-gif-16355545">https://tenor.com/view/michael-scott-wink-yes-no-problem-gif-16355545</a></figcaption></figure><p><strong>Case 1:</strong> A new women’s shoe brand will be included. The target audience (champions, loyal_customers) and women are determined as shoppers. We need access to the id numbers of these customers.</p><p><strong>Case 2:</strong> A 40% discount on men’s and children’s products is planned. The target audience is (cant_loose, about_to_sleep, new_customers). We need to access the id numbers of these customers.</p><p>For those who are curious about case solutions, <a href="https://github.com/simgeerozel/RFM_Segmentation.git">Github </a>is included in my profile.</p><p>I think it’s time to finish. I congratulate those who manage to read until the end.</p><p>See you soon 🍀</p><p><strong>Additional Resources</strong></p><ul><li><a href="https://medium.com/analytics-vidhya/data-visualization-and-rfm-recency-frequency-and-monetary-analysis-using-python-customer-d7e129437aac">Data visualization and RFM( Recency, Frequency and Monetary) analysis using Python-Customer…</a></li><li><a href="https://medium.com/@ogunbajoadeyinka/building-an-rfm-model-in-python-3481112a2816">Building An RFM Model in Python</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48f0940a936e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mini Keşif 4: PIVOT TABLE]]></title>
            <link>https://medium.com/@simgeerozel/mini-ke%C5%9Fif-4-pivot-table-ba6cd703262f?source=rss-69d619126dc3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba6cd703262f</guid>
            <dc:creator><![CDATA[Simge Erözel]]></dc:creator>
            <pubDate>Sun, 06 Mar 2022 21:34:18 GMT</pubDate>
            <atom:updated>2022-03-06T21:34:18.195Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fmoving-gif-4824850&amp;psig=AOvVaw1ZyGPF2ZwK_AHrRMJY9Gjd&amp;ust=1646688643242000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCJDj2K-3svYCFQAAAAAdAAAAABBF"><img alt="" src="https://cdn-images-1.medium.com/max/792/0*BUGacOuFIjQgeSoG.jpg" /></a></figure><p>Merhabalar,</p><p>Serinin 4. Yazısında Pivot komutunu ele alacağız. Pivot nedir? Temelde satırlarda yer alan bilgiyi belirtilen alanlara göre sütunlara dönüştürür. Veriyi daha düzenli/anlaşılır hale getirirken kullanılan bir yöntemdir.</p><p>O zaman hızlıca senaryomuza geçelim. Northwind db ile çalışmaya devam ediyoruz. Bu sefer ise kategori bazında yıllara göre verilen sipariş sayılarını elde etmek istiyoruz. Bunu elde ettikten sonra ise raporumuzu pivot haline getireceğiz. Pivot derken ne kastediyorum kısmını görselleştirecek olursam:</p><p><strong>Çıktının ilk hali / Çıktının elde etmek istediğimiz hali</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*zqemtsJ9mhMSJ2E2BGAdNQ.png" /></figure><p>Raporumuzu bu hale getirmeden önce bazı join işlemleri yapmamız gerekecek. Bu noktada kullanacağımız tablolara göz atıp hangi alanları bağlayacağımıza karar vermemiz gerekiyor.</p><p>Aşağıdaki diyagramı inceleyecek olursak Categories tablosu ile Orders tablosunu birleştirmemiz gerekiyor. Çünkü ihtiyacımız olan tarih bilgisini Orders tablosu içindeki OrderDate sütunundan sağlayacağız.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*8ZrvuEUZL1qo_cs1bDeevA.png" /></figure><p>Tabloların bağlanacağı alanlara da karar verdikten sonra sorgumuzun ilk adımına geçebiliriz.</p><p>Öncelikle CategoryName sütununa göre bir gruplama işlemi yapalım.<strong> Bu noktada dikkat noktası ise şurası: </strong>OrderDate sütununda yer alan tarih formatı “YYY-MM-DD 00:00:00.000” şeklinde. Buradan yılı çekmek için YEAR() fonksiyonunu kullandık.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*TE0K1Snbxyl-MiIEPbelMA.png" /></figure><p>Elde ettiğimiz sonuç:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*N0GuMUeW2mvLBCjcmpPFDA.png" /></figure><p>Son aşamaya geldik. Şimdi sorgudan dönen bu sonucu PIVOT ifadesi yardımıyla pivot tabloya çeviriyoruz. Bu işlemi yaparken de neye göre gruplayacağını ve bu gruplama sonucu elde edilecek çıktının kolon isimlerini belirtmemiz gerekiyor. Sum(total) CategoryName sütunu için kategori bazlı sipariş sayılarının toplamını verecektir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*s2YL65bj7qGuSOos2I-a6A.png" /></figure><p>Sorgumuzun sonucunda en başta çıktımızı elde etmek istediğimiz pivot formatını da böylelikle elde etmiş olduk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*8tdFwMP7cAUpzZQu2C7GtA.png" /></figure><p>Böylelikle serinin 4. konusunu da tamamlamış olduk. Bir sonraki yazıda görüşmek dileği ile 🌗</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba6cd703262f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mini Keşif 3: Correlated Subquery (İlişkili Alt Sorgu)]]></title>
            <link>https://medium.com/@simgeerozel/mini-ke%C5%9Fif-3-correlated-subquery-i%CC%87li%C5%9Fkili-alt-sorgu-1fc681b78a88?source=rss-69d619126dc3------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fc681b78a88</guid>
            <dc:creator><![CDATA[Simge Erözel]]></dc:creator>
            <pubDate>Fri, 11 Feb 2022 03:35:18 GMT</pubDate>
            <atom:updated>2022-02-11T03:35:18.999Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwallpapercave.com%2Fsql-wallpapers&amp;psig=AOvVaw2lc2LwxKr_X_704PDQ14Hv&amp;ust=1644636436947000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCMDZlq3a9vUCFQAAAAAdAAAAABAE"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w0tRa8k7-xLMm_DI.jpg" /></a></figure><p>Selamlar,</p><p>Mini Keşif-2 yazısını okuyanlarınız bilir tam raporu teslim edecekken mesai uzatan bir durumla karşılaşmıştık. Neydi o durum? Öncelikle gemileri nakliye ücretlerine göre sınıflandırdıktan sonra bir de bu kayıtların sayısını elde etmiştik.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*8oxbxWews0JvVt5TyJzqZA.png" /></figure><p>Ancak tamam oldu bu iş derken ilk satırda Alfreds Futterkiste ve hemen altında yer alan Alfred’s Futterkiste bize bi göz kırptı. <em>“Biz buradayız! Hadi ispatla bizim aynı kayıt olduğumuzu :) “</em></p><p>Bu noktada ne yapılabilir diye düşündük. Öncelikle bu tabloda kaç tane böyle kayıt var bunu tek tek tespit edemeyiz sonuçta. Hadi şu an 830 satırlık bir veride ettik diyelim 83000 satırlık bir veride ne yapacağız? Keşke bir sorgum olsa da içine istediğim şartları eklesem ana sorgumda derdimi anlasa da çıktıyı bana verse.</p><p>Anlık modumuz aşağıdaki gibidir:</p><figure><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.meme-arsenal.com%2Fen%2Fcreate%2Fmeme%2F3228846&amp;psig=AOvVaw2gliZhK6HZEH1RHv_yYTxr&amp;ust=1644616625210000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCICLrMOQ9vUCFQAAAAAdAAAAABAD"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mxNDxs5fnu65o8IM.jpg" /></a></figure><p>Süper güç Subquery yardıma koşar: “Gel vatandaş gel ✋” Nedir bu Subquery kavramı?</p><p>Subquery temelde sorgu içerisindeki sorguların ele alındığı bir kavramdır.</p><p>Alt sorgudan tek kayıt döndürebilir. Birden fazla kayıt döndürülebilir. Alt sorgunun ana sorgudan bağımsız çalıştığı örnekler ele alınabileceği gibi alt sorgunun üreteceği çıktıyı ana sorgudan sağladığı örnekleri de mevcuttur. Bizim durumumuzda ise kullanacağımız<strong> Correlated Subquery (İlişkili Alt Sorgu)</strong>. Performans açısından her zaman tercih sebebi olmayabiliyor. Detaylar ve karşılaştırmalar için → (Kaynakça)</p><p>Correlated Subquery yapısı nasıldır? Alt sorgular ana sorgudaki sütunlar için referans düzeneği kurar.</p><p>Bizim uygulayacağımız da aslında bu olacak. Elimizdeki problemde eşleşmeyen satırları belirlemek istiyoruz. Senaryomuzu da şu şekilde ilerletecek olursak veriye göz gezdirdik, incelemeleri yaptık ve tamam her gemi grubu için nakliye adresi (ShipAddress) farklılık gösteriyor. O zaman ShipAddress bilgileri aynı olan ama farklı ShipName bilgisine ait gemi varsa bana bunların listesini getir desem acaba olur mu?</p><p>Aşağıda aslında tam da bunu yapmış olduk. Benim Orders tablom var sen bunu ana sorguda kullan bir de sana zahmet bunu alt sorguda kullan. Son olarak bir de sana şart eklemem gerek. Bana ana tablomdaki sütunları da referans alarak adresleri aynı ama gemi adlarının farklı olduğu kayıtları getir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*bs98ds0VfmQZSwkWTl6hXw.png" /></figure><p>Bakalım ne yaptı?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OTmt0zYVHb-Rjooej8WHAg.png" /></figure><p>Bana tek bir kayıt döndü. O kayıt da <strong>“Alfreds Futterkiste” </strong>adlı gemi oldu. Demek arada fark edilmeyi bekleyen sadece oymuş. Minik bir kontrol yapacak olursak LIKE operatörü kullanarak bir test edelim.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*53ba98oxb3VWsGAzbmkihQ.png" /></figure><p>ShipName içerisinde Alfred geçenleri getirdiğimizde elde ettiğimiz çıktı şu şekilde oldu: Toplamda 6 kayıt döndü. Bunlardan 1 tanesinin bize biraz önce verdiği <strong>“Alfreds Futterkiste” </strong>kalan 5 tanesinin ise<strong> “Alfred’s Futterkiste” </strong>olduğunu görmüş olduk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*15rMEPt4xnFjtD-uKuoiVA.png" /></figure><p>O zaman kapanışa geçebiliriz. Raporda canımızı sıkan detay adlarının aynı olmasına rağmen (‘) farkından dolayı farklı kayıt olarak algılanmalarıydı.</p><p>Raporun eski haline tekrar göz atacak olursak,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*8oxbxWews0JvVt5TyJzqZA.png" /></figure><p>Biz burada minik bir UPDATE işlemi uygularsak bakalım raporun son hali ne olacak? SELECT ifadesi içinde belirttiğimiz sorgu bize tek kayıt dönen sorgumuz. Dedik ki bu kayıt sana <strong>“Alfreds Futterkiste” </strong>olarak dönecek sen<strong> </strong>bunu<strong> → “Alfred’s Futterkiste” </strong>olarak güncelle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*KDCkydYZBxZQ1je6SFjBog.png" /></figure><p><strong>(Bu işlem kalıcıdır şu an 1 kayıt yarın 8388409 olabilir dikkat 😆)</strong></p><figure><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.reddit.com%2Fr%2FProgrammerHumor%2Fcomments%2Fkwb3el%2Fit_happend_to_me_also%2F&amp;psig=AOvVaw2eXsBkvFf2rS12WymM56A3&amp;ust=1644634015246000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCNDa8qTR9vUCFQAAAAAdAAAAABAi"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3iu8dsf3bFkb2VIV" /></a></figure><p>Son işleme geldik artık önceki yazıda yazmış olduğumuz sorguyu değiştirmeden sadece çalıştıracağız. Okumaya bu yazıdan başlayanlar için sorgu:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*MBi4zAW7Za7o6Va29nBVhQ.png" /></figure><p>Elde ettiğimiz sonucun ilk 20 satırı:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*m5eWR03WeKtngkAS5KU0aA.png" /></figure><p>İlk satıra dikkat edecek olursak sadece Alfred’s Futterkiste mevcut. Bu yüzden de kayıt sayısını 5 ve 1 diye ayırmadan LESS kategorisinde 6 tane olarak çıktıyı vermiş oldu.</p><p>Mini Keşif 3&#39;ün de sonuna gelmiş bulunduk. Umarım keyifli bir okuma olmuştur.</p><p>Görüşmek dileği ile 💃</p><p>Subquery için detaylı kaynaklar,</p><ul><li><a href="https://mode.com/sql-tutorial/sql-sub-queries/">Writing Subqueries in SQL | Advanced SQL - Mode</a></li><li><a href="https://learnsql.com/blog/correlated-sql-subqueries-newbies/">Correlated Subquery in SQL: A Beginner&#39;s Guide</a></li><li><a href="https://learnsql.com/blog/sql-subquery-examples/">5 SQL Subquery Examples</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fc681b78a88" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mini Keşif 2: CTE-Case When]]></title>
            <link>https://medium.com/@simgeerozel/mini-ke%C5%9Fif-2-cte-case-when-2795ce6cdf0f?source=rss-69d619126dc3------2</link>
            <guid isPermaLink="false">https://medium.com/p/2795ce6cdf0f</guid>
            <dc:creator><![CDATA[Simge Erözel]]></dc:creator>
            <pubDate>Thu, 03 Feb 2022 01:08:03 GMT</pubDate>
            <atom:updated>2022-02-03T01:08:03.686Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fmemegenerator.net%2Finstance%2F43698346%2Fcomputer-guy-sql-delete-all-the-rows&amp;psig=AOvVaw0WyFvbZB0vcmNBOwoyk0dS&amp;ust=1643935909312000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCICRr9qo4vUCFQAAAAAdAAAAABBE"><img alt="" src="https://cdn-images-1.medium.com/max/327/0*DBj7YyMTh6XGv7w_.jpg" /></a></figure><p>Selamlar,</p><p>Mini keşif serisinin yeni yazısıyla buradayım. Serinin ilk bölümünde ROW_NUMBER() fonksiyonunu ele almıştık. Bugün ele alacağım konuda biraz Common Table Expression(CTE) biraz Case When ele alacağız. Biraz da ROW_NUMBER() yazısında bir sonraki yazıda değiniriz dediğimiz <em>“Boş değerlerle ne yapacağız?”</em><strong> </strong>sorusuna yanıt arayacağız. Kullanacağımız veritabanı yine Northwind veritabanı ve ORDERS tablosu üzerinden devam edeceğiz.</p><p>Öncelikle senaryomuzu belirleyelim. ORDERS tablosu içinde yer alan ShipRegion sütununda bölge bilgisi var olanlardan NULL olanları ayrıştırmak ve ayrıştırdığımız bu gemileri nakliye ücretlerine göre sınıflandırmak istiyoruz.</p><p>SELECT çekip başlama vakti gelmiş demektir.</p><p><strong>SELECT TOP 20 * FROM ORDERS</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZG0UQRIkEB7cRzZGZ6Zohw.png" /><figcaption>830 satırlık verimizden 20 satırlık kesit</figcaption></figure><p>Şimdi veriye kısa bir bakış attığımızda ShipRegion kısmında “NULL” ifadeleri direkt göze çarpıyor. 830 satırlık verinin içinde ShipRegion için kaç tane NULL değer mevcut öncelikle bunu tespit edelim. Bunu nasıl yaparız?</p><p><strong>SELECT COUNT(*) AS MISSING FROM ORDERS WHERE ShipRegion IS NULL</strong></p><p>ShipRegion sütununda NULL olan değerlerin bana sayısını getirir misin? diye rica ettik ve bize bir dönüş yaptı. ShipRegion içinde bölgesi NULL olan 507 değer mevcutmuş.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/198/1*SeHivsctv8De4ymLM6P9LA.png" /></figure><p>Bu değerleri değiştirme şansımız var mı? Tabii ki var. Örneğin NULL değerleri . ile ISNULL() fonksiyonu bu noktada işimize yarayabilir. 2 parametre içerir: İçeriği değişecek sütun ve NULL ise değiştirilecek ifade.</p><p><strong>SELECT ShipRegion,ISNULL(ShipRegion,’.’) AS MISSING_VALUE FROM Orders</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/233/1*-5AjvvEgy0PD4_EBxkSzQg.png" /></figure><p>Sadece NULL ifadelerle uğraşmamız gerektiğinde işe yarayabilir. Ancak bize daha spesifik bir şey gerekiyor. Örneğin NULL değerler 0 ile değişsin ama aynı zamanda 0 ile değiştirdiğimiz NULL değerlere sahip gemileri nakliye ücretlerine göre sınıflandıralım. Bu noktada koşullara giriş yapmamız gerekecek gibi. Bunu nasıl yapabiliriz? İşte bu noktada Case When yapısı devreye giriyor.</p><p><strong>Nedir bu Case When?</strong></p><p>Case When belirlediğimiz koşullara göre çıktılar elde etmemizi sağlar. Case ifadesi ile başlayıp When ifadesinde koşullarımızı belirtiriz. Koşullarımıza artık bir dur demek için de End ifadesi kullanırız.</p><p>Baştan sona doğru gidecek olursak, gemileri nakliye ücretlerine göre sınıflandırmaktan bahsettim. Bu sınıflandırma için 3 grubumuz olsun.</p><p>Nakliye ücreti ortalama üzerinde olanlar için →High</p><p>Nakliye ücreti ortalama olanlar için → Average</p><p>Nakliye ücreti ortalamanın altında olanlar için → Less</p><p>O halde ortalama bir değer belirleyerek başlayalım. Hatta bunun için de AVG() fonksiyonundan yardım alalım.</p><p><strong>SELECT AVG(Freight) FROM ORDERS</strong></p><p>Bize dönen sonuç 78,2442 oldu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/179/1*4p3_WckalZCHplaS0U8Odw.png" /></figure><p>O zaman Case When yapımızı 78 üzerinden kuralım. ROUND() ile Freight değerlerimizi en yakın tam sayıya yuvarladık. Case When yapısıyla da şöyle dedik: Nakliye ücretlerim için ortalama değerim 78. Eğer ücret 78&#39;den büyük ise High, 78&#39;den küçük ise Less olsun ikisi de değilse Average olsun.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*VR60r13Hy_BeRVwmRb5WKA.png" /></figure><p>Çıktımızın ilk 20 satırı da şu şekilde,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*3MqAXZ-y32-lsxZR4ZQt9Q.png" /></figure><p>Şimdi sondan başa doğru ilerlediğimize göre sınıflandırma tamam ancak ShipRegion kısmında NULL olan değerleri ayrıştırmak istiyoruz. Minik bir Case When ifadesi ile de bunu yapma şansımız var.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*eba-XbCrMR3kVLyhT4fuYw.png" /></figure><p>CLASS sütununu az önce oluşturmuştuk ardından IS NULL kullanarak dedik ki ShipRegion sütununda NULL ifadesi görürsen bu 0 olsun. NULL olmayanlar da ShipRegion içerisinde olduğu gibi kalsın.</p><p>Çıktımız şu şekilde,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*KFyKyZjMXhabYe_S_6kwTQ.png" /></figure><p>Buraya kadar güzelce geldik. Nakliye ücretlerini sınıflandırdık ve NULL değerleri başka bir ifadeye dönüştürdük. Ancak raporumuzun çıktısında ShipRegion kolonunda NULL olmayan değerlerin de kayıtlarını içeriyor. Bunu nasıl ayrıştırabiliriz? Buraya kadar elimde olanı bırakmadan üzerine ekleyebilmek için Common Table Expression(CTE) yapısından yararlanabiliriz.</p><p><strong>Nedir bu CTE?</strong></p><p>Geçici olarak bir sorgunun sonucu elde tutup sonrasında daha karmaşık sorgular yazabilmemizi sağlar. WITH ile tanımlanır. WITH olmadan olmaz.</p><p>Senaryomuza geri dönecek olursak WITH ile başlayarak ORDERS tablomuz üzerinde CTE yapısını kurduk. Ardından öncelikle ShipRegion ifadesi NULL olup 0 atadığımız değerlerden oluşan çıktı sonucu için sorgunun sonunda yer alan WHERE MISSING=’0&#39; ifadesini kullandık. Sonrasında Group By ifadesi ile CLASS kolonuna göre gruplama yaptık ve COUNT(*) ifadesi ile sınıflandırma içerisindeki MISSING değerlerinin sayısını elde ettik.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*U7DizAZ8qU0_thvOhdquTA.png" /></figure><p>Çıktıyı incelediğimizde LESS sınıfında olup bölgesi NULL olan 357, HIGH sınıfında olup bölgesi NULL olan 146 ve son olarak AVERAGE sınıfında olup bölgesi NULL olan 4 kaydımız bulunuyormuş.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/172/1*-dYJ_WbBJ7EsriWEpxFYSg.png" /></figure><p>Senaryomuzun son haline ulaşmak için buraya ShipName kolonunu da eklersek,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*xLV7JjmzLvdejcNISYqRUg.png" /></figure><p>109 kayıtlık çıktımızın belirli bir kısmı aşağıdaki gibidir. Yorumlayacak olursak <strong>“Ana Trujillo Emparedados y helados”</strong> için toplam 4 kayıt mevcutmuş ve bu kayıtların hepsinin nakliye ücreti LESS sınıfında ya da <strong>“Antonio Moreno Taquería” </strong>için toplamda 7 kayıt var. Bu kayıtlardan 6 tanesinin nakliye ücretinin LESS,1 tanesinin HIGH sınıfında olduğu görülüyor. Bu çıktı da ürün dağılımını hariç tuttuk ve bu sonuçları elde ettik. Ancak çıktıda dikkat edilmesi gereken bir nokta var. “<strong>Alfreds Futterkiste” </strong>ve<strong> “Alfred’s Futterkiste” </strong>birbirinin aynısı ancak ‘s kısmından dolayı ayrı olarak algılanmış. Bununla ilgili ne yapılabilir acaba? Ben de öğrenip geleyim.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*dwn-ELJJXJKBYqWKgNDUSA.png" /></figure><p>Yazının sonuna ulaştık. Bir sonraki yazıda görüşmek dileği ile 🍀</p><p>Çok geniş kapsamlı olan CTE dünyası için detaylı bilgi almak isteyenler için,</p><p><strong>Kaynakça</strong></p><p><a href="https://www.sqlshack.com/sql-server-common-table-expressions-cte/">https://www.sqlshack.com/sql-server-common-table-expressions-cte/</a></p><p><a href="https://www.mssqltips.com/sqlservertip/6861/cte-in-sql-server-examples/">https://www.mssqltips.com/sqlservertip/6861/cte-in-sql-server-examples/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2795ce6cdf0f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mini Keşif 1: ROW_NUMBER()]]></title>
            <link>https://medium.com/@simgeerozel/mini-ke%C5%9Fif-1-row-number-a1b000d8bb65?source=rss-69d619126dc3------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1b000d8bb65</guid>
            <dc:creator><![CDATA[Simge Erözel]]></dc:creator>
            <pubDate>Wed, 26 Jan 2022 19:50:10 GMT</pubDate>
            <atom:updated>2022-01-26T19:50:10.486Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fmemegenerator.net%2Finstance%2F45598718%2Fpicardfacepalm-saw-an-sql-query-starting-with-select-&amp;psig=AOvVaw1eeyoCEmR5c4LS6361vS3W&amp;ust=1643312906285000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCJiRmfOX0PUCFQAAAAAdAAAAABAD"><img alt="" src="https://cdn-images-1.medium.com/max/512/0*_App60wP5Zu8tn6s.jpg" /></a></figure><p>Selamlar,</p><p>Bugün buraya Row_Number() ile geldim. Nedir bu Row_Number?</p><p>Row_Number(), elimizdeki veri kümesine belirlediğimiz kriter üzerinden gruplara bölen ve her değer için numerik bir değer üreten sıralama fonksiyonlarından biridir. Bugün bu fonksiyonu MSSQL üzerinden inceleyeceğiz.</p><p>O halde başlayalım.</p><p>Kullanacağımız veritabanı meşhur Northwind veritabanı olacak. Şöyle bir senaryomuz olduğunu hayal edelim. Elimizde gemi nakliye ve sipariş bilgilerine ait bir veri var. Bu verinin içinde sipariş tarihi, siparişin verildiği tarih, yüklenmesi gereken tarih, nakliye ücreti vb. pek çok bilgi bulunuyor. Bizim senaryomuz ise şöyle olsun şehir bazında en yüksek nakliye ücretlerini belirleyelim.</p><p>Öncelikle minik bir select ifadesi çekip veriye göz atalım. (Evet ben de select ifadesini SELECT yazmazsam iyi hissetmeyenlerdenim 💃)</p><p><strong>SELECT TOP 20 * FROM Orders</strong></p><p>Verinin tamamı 830 satırdan oluşuyor. İlk 20 satırını gözden geçirdikten sonra öncelikle üzerinde çalışmak istediğimiz sütunları belirleyelim. Bu sütunlar ShipCity,ShipName,Freight ve OrderDate olsun. ShipRegion sütununda da boş değerler varmış bir sonraki yazıda bunları da doldururuz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*30jFF9DvvjEFK-AdDFmKpQ.png" /></figure><p>Sütunları da belirlediğimize göre ROW_NUMBER() ile tanışalım.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*w1eESqQ4pc2ibl16itZ5Ng.png" /></figure><p>ROW_NUMBER() gelirken yanında OVER ve ORDER BY gelmeden yapamaz. Over dışındaki operatörlerinden bir diğeri de PARTITION_BY ifadesidir. Ancak kullanımı opsiyoneldir.</p><p>Peki şimdi nasıl bir sonuç elde etmeyi umuyoruz? ORDER BY ifadesine odaklanırsak Freight (nakliye ücret) bilgisi içeren sütunumuzun en yüksekten en düşüğe doğru sıralanacağını bekliyoruz. Peki başka?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*9a8TFKB57UyoBfE_O93TCg.png" /></figure><p>ROW_NUMBER() hemen Freight öncesinde yerini aldı ve numerik ve artan bir şekilde değer üretmeye başladı. Peki ROW_NUMBER burada ne yaptı? Az önce şunu dedik benim elimde nakliye ücretleri var ve ben bunları yüksekten düşüğe sıraladım. Sen de gel benim en yüksek değerime 1 de. Şimdi bu noktaya kadar iyi hoş geldik ama bir gruplama yapmamız gerekecek. Bunu nasıl yapacağız? İşte o noktada PARTITION BYdevreye giriyor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*GmEwWLf7f2GVKCDE6wut-A.png" /></figure><p>PARTITION BY ifadesini kullanarak ShipCity sütununa göre bir gruplama işlemi yaptık. Nasıl bir sonuç elde ettik? PARTITION_BY şehirlere göre gruplama yaptıktan sonra ROW_NUMBER() da kendi içinde bir sıralamaya girişti. Aachen şehri için 6 kayıt mevcutmuş 1&#39;den 6&#39;ya kadar sıraladı. Sıradaki şehir gelince de onun mevcut kayıt sayısına göre sıralamasını tekrar 1&#39;den başlayarak yapmaya başladı. Buradaki dikkat noktası ise şu: ROW_NUMBER() fonksiyonunun 1 dediği her kayıt Freigh değerinin o grup içindeki maksimum değerini ifade ediyor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*EZ6xf01dVCB_okvmYJXTQA.png" /></figure><p>O halde ufak bir SELECT ve WHERE ifadesiyle senaryomuzun sonucuna ulaşabiliriz. Bizim senaryomuz her şehir en yüksek nakliye ücretlerini belirlemekti.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*oRkRcNGPVde2Cfz34RMnwg.png" /></figure><p>WHERE Hi_Row_Number=1 dediğimizde sadece en yükseklerden oluşan çıktıyı bize böylelikle getirmiş oldu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*Ne1FmFv9A28D0JMRjwSIvw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*gn7kPf1SWJeybOWaAodVKA.png" /></figure><p>Yazının sonuna geldik, bir sonraki yazıda görüşmek dileği ile 💃</p><p>Farklı örnekler için,</p><h4>Kaynakça</h4><p><a href="https://www.sqlservertutorial.net/sql-server-window-functions/sql-server-row_number-function/">https://www.sqlservertutorial.net/sql-server-window-functions/sql-server-row_number-function/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1b000d8bb65" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Makine öğrenmesini unuttum. Bu veriler nasıl analiz edilecek?]]></title>
            <link>https://medium.com/@simgeerozel/makine-%C3%B6%C4%9Frenmesini-unuttum-bu-veriler-nas%C4%B1l-analiz-edilecek-c725f91a12c0?source=rss-69d619126dc3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c725f91a12c0</guid>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Simge Erözel]]></dc:creator>
            <pubDate>Wed, 15 Sep 2021 15:15:20 GMT</pubDate>
            <atom:updated>2021-09-15T15:15:20.731Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Kaynak:" src="https://cdn-images-1.medium.com/max/500/1*SaOSGiX-UWg2eX27JN7X9w.jpeg" /><figcaption>Kaynak: <a href="https://towardsdatascience.com/without-theory-data-science-is-just-about-cat-memes-5c3c3948d84f">https://towardsdatascience.com/without-theory-data-science-is-just-about-cat-memes-5c3c3948d84f</a></figcaption></figure><p>Makine öğrenimi dünyasında bir gün uyandık ve makine öğrenimini unutmuşuz. Elimizde de bir veri var. Ee ne yapacağız? Veri varsa analizi de vardır. Bir yerde veri varsa umut vardır diyip yola devam edeceğiz. Biri kural tabanlı sınıflandırma mı dedi? Temel prensip “if-else” kuralları üzerine kurulu olup tanımlayıcı ve sınıflandırıcı model oluşturma amacı taşımaktadır.</p><p>Öncelikle problemi ele alalım. Bir oyun şirketi müşterilerin özelliklerinden yola çıkarak yeni müşteri tanımlamaları oluşturmak ve bu tanımlamalar üzerinden müşterilerin şirkete ortalama ne kadar kazandırabileceğini tahmin etmek istemektedir.</p><p><strong>Veri Seti Değişkenleri</strong></p><p>Price: Müşterinin harcama tutarını</p><p>Source: Müşterinin bağlandığını cihazın türünü</p><p>Sex: Müşterinin cinsiyetini</p><p>Country: Müşterinin ülkesini</p><p>Age: Müşterinin yaşını</p><p>ifade etmektedir.</p><p><strong>Verinin Okutulması ve Temel İşlemler</strong></p><p>Öncelikle veri analizinin vazgeçilmezlerinden pandas kütüphanesini import edelim ve read.csv fonksiyonuyla veriyi okutalım.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cekx2yvTv3ecpkw4XMFBYQ.png" /></figure><p>Verinin ilk 5 gözlem değerine head() fonksiyonu yardımıyla göz atılabilir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nRokxZh6llcfvPJZSqoVpg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*lG06JCIae9vxTK3TPcFAdw.png" /></figure><p>Verinin gözlem değerleri ve değişkenleri hakkında bilgi almak istediğimizde shape yardımcı olabilir. Verimiz 5000 gözlem biriminden ve 5 değişkenden oluşmaktadır.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qASavTKeqnktj5YyYa5jIw.png" /></figure><p>Sayısal değişkenlerin betimsel istatistiklerine göz atmak için,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bgbrWFBfxlAHKIaHC4TXsQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*sbvbKwT4JwWD65CSbQmsfQ.png" /><figcaption>Age ve Price değişkenlerinin betimsel istatistikleri</figcaption></figure><p>Veriden göz ucuyla bilgileri topladıktan sonra soruları sormaya başlamamız gerekiyor.</p><p>Kaç tane unique Source var? Frekansları nasıl ifade edilebilir?</p><p>Burada unique kavramıyla sorgulanmak istenen Source değişkenindeki eşsiz sınıfların sayısıdır. Bu eşsiz sınıfların frekanslarına ulaşmak için de value_counts() kullanılabilir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YLFySHP463CKeGlAHSppdg.png" /></figure><p>Soru sormaya devam ediyoruz. Elimizdeki değişkenlerden biri de ülke değişkeni. Ülke değişkenine göre Price ortalamalarını nasıl elde edebiliriz?</p><p>Ülkelere göre gruplayıp agg fonksiyonu yardımıyla Price ortalamalarını hesapladık.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lviFQeg-JrH6yrWnFvw7FQ.png" /></figure><p>Çıktımızın sonucuna göz atacak olursak,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*fWWuhGADNdRn7dYoFs9pkg.png" /></figure><p>Bu kırılımları biraz daha fazlalaştıralım. Country, Source,Sex,Age bazında ortalama kazançları görmek istersek?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5oykw7apalGJqJq6mo-IiQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*GV4ncCF1tb9qI1_lO1CpLw.png" /></figure><p>Bu çıktıyı da elde ettikten sonra güzel metodlardan biri olan sort_values metodu ile elde ettiğimiz çıktıyı azalan şekilde Price değişkenine göre sıralamak istersek?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iMKIX00ZC7RAmEYvYe7RUg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*6_2FLL7C6zVrQTzHCWVG6A.png" /></figure><p>Buraya kadar yaptığımız işlemlerde ele alınması gereken bir diğer konu ise şudur: Price değişkeni dışındaki diğer değişkenlerin index isimleri olarak gözükmesi. Onların suçu ne? Onları da değişken isimlerine çevirelim. reset_index() yardıma koşar. inplace=True ise bu işlemi kalıcı hale getirir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*riS7_dlXFZCRnrY8XLLSag.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*5YWn7rZG241bJjtqSsKMUw.png" /></figure><p>Peki biraz daha ilerletelim konuyu. Verimizde Age değişkeni mevcut. Ancak bu sayısal değişken ve sunacağımız raporda yaşları kategorize etsek ve bunun üzerinden konuşsak güzel olmaz mı? O halde Age değişkenini kategorik değişkene çevirmeliyiz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IHsbtHho3QSs5HaiazT7mg.png" /></figure><p>Öncelikle yaş değişkenini böleceğimiz aralıkları belirledik. Ardından <strong>labels</strong> değişkeninde böldüğümüz aralıkların neye göre isimlendirileceğini belirledik. <strong>cut</strong> fonksiyonu yardımıyla da Age değişkenini bölme işlemini gerçekleştirdik.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*bDL0zRwlElDgn9WUZnygSA.png" /></figure><p>Yeni seviye tabanlı müşterileri artık tanımlayıp veri setine ekleme aşamasına geçebiliriz. List comprehension yapısı kullanarak customer_leved_based değerlerini oluşturduktan sonra tekilleştirme işlemine giderek Price edğişkenine göre ortalama aldık.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QwUXzaU9-Rb_ZZEyZjuMdQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*VZ8x6d5EF-bIyNli3tdmhA.png" /></figure><p>Peki yeni müşterileri segmentlere ayırmak istersek? qcut fonksiyonu burada yardıma koşar. Müşteriler için 4 segmentimiz olsun (A-B-C-D).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Llf3f0Wmmi6HSaOg3kFsug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*COfhwoBNd3lZcYLpIrmLOQ.png" /></figure><p>Segmentleri, Price değişkeni açısından gözlemlemek istersek?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CRPuTcqr4Mqbp3M1VGQsAg.png" /></figure><p>Aşağıda yer alan çıktıda ortalamalar açısından incelediğimizde D segmenti 29.20 ortalama ile diğer segmentlerin gerisinde kalmıştır. Bu noktada D segmentindeki müşteriler firmaya en az kazandıran grubu temsil etmektedir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*MMbQdtRCIv2MmrN0JEfgpQ.png" /></figure><p>Bu işlemlerin ardından biraz daha kurcalamak istediğimizi varsayalım. Örneğin, 38 yaşında IOS kullanan bir Türk kadınının hangi segmente ait olduğunu ve ortalama kazandırabileceği gelir ne kadar olabilir diye sorarsak?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sSI6orlsAMUDf2E1AKUEQg.png" /></figure><p>İlgili kullanıcının D segmentinde yer aldığı görülmektedir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*wCCSq4XCOp0vgK-Rh4R-sA.png" /></figure><p>Örneği çoğaltıp 25 yaşında ANDROID kullanan bir Fransız erkeğinin hangi segmente ait olduğunu inceleyelim.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qCx7BfHzcmxb0HPLX7-YTw.png" /></figure><p>İlgili kullanıcının C segmentine ait olduğu görülmektedir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B6h8e95JTG2mM-ROkVdtSQ.png" /></figure><p>Son bir örnek daha yapalım ve 50yaşında ANDROID kullanan Kanadalı bir erkeğin hangi segmente ait olduğunu inceleyelim.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KUiwXoOAif0jnZTf06n6sA.png" /></figure><p>İlgili kullanıcının A segmentine ait olduğu görülmektedir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y5E295i1H5Uv7ow3QE4AsA.png" /></figure><p>Bu yazıda segmentlere göre kural tabanlı sınıflandırmayı ele aldık ve müşterilerin ortalama kazandırabileceği gelirleri hesapladık. Tabii ki örnekler çoğaltılabilir ve yeni bakış açıları eklenebilir. Makine öğrenmesine gelmeden önce veriyle neler yapılabileceğini ele aldık. Bir sonraki yazıda görüşene dek veriniz bol olsun. :)</p><p>Kaynak: <a href="https://www.veribilimiokulu.com/">https://www.veribilimiokulu.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c725f91a12c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>