<?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 Alaaelnakeeb on Medium]]></title>
        <description><![CDATA[Stories by Alaaelnakeeb on Medium]]></description>
        <link>https://medium.com/@alaaelnakeeb81?source=rss-9f4c5ff2cf48------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_p7a6xEGjnc1dEeIBbf8cA.png</url>
            <title>Stories by Alaaelnakeeb on Medium</title>
            <link>https://medium.com/@alaaelnakeeb81?source=rss-9f4c5ff2cf48------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 18:22:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alaaelnakeeb81/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[Looking Beyond Revenue: The Question That Changed How I Read Data.]]></title>
            <link>https://medium.com/@alaaelnakeeb81/looking-beyond-revenue-how-marketing-analysts-actually-read-campaign-performance-b37bdc65738a?source=rss-9f4c5ff2cf48------2</link>
            <guid isPermaLink="false">https://medium.com/p/b37bdc65738a</guid>
            <dc:creator><![CDATA[Alaaelnakeeb]]></dc:creator>
            <pubDate>Thu, 25 Jun 2026 13:20:02 GMT</pubDate>
            <atom:updated>2026-06-25T13:23:05.122Z</atom:updated>
            <content:encoded><![CDATA[<p>Revenue is the last number you should look at — not the first.</p><p>One of the biggest mistakes I made early in my analytics career was opening every campaign report and going straight to revenue.</p><p>If it went up, the campaign succeeded. If it dropped, something went wrong.</p><p>It took me a while to realize that revenue is only the ending of the story. And endings without context mean nothing.</p><h3>The dashboard that changed my perspective</h3><p>I was reviewing a campaign once and saw this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*ts_XCGXqPwGhBhWrGqMSiw.png" /></figure><p>At first glance this looked like a disaster. Revenue was down 40%.</p><p>But then I saw that clicks were up 120%. Impressions were up. CTR was up. The campaign was performing better than ever at getting people to the site so why was revenue falling?</p><p>That question led me to a completely different way of reading data.</p><blockquote>The insight: when upper-funnel metrics improve but lower-funnel metrics decline, the problem almost always lives between those two points — not in the campaign itself.</blockquote><h3>Metrics are not independent</h3><p>Most people analyze campaigns by looking at each metric separately. Revenue. Clicks. CTR. Cost. But marketing metrics are connected — they tell a story only when viewed together.</p><p>If impressions rise and CTR rises, the campaign is attracting attention. But if revenue falls while those metrics improve, the issue probably exists after the click — on the landing page, in the checkout flow, or in the quality of the audience being reached.</p><h3>Reading the funnel instead of the dashboard</h3><p>When I analyze a campaign today, I always think in terms of a funnel. Here is what a healthy funnel looks like vs a broken one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*D5R5Bx4HPZdGwW0O0czq6w.png" /></figure><p>Whenever a metric changes, I ask one question: <strong>where in the funnel did this happen?</strong> That single question leads to most of the valuable insights.</p><h3>Why high CTR does not always mean success</h3><p>CTR is one of the most celebrated metrics in digital marketing. But clicks are not the goal — business outcomes are.</p><p>I once found that the campaigns with the highest CTR were not generating the most revenue. Those campaigns were great at generating curiosity. They were much worse at generating action. Getting attention and creating value are not the same thing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*dGrJ4aVdSkkxC6-NVpgw7Q.png" /></figure><h3>How recommendations are actually made</h3><p>Recommendations do not come from metrics — they come from patterns. Every recommendation I make follows three steps.</p><p>First, identify the observation: revenue decreased 40%. Second, investigate the reason: clicks increased 120%, so traffic acquisition is healthy — the issue is post-click. Third, propose the action: review landing page performance, conversion rates, and audience quality.</p><h3>Looking beyond campaign-level metrics</h3><p>A campaign might perform well overall but struggle on mobile. Another might have lower traffic but significantly higher conversion rates. These details reveal opportunities that are invisible in summary reports.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*hzKSObr55jjzySbIl8nHZg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b37bdc65738a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Summary of Chapter 2: Kimball Dimensional Modeling Techniques]]></title>
            <link>https://medium.com/@alaaelnakeeb81/summary-of-chapter-2-kimball-dimensional-modeling-techniques-cf81cc6d96c7?source=rss-9f4c5ff2cf48------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf81cc6d96c7</guid>
            <category><![CDATA[kimball-book]]></category>
            <category><![CDATA[dimensional-modeling]]></category>
            <category><![CDATA[data-warehouse]]></category>
            <dc:creator><![CDATA[Alaaelnakeeb]]></dc:creator>
            <pubDate>Sun, 08 Mar 2026 15:26:02 GMT</pubDate>
            <atom:updated>2026-03-08T15:26:02.153Z</atom:updated>
            <content:encoded><![CDATA[<p>When building a data warehouse, the way you structure your data can make or break your analytics. The <strong>Kimball Group</strong> has been teaching dimensional modeling for decades, and their techniques are now industry standards.</p><p>Let me walk you through the Fundamental Concepts with simple explanations:</p><blockquote>1. Understand the Business and Data Reality</blockquote><p>Before designing anything, you need to <strong>know what the business really wants</strong> and <strong>what data you actually have</strong>.</p><blockquote>2. Collaborate Through Workshops</blockquote><p>Dimensional models should <strong>never</strong> be designed in isolation. Bring business experts and data stewards together. These interactive sessions help refine requirements and ensure everyone agrees on the model.</p><blockquote>3. The Four-Step Dimensional Design Process</blockquote><p>Every dimensional model follows four key steps:</p><ol><li><strong>Choose the business process</strong> — what operational event you’re analyzing.</li><li><strong>Declare the grain</strong> — what one row in your fact table represents.</li><li><strong>Identify dimensions</strong> — the “who, what, where, when, why, how” context.</li><li><strong>Identify facts</strong> — the numeric measurements generated by the process.</li></ol><blockquote>Note: what is meant by Grain?!</blockquote><p>The <strong>grain</strong> is crucial; it defines exactly what each fact table row represents.</p><ul><li>Atomic grain: one product per transaction.</li><li>Summary grain: total sales per day per store.</li></ul><h3>Dimensions for Descriptive Context</h3><ul><li>Dimensions are what give your numbers meaning. They answer the “who, what, where, when, why, and how.”</li><li>Dimension tables contain the <strong>descriptive attributes used by BI for filtering and grouping the facts</strong>.</li></ul><p><strong>Example:</strong> The <strong>Customer</strong> dimension might include Name, Region, Age, and Loyalty Tier. These attributes let you filter, group, and analyze your sales.</p><h3>Facts for Measurements</h3><ul><li>Facts are the measurements that result from a business process event and are almost always numeric, they usually answer questions like <strong>“how much?”</strong> or <strong>“how many?”</strong>.</li><li>it also includes Foreign Keys that link to the relevant dimension tables, providing context for analysis.</li></ul><p><strong>Example:</strong> <strong>Quantity sold, revenue, or discount per product sold</strong>.</p><blockquote>So essentially, facts <strong>measure the process</strong>, while dimensions provide <strong>the context</strong>.</blockquote><p>When we talk about dimensional modeling in data warehousing, two terms come up again and again: <strong>Star Schemas &amp; OLAP Cubes</strong></p><blockquote>What is a Star Schema?</blockquote><p>A <strong>Star Schema</strong> is a way of organizing data in a relational database to support fast analytics.</p><p>✔ One central <strong>Fact Table</strong> (contains numbers you care about)<br> ✔ Multiple <strong>Dimension Tables</strong> (provide context)</p><pre>          Product<br>             |<br>Customer — Fact Sales — Time<br>             |<br>          Store              // look like the star</pre><blockquote>What is an OLAP Cube?</blockquote><ul><li>An <strong>OLAP Cube</strong> is a multi-dimensional structure <strong><em>built on top of star schemas,</em></strong> that stores data in a way that makes many analytics queries very fast.</li><li>OLAP Cubes are <strong>pre-aggregated</strong> and often stored in a <strong>columnar format</strong> to make slicing and dicing lightning fast.</li></ul><blockquote>Note: In the past,<strong> </strong>OLAP cubes<strong> were built on a nightly schedule on top of star schemas. </strong>This approach improved query performance but meant analytics data was usually one or two business days old.</blockquote><blockquote>Today, <strong>modern cloud data warehouses like snowflake</strong> use scalable, distributed compute to <strong>run analytical queries efficiently directly on star schemas.</strong> As a result, data can be updated throughout the day, allowing reports to refresh frequently without relying on traditional OLAP cubes.</blockquote><p>Read more: <a href="https://www.reddit.com/r/dataengineering/comments/1eevtwi/what_is_the_difference_between_star_schemas_and/">Reddit/Comments about OLAP </a>Cubes, Also I have explained it briefly in the summary 1.</p><h4>Basic Fact Table Techniques</h4><p>A Fact Table is the central table in a data warehouse schema (primarily in star and snowflake schemas). It stores quantitative data (measures) about a business process and links to dimension tables through foreign keys.</p><blockquote>Structure of a Fact Table</blockquote><ol><li>Measures (Quantitative Data): Contains numeric values for analysis as (Unit Sold, Sales Amount)</li><li>Foreign Keys: Fact tables use foreign keys to link to dimension tables.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qUssFmpbHV6m0SgOfKgxtQ.png" /></figure><blockquote>Additive, Semi-Additive, and Non-Additive Measures</blockquote><p>There are three types of facts in a fact table, classified based on whether <strong>the stored measures can be aggregated across different dimensions.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*3zmCzTvqt-UjvGLZX5Oxbg.png" /></figure><p>There are just three fundamental types of fact tables: transaction, periodic snapshot, and accumulating snapshot.</p><blockquote>Conformed Facts</blockquote><p>Conformed facts are measures that appear in multiple fact tables with the <strong>same business meaning and calculation.</strong></p><ul><li>If the separate fact definitions are consistent, the conformed facts should be identically named<em> (e.g., </em><strong><em>Total Sales </em></strong><em>means the same thing everywhere)</em></li><li><strong>but if they are incompatible, they should be differently named to alert the business users and BI applications</strong><br> <em>(e.g., Revenue_With_Tax vs Revenue_Without_Tax)</em></li></ul><blockquote>Nulls in Fact Tables</blockquote><ul><li><strong>Null-valued measurements behave gracefully in fact tables.</strong> The aggregate functions (SUM, COUNT, MIN, MAX, and AVG) all do the “right thing” with null facts.</li><li>However, <strong>nulls must be avoided in the fact table’s foreign keys</strong> because these nulls would automatically cause a referential integrity violation.</li></ul><blockquote>Types of Fact Tables</blockquote><p>There are several types of fact tables, each serving different purposes in a data warehouse:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*E25YuIM_9sm0G7Qlbg4WkQ.png" /><figcaption>types of fact tables</figcaption></figure><h4>Dimension Table Structure :</h4><p>A dimension table contains <strong>a single primary key </strong>, which is<strong> linked to fact tables as a foreign key.</strong> This connection ensures that each fact row is associated with the correct descriptive context.</p><p>Dimension tables are typically:</p><ul><li>Denormalized.</li><li>Rich in descriptive (text) attributes.</li><li>They don’t just store codes; they store <strong>meaningful business descriptions</strong>. These attributes are what users <strong>filter, group by, and display in BI tools. </strong>In fact, most report labels come directly from dimension attributes.</li></ul><blockquote>Dimension tables often <strong>use surrogate keys</strong> instead of natural keys from source systems , a random or sequential number generated inside the data warehouse , which keeps the tables <strong>stable and easy to work with</strong>, even if business data changes over time.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Urloyk3zadoNLGI_5a-fw.png" /></figure><blockquote>Natural, Durable, and Supernatural Keys</blockquote><p>In dimensional modeling (as defined by Ralph Kimball), we cannot fully rely on natural keys because they are controlled by business systems and may change.</p><ul><li>For example, an employee might leave and return with a new <strong>Employee_ID</strong>. If we depend only on that <strong>ID, the Data Warehouse may treat the same person as two different employees.</strong></li></ul><blockquote>To avoid this, we separate identity into two levels:</blockquote><ul><li><strong>Surrogate Key</strong>: a warehouse-generated key that represents a specific version of the entity (used to track changes over time).</li><li><strong>Durable Key</strong>: a permanent warehouse-generated key that represents the entity itself and never changes, even if the natural key does.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SwQeL6BDdFdRELYGM0czOw.png" /></figure><h3>Types of Dimensions in Dimensional Data Modeling</h3><blockquote>Conformed Dimension</blockquote><p>A conformed dimension <strong>is a dimension that is shared by multiple Facts in the data warehouse.</strong></p><ul><li>The definition and structure of the conformed dimension need to be consistent across all the fact tables that use it, so the facts can be categorized across the Dimensional Modeling.</li></ul><blockquote>Outrigger Dimension</blockquote><ul><li>Outriggers are dimension tables <strong>that are shared across more than one dimension in a dimensional data model.</strong></li><li>An outrigger table is generally included in a hierarchy, although it is not directly linked to the Fact Table.</li></ul><blockquote>Shrunken Dimension</blockquote><ul><li>It is a subset of a larger dimension in dimensional modeling<strong>. It contains only a subset of the attributes of the larger dimension</strong> and is used in a specific context.</li></ul><p>An example of a shrunken dimension could be a product dimension containing only the attributes relevant to a specific store location.</p><blockquote>Role-Playing Dimensions</blockquote><ul><li>This dimension can be <strong>used in multiple ways within the same table and other dimensional data model tables as well.</strong> It is essentially the same dimension but is used to represent different aspects in dimensional modeling.</li></ul><p>Sometimes one fact table has multiple dates:</p><ul><li><strong>Order Date, Ship Date, Delivery Date</strong></li></ul><p>All of them connect to the same Date Dimension.</p><p><strong>The same physical table is reused, but each connection represents a different business role.</strong></p><blockquote>Degenerate Dimension</blockquote><p>A <strong>degenerate dimension</strong> is a dimension that has <strong>no descriptive attributes</strong>, only a key.</p><ul><li>Example: <strong>Invoice Number</strong> in a fact table with multiple line items.</li><li>The invoice number itself is stored in the fact table, without a separate dimension table.</li><li>It allows grouping, filtering, and analysis at the transaction level.</li></ul><p><em>In short: </em>A degenerate dimension is derived from a Fact Table and is known as a Fact Dimension in a dimensional data model. <strong>It contains facts used for grouping or filtering the data unrelated to any other dimension.</strong></p><blockquote>Junk Dimensions</blockquote><p>A dimension that <strong>contains low cardinality facts is put together into one dimension in the dimensional modeling data warehouse</strong>. It is used to reduce the number of dimensions in a fact table and to simplify the data model.</p><h4>Flattened Dimensions, Multiple Hierarchies, and Clear Attributes :</h4><ul><li>In dimensional modeling, we <strong>denormalize dimension tables</strong> to make them simpler and faster.</li><li>Instead of splitting hierarchical data across multiple tables (like City → State → Country), we store all related attributes in a single flattened dimension row. This reduces joins, improves performance, and makes queries easier for business users.</li></ul><p>A single dimension can also contain <strong>multiple hierarchies</strong>. For example, a Date Dimension may support both:</p><ul><li>Day → Month → Year</li><li>Day → Week → Fiscal Period</li></ul><p>All these hierarchies can coexist in the same table, allowing flexible analysis without additional complexity.</p><p><strong>In short, dimensional modeling prioritizes: simplicity, clarity, and performance.</strong></p><blockquote>Null Attributes in Dimensions</blockquote><ul><li>Dimension attributes should never contain NULL values.</li></ul><p>If a value is missing or not applicable, use a clear text like:</p><ul><li>&quot;Unknown&quot;</li><li>&quot;Not Applicable&quot;</li></ul><p>Because different databases handle NULL differently in grouping and filtering, which can cause inconsistent results.</p><blockquote>Calendar Date Dimension</blockquote><ul><li>Almost every fact table connects to a Date Dimension.</li></ul><p>Instead of calculating things like:</p><ul><li>Week number, Fiscal period, Holiday indicator</li></ul><p><strong>We store them as columns inside the Date Dimension.</strong></p><p><strong>Sometimes the primary key can be a smart key like </strong><strong>YYYYMMDD instead of a surrogate key.</strong></p><h4>Integration via Conformed Dimensions</h4><p>In a data warehouse, conformed dimensions allow multiple fact tables like Sales, Returns, and Inventory , to use the same dimension table (e.g., Dim_Product). This enables unified reporting, consistent analytics, and easier drill-across between business processes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y1Jw_REc89wnMSE2rK46BQ.png" /></figure><h4>** Shrunken Dimensions, Drilling Across, &amp; Value Chain**</h4><blockquote>Shrunken Dimensions</blockquote><p>A <strong>Shrunken Dimension</strong> is a smaller, aggregated subset of the base dimension, containing fewer rows or columns for higher-level analysis—for example, Brand + Month or Brand + Category.<br>The arrows from the shrunken dimension show that it is <strong>shared in Drill-Across Reports</strong>.</p><blockquote>Drilling Across</blockquote><p>Multiple <strong>Fact Tables</strong> <strong>(e.g., Fact_Sales, Fact_Returns, Fact_Inventory)</strong> are linked via the <strong>same conformed dimensions</strong> (like Product Category).<br>A <strong>Drill-Across Report</strong> aligns the data from all fact tables on the shared dimension, producing a unified report:</p><p><strong>This is exactly what Drilling Across means: combining different fact tables along the same shared attributes.</strong></p><blockquote>Value Chain</blockquote><ul><li>The <strong>Value Chain</strong> represents the primary business processes of the company.<br>Example: <strong>Purchase Orders → Inventory Receipts → Retail Sales → Customer Returns</strong></li><li>Each step produces unique metrics and typically generates its own <strong>atomic fact table</strong>.</li><li>Fact tables from different steps can still be analyzed together using <strong>conformed dimensions</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ekyHvvt5wGsVBa6CYx3EVg.png" /></figure><ul><li><strong>Shrunken Dimension</strong> → subset of a larger dimension in dimensional modeling. It contains only a subset of the attributes of the larger dimension and is used in a specific context.</li><li><strong>Drilling Across</strong> → combining multiple fact tables using shared dimensions to produce unified reports.</li><li><strong>Value Chain</strong> → a sequence of business processes, each generating distinct fact tables that can be analyzed individually or together.</li></ul><h3>Reference</h3><blockquote><em>Kimball, R. &amp; Ross, M. The Data Warehouse Toolkit: The Definitive Guide to Dimensional Modeling. Wiley, 3rd Edition.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf81cc6d96c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Summary of Chapter 1 : Data Warehousing, Business Intelligence, and Dimensional Modeling Primer]]></title>
            <link>https://medium.com/@alaaelnakeeb81/summary-of-chapter-1-data-warehousing-business-intelligence-and-dimensional-modeling-primer-ff943f79cadf?source=rss-9f4c5ff2cf48------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff943f79cadf</guid>
            <category><![CDATA[data-warehouse]]></category>
            <category><![CDATA[dimension-model]]></category>
            <dc:creator><![CDATA[Alaaelnakeeb]]></dc:creator>
            <pubDate>Wed, 29 Oct 2025 12:49:39 GMT</pubDate>
            <atom:updated>2025-10-29T13:03:02.697Z</atom:updated>
            <content:encoded><![CDATA[<h3>Summary of Chapter 1 : Data Warehousing, Business Intelligence, and Dimensional Modeling Primer</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*bU1qRVgmi333YnkCQvf0qQ.png" /><figcaption>The Data Warehouse Toolkit, 3rd Edition by Ralph Kimball and Margy Ross</figcaption></figure><p>Before we dive into the details of dimensional modeling, it’s important to step back and reflect on <strong>why organizations invest in Data Warehousing (DW) and Business Intelligence (BI) systems in the first place</strong>.</p><p>If you walk through the halls of any company and listen carefully to managers, you’ll hear the same recurring themes that have existed for decades:</p><ul><li>We collect massive amounts of data, but we can’t access it, A core goal of DW/BI is to make data <strong>readily available</strong> across the business.</li><li>We need to slice and dice the data every which way.</li><li>Business people need to get at the data easily, to <strong>explore and analyze data directly</strong> through intuitive tools without waiting for technical support.</li><li>Just show me what is important, where BI systems highlight <strong>key performance indicators (KPIs).</strong></li><li>We spend entire meetings arguing about who has the right numbers rather than making decisions.</li><li>We want people to use information to support more fact-based decision making.</li></ul><blockquote>Core Requirements for a Successful DW/BI System</blockquote><ol><li><strong>Simple &amp; Fast:</strong> Data must be intuitive, easy to access, and delivered quickly.</li><li><strong>Consistent:</strong> Information must be clean, credible, and uniformly defined across sources.</li><li><strong>Adaptable:</strong> The system must gracefully handle business, data, and technology changes.</li><li><strong>Timely:</strong> Data should be transformed into actionable insights within seconds or minutes when needed.</li><li><strong>Secure:</strong> Confidential information must be strictly protected from unauthorized access.</li><li><strong>Decision-Oriented:</strong> The warehouse must support better decisions through accurate evidence.</li><li><strong>Business Acceptance:</strong> Success depends on user adoption — if it’s not used, it has failed.</li></ol><blockquote>Dimensional Modeling Introduction</blockquote><p>First, it’s important to understand why <strong>normalized (3NF) structures, which work perfectly for transactional systems, are not the best fit for analytics</strong>. Let’s start by exploring what normalization means and why it becomes challenging for BI queries.</p><ul><li>In a <strong>normalized (3NF) model</strong>, data is split into many small tables to remove redundancy. This is great for transactional systems but makes queries complex, as analysts need to join multiple tables.</li></ul><blockquote>Orders</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*9k63l_ZyfCfzILYGTbTYTw.png" /></figure><blockquote>Customers</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*Cu5QjacRmgOsNzNOVNt3KA.png" /></figure><blockquote>Products</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*c98Yy2uk2IJgSKFqwGFGtw.png" /></figure><p>To get <strong>Total sales per customer</strong>, you need to join <strong>3+ tables</strong>:</p><pre>SELECT c.CustomerName, SUM(p.Price * o.Quantity) AS TotalSales<br>FROM Orders o<br>JOIN Customers c ON o.CustomerID = c.CustomerID<br>JOIN Products p ON o.ProductID = p.ProductID<br>GROUP BY c.CustomerName;</pre><ul><li>In a <strong>dimensional model</strong>, data is simplified into <strong>fact tables</strong> (numbers, transactions) and <strong>dimension tables</strong> (descriptive details). This makes queries much faster and easier to understand for business users.</li></ul><blockquote>FactSales</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*_MQgoNWrQh9JQoOD7V16JA.png" /></figure><blockquote>DimCustomer</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/1*FJlkL3ik-NKQ8wQd34JdPQ.png" /></figure><blockquote>DimProduct</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*TPsRP_uQ25UwnZesIKZdOQ.png" /></figure><p>Query becomes much easier and faster:</p><pre>SELECT c.CustomerName, SUM(f.TotalPrice) AS TotalSales<br>FROM FactSales f<br>JOIN DimCustomer c ON f.CustomerID = c.CustomerID<br>GROUP BY c.CustomerName;</pre><p><strong><em>Conclusion:</em></strong></p><ul><li><strong>Use 3NF</strong> →If system in (Banking, E-commerce transactions).</li><li><strong>Use Star Schema</strong> → BI/DW (Dashboards, Reporting, Analytics).</li><li><strong><em>“Normalization keeps your data clean, but dimensional modeling makes your data useful.”</em></strong></li></ul><h3>Star Schemas Versus OLAP Cubes</h3><p>When we talk about dimensional modeling in Data Warehousing and Business Intelligence (DW/BI), two common terms appear: <strong>Star Schema</strong> and <strong>OLAP Cube</strong>.<br> Both rely on the same dimensional concepts (facts and dimensions), but the way they are <strong>implemented and used</strong> is different.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*M0mc6Ra0ioMwx3kRRJor1A.png" /></figure><blockquote>1st: Star Schema?</blockquote><p>A <strong>Star Schema</strong> is a relational database design for DW/BI systems.</p><ul><li>At the center: a <strong>Fact Table</strong> with numeric measures (like sales amount, quantity) , around it: <strong>Dimension Tables</strong> describing the facts (such as product, customer, date).</li><li>Its name comes from the “star-like” structure when drawn.</li></ul><h4>Star Schemas are:</h4><ul><li>Easy to build in relational databases (SQL-based), Stable and reliable for storage, backup, and recovery.</li><li><strong>The foundation for most Data Warehouses</strong></li></ul><blockquote>2nd: OLAP Cube?</blockquote><p>An <strong>OLAP Cube</strong> is a multidimensional data structure designed for fast analysis.</p><ul><li>It takes data from a <strong>Star Schema, </strong>measures (facts) become <strong>cube measures, </strong>dimensions become <strong>hierarchies</strong> inside the cube (e.g., Year → Quarter → Month → Day).</li></ul><h4>OLAP Cubes provide:</h4><ul><li>Pre-aggregation ,indexing and advanced functions.</li><li>Extremely fast query performance.</li><li>Support for drill-down(Year → Quarter → Month → Day), roll-up(Day → Month → Quarter → Year), slicing, and dicing.</li><li>Rich analytical functions beyond SQL.</li><li><strong>Downside: Loading and processing cubes can take longer, especially for large datasets.</strong></li></ul><blockquote>Relationship Between the Two</blockquote><ul><li><strong>Star Schema</strong> = the foundation (relational storage).</li><li><strong>OLAP Cube</strong> = an analytical layer <strong>built on top of it.</strong></li></ul><h3>Fact Tables vs Dimension Tables</h3><p>In dimensional modeling, we deal with <strong>two main types of tables</strong>:</p><blockquote>Fact Tables</blockquote><ul><li>Store <strong>measurements</strong> (numbers that can be aggregated). e.g: <em>Sales Amount, Quantity Sold, Revenue</em>.</li><li>Each row = a <strong>business event</strong> at a specific level (called the <strong>grain</strong>), e.g., one row per product sold in a transaction.</li><li>Usually very <strong>large (millions of rows)</strong> but <strong>narrow</strong> (few columns).</li><li>Contain <strong>foreign keys</strong> linking to dimension tables + numeric facts.</li><li>Most useful when facts are <strong>additive</strong>, so you can sum them up (e.g., total sales by product, by month, etc.).</li></ul><p>Example: A <strong>Sales Fact Table</strong> might include:<br> Date Key | Product Key | Customer Key | Store Key | Sales Dollars | Units Sold</p><blockquote>Dimension Tables</blockquote><ul><li>Store the <strong>context / descriptive attributes</strong> of business entities. e.g: <em>Product Name, Category, Brand, Customer Info, Store Location</em>.</li><li>Each row describes a <strong>“who, what, where, when, how, why”</strong> of a fact.</li><li>Typically <strong>smaller in row count</strong> but <strong>wider</strong> (many attributes).</li><li>Denormalized on purpose → easier for analysts to use (no need to join 5 lookup tables).</li></ul><p>Example: A <strong>Product Dimension Table</strong> might include:<br> Product Key | Product Name | Brand | Category | Package Size | Weight</p><blockquote>Together, fact tables + dimension tables form the <strong>Star Schema</strong>, making queries simple and intuitive.</blockquote><h3>Kimball’s DW/BI Architecture(Bottom-Up)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*hZqe2ZfTQyjxGfNEuuQraA.png" /></figure><blockquote><strong>Flow:</strong></blockquote><p>the focus is on <strong>data marts</strong>, <strong>all data marts are connected</strong> through <strong>conformed dimensions</strong> shared definitions of key entities such as Customer, Product, Time, or Region, they together form the <strong>Enterprise Data Warehouse (EDW)</strong>..</p><p>These conformed dimensions ensure that every data mart <strong>“speaks the same language,”</strong> allowing easy integration and consistent reporting across the entire organization.</p><p>Data flows from <strong>operational systems → ETL layer → data marts (presentation layer)</strong>, where data is modeled dimensionally (using star schemas).</p><blockquote>1. Operational Source Systems</blockquote><p>These are the company’s systems that record daily transactions (such as ERP, CRM, and sales systems).<br> We don’t have much control over how the data is structured inside them.<br> Their main purpose is <strong>speed in recording daily operations</strong>, not analytics.<br> They also don’t usually keep long historical data.</p><blockquote>2. ETL System (Extract, Transform, Load) — Back Room</blockquote><p>This is the part that takes data from the operational systems and prepares it.<br> Its steps are:</p><ul><li><strong>Extract</strong>: Pull the data.</li><li><strong>Transform</strong>: Clean it and apply <strong>conformed dimensions </strong>(such as unifying customer or product names)that connect all the Data Marts together.</li><li><strong>Load</strong>: Store it in the Presentation Area.</li></ul><blockquote>It focuses on <strong>throughput (speed)</strong> and <strong>integrity &amp; consistency (quality and accuracy)</strong>.<br> It’s like the <strong>“kitchen” in the restaurant analogy</strong> → preparing the food (data) before it is served to the customer.</blockquote><blockquote>3. Data Presentation Area — Front Room</blockquote><p>Here the data is stored and made available to users.<br>- It must be structured in a <strong>Dimensional Model (Star Schema or OLAP Cube)</strong>.<br>- The data is both <strong>atomic (detailed)</strong> and <strong>aggregated (summarized)</strong>.<br>- It’s organized by <strong>business processes</strong> (sales, inventory, finance, etc.).<br>- It uses <strong>conformed dimensions</strong> to ensure everything is consistent and integrated.<br>- The goal is <strong>ease of use and good performance for queries</strong>.</p><blockquote>4. BI Applications (Business Intelligence Applications)</blockquote><p>These are the tools that users rely on to analyze the data:</p><ul><li><strong>Ad hoc queries</strong> ( queries).</li><li><strong>Standard reports</strong> (reports).</li><li><strong>Analytic applications</strong> .</li><li><strong>Data mining &amp; models</strong> (prediction &amp; analytical models).</li></ul><blockquote><strong>Restaurant Analogy for Kimball’s Architecture</strong></blockquote><ul><li><strong>Kitchen = ETL</strong> (where food/data is prepared — customers can’t enter).</li><li><strong>Dining Room = Presentation Area + BI</strong> (customers see the food nicely presented, not the raw ingredients).</li><li><strong>Customers = Business Users</strong> (they want ready-to-use data, just like ready-to-eat food).</li></ul><blockquote>Alternative DW/BI Architectures</blockquote><h4>1. Independent Data Mart Architecture</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*f-1XcytUWeV2o4tfW0rqww.png" /></figure><ul><li>In this approach, each business department builds its own <strong>data mart</strong> independently. <strong>For example,</strong> the Sales, HR, and Inventory teams each collect, clean, and<strong> store their own data </strong>using different rules, tools, and data models.</li><li>There is <strong>no centralized Data Warehouse</strong>, and more importantly, there are <strong>no conformed dimensions</strong> shared across departments. This means <strong>a “Customer” in the Sales mart may not match a “Customer” in the Marketing mart,</strong> and comparing them becomes nearly impossible</li><li>While this may solve the department’s problems, <strong>it happens in isolation</strong>.</li><li>While this approach is <strong>quick to implement and gives fast results for individual departments, but no enterprise-wide view.</strong></li></ul><h3>Hub-and-Spoke Inmon’s Corporate Factory (CIF) — The Top-Down Approach</h3><p>Bill Inmon introduced the <strong>Corporate Information Factory (CIF)</strong>, a <strong>top-down</strong> approach to building a Data Warehouse.<br> Unlike Kimball’s bottom-up model that begins with data marts, Inmon’s architecture starts by creating a <strong>centralized Enterprise Data Warehouse (EDW)</strong> for the entire organization.</p><h3>1. Concept</h3><p>The <strong>EDW</strong> acts as the <strong>single source of truth</strong>, integrating and storing detailed, historical data from all operational systems in a <strong>normalized (3NF)</strong> structure.<br> After the EDW is built, <strong>departmental Data Marts</strong> are created from it to support specific analytical needs (e.g., Sales, HR, Finance).</p><p><strong>Flow:</strong> Operational Systems → ETL → EDW → Data Marts → BI Applications.</p><blockquote><strong>Top-down approach</strong>: EDW first, then Data Marts.</blockquote><h3>2. Architecture Overview</h3><p>This design follows a <strong>Hub-and-Spoke</strong> model:</p><ul><li>The <strong>Hub</strong> represents the <strong>Enterprise Data Warehouse (EDW)</strong>, where all corporate data is integrated and stored in detailed, historical form.</li><li>The <strong>Spokes</strong> represent <strong>Data Marts</strong>, which are built from the EDW to serve the analytical needs of specific business units.</li></ul><p>Data flow looks like this:<br> → <strong>Operational Systems</strong><br> → <strong>ETL Process (Integration &amp; Cleansing)</strong><br> → <strong>Enterprise Data Warehouse (Hub)</strong><br> → <strong>Data Marts (Spokes)</strong><br> → <strong>BI Tools &amp; Applications</strong></p><blockquote>Inmon Vs. Kimball</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*bAtmVcZ2J_VzSUEMLipKFA.png" /></figure><h3>Reference</h3><blockquote><em>Kimball, R. &amp; Ross, M. </em>The Data Warehouse Toolkit: The Definitive Guide to Dimensional Modeling<em>. Wiley, 3rd Edition.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff943f79cadf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Time-Series Data Joining Using the Snowflake ASOF Join]]></title>
            <link>https://medium.com/@alaaelnakeeb81/time-series-data-joining-using-the-snowflake-asof-join-fd936f0849d7?source=rss-9f4c5ff2cf48------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd936f0849d7</guid>
            <category><![CDATA[sql-techniques]]></category>
            <category><![CDATA[time-series-analysis]]></category>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[analytics-engineering]]></category>
            <dc:creator><![CDATA[Alaaelnakeeb]]></dc:creator>
            <pubDate>Thu, 24 Jul 2025 13:15:21 GMT</pubDate>
            <atom:updated>2025-07-24T19:15:57.138Z</atom:updated>
            <content:encoded><![CDATA[<p>Working with time-based data is common in the real world — from tracking user behavior, sensor logs, to billing systems and financial pricing. But there’s often a challenge: <strong>timestamps rarely align perfectly</strong> between tables.</p><p>That’s where <strong>ASOF JOIN</strong> (As-Of Join) comes in.</p><p>It’s one of the most efficient ways to <strong>relate events across time</strong>, even when the timestamps don’t match exactly.</p><blockquote><strong>ASOF (As-Of) Join</strong> is a special kind of join used when working with <strong>time-series data</strong>.<br> Instead of matching rows based on exact equality like a typical join, ASOF Join <strong>matches each row from the left table with the nearest row on the right table where the timestamp is less than or equal to the left’s timestamp</strong>.</blockquote><p>This is especially useful when the two tables have timestamps that don’t align perfectly — which is often the case in real-world data <strong>such as financial trading data, weather observations, readings from sensors, and audit trails.</strong></p><h4>Visual Example — How ASOF JOIN Works :</h4><p><em>Let’s imagine this scenario:</em></p><p><em>You have two tables:</em></p><p><strong><em>1. entry_events</em></strong><em> — records of people entering a building<br></em><strong><em>2. door_openings</em></strong><em> — records of when the door was opened</em></p><h4>Now the <strong>challenge</strong> is:</h4><blockquote><strong><em>For each entry event, how can we find the most recent door opening that happened before or at the same time as the user entered?</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*WjBvBW_BLoeLCAV6ET6pzA.png" /><figcaption>For each row in entry_events, we want to join it with the most recent door_open_time that occurred before or exactly at the enter_time.</figcaption></figure><blockquote><strong>A standard SQL </strong><strong>JOIN can&#39;t help here — because it only matches exact values, not conditions based on time proximity.</strong></blockquote><p>This is where the ASOF JOIN comes in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*fWXK2M-cnSw0gYK6YoLJKw.png" /></figure><ul><li><strong>To Structure ASOF JOIN Queries in Snowflake</strong></li></ul><pre>SELECT<br> .....<br>FROM entry_events e<br>ASOF JOIN door_openings d<br>    MATCH_CONDITION (e.enter_time &gt;= d.door_open_time)<br>    ON e.door_id = d.door_id;</pre><h3>🧾 Real-World Use Case: Rollback-Based Pricing for Telecom Calls</h3><p>In telecom, pricing isn’t always fixed. Rates can change multiple times per day depending on user plans, regional promotions, or time-based offers.</p><p>But here’s the challenge:<br> <strong>When a user makes a call, we need to charge them based on the rate that was active <em>at the time the call started</em></strong> — not the current rate, and not a future rate.</p><p>This billing model is called <strong>rollback-based pricing</strong>.</p><h4>Imagine this scenario:</h4><ul><li>On <strong>June 1st at 8:00 AM</strong>, user 101 makes a call. At that moment, the price per minute is <strong>$0.10</strong>.</li><li>But at <strong>12:00 PM</strong>, the price changes to <strong>$0.15</strong>.</li><li>Later that day at <strong>1:00 PM</strong>, user 101 makes another call.</li></ul><blockquote><em>So how do we calculate the cost for each call?<br> We need to find </em><strong><em>the latest price that was in effect </em>at or before<em> the call start time</em></strong><em>.</em></blockquote><p><strong>Table: CALLS</strong></p><pre>CREATE OR REPLACE TRANSIENT TABLE CALLS (<br>  CALL_ID NUMBER,<br>  USER_ID NUMBER,<br>  CALL_START_TIME TIMESTAMP,<br>  CALL_DURATION NUMBER<br>);<br><br>INSERT INTO CALLS VALUES<br>(1, 101, &#39;2024-06-01 08:00:00&#39;, 60),<br>(2, 101, &#39;2024-06-01 13:00:00&#39;, 90),<br>(3, 102, &#39;2024-06-02 10:00:00&#39;, 120),<br>(4, 102, &#39;2024-06-03 15:00:00&#39;, 30),<br>(5, 103, &#39;2024-06-04 20:00:00&#39;, 45),<br>(6, 101, &#39;2024-06-05 09:00:00&#39;, 150);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r6ojK92Ka6i8-fPg7UFfbg.png" /></figure><p><strong>Table: PRICING_HISTORY</strong></p><pre>CREATE OR REPLACE TRANSIENT TABLE PRICING_HISTORY (<br>  USER_ID NUMBER,<br>  PRICE_PER_MIN NUMBER(5,2),<br>  PRICE_START_TIME TIMESTAMP<br>);<br><br>INSERT INTO PRICING_HISTORY VALUES<br>(101, 0.10, &#39;2024-06-01 00:00:00&#39;),<br>(101, 0.15, &#39;2024-06-01 12:00:00&#39;),<br>(101, 0.12, &#39;2024-06-04 00:00:00&#39;),<br>(102, 0.08, &#39;2024-06-01 00:00:00&#39;),<br>(102, 0.09, &#39;2024-06-03 00:00:00&#39;),<br>(103, 0.07, &#39;2024-06-01 00:00:00&#39;);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3La0bCKpMGMJ8sxrX3DTfg.png" /></figure><blockquote><strong>How the ASOF JOIN Works</strong></blockquote><pre>SELECT <br>  C.CALL_ID,<br>  C.USER_ID,<br>  C.CALL_START_TIME,<br>  C.CALL_DURATION,<br>  P.PRICE_PER_MIN,<br>  P.PRICE_START_TIME,<br>  C.CALL_DURATION * P.PRICE_PER_MIN AS TOTAL_COST<br>FROM CALLS C<br>ASOF JOIN PRICING_HISTORY P<br>  MATCH_CONDITION(C.CALL_START_TIME &gt;= P.PRICE_START_TIME)<br>  ON C.USER_ID = P.USER_ID<br>ORDER BY C.CALL_ID;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cHrBnJh_GpUb08MaydJVWw.png" /></figure><blockquote><strong>Why ASOF JOIN?</strong></blockquote><p>ASOF JOIN allows us to join two tables based on:</p><ul><li>A matching key (like USER_ID)</li><li>And the most recent record <em>before or at</em> a specific timestamp (like CALL_START_TIME &gt;= PRICE_START_TIME)</li><li>It lets us write a query that says:</li></ul><p><strong><em>“For each call, find the most recent price (from pricing history) that applies at the time of that call.”</em></strong></p><blockquote><strong>Traditional Approach vs. ASOF JOIN</strong></blockquote><p>Before Snowflake introduced the ASOF JOIN, implementing this kind of logic required a workaround using standard SQL window functions.</p><p>Let’s look at how we could achieve the same result <strong>without</strong> ASOF JOIN:</p><pre>SELECT *<br>FROM (<br>  SELECT <br>    C.CALL_ID,<br>    C.USER_ID,<br>    C.CALL_START_TIME,<br>    C.CALL_DURATION,<br>    P.PRICE_PER_MIN,<br>    P.PRICE_START_TIME,<br>    ROW_NUMBER() OVER (<br>      PARTITION BY C.CALL_ID <br>      ORDER BY P.PRICE_START_TIME DESC<br>    ) AS RN<br>  FROM CALLS C<br>  JOIN PRICING_HISTORY P<br>    ON C.USER_ID = P.USER_ID<br>   AND P.PRICE_START_TIME &lt;= C.CALL_START_TIME<br>) X<br>WHERE RN = 1;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fJIXGA6OhkXSVSpufuDRpQ.png" /></figure><p>This works, but:</p><ul><li>You need to use a subquery.</li><li>You need ROW_NUMBER() to rank potential matches.</li><li>Then you filter to pick the most recent one (WHERE RN = 1).</li></ul><p>This is more verbose and harder to read or maintain, especially at scale.<br> <strong>ASOF JOIN simplifies all of that into a clean, readable query.</strong></p><blockquote><strong>When to Use ASOF JOIN</strong></blockquote><p>Use ASOF JOIN when:</p><ul><li>You need to match rows based on the closest <em>past</em> timestamp.</li><li>You’re working with event logs, metrics, price history, sensor data, or any form of temporal data.</li></ul><p>Note:<br> ASOF JOIN was introduced in <strong>February 2024</strong> and is currently supported in <strong>Snowflake only</strong>.</p><blockquote><strong>Conclusion</strong></blockquote><p>ASOF JOIN is a smart way to handle time-based relationships in Snowflake. It simplifies complex matching across timestamps, helping you make accurate and timely decisions from your data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd936f0849d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Book summary: Storytelling with data]]></title>
            <link>https://medium.com/@alaaelnakeeb81/book-summary-storytelling-with-data-5934c3082e01?source=rss-9f4c5ff2cf48------2</link>
            <guid isPermaLink="false">https://medium.com/p/5934c3082e01</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[storytelling]]></category>
            <category><![CDATA[dat]]></category>
            <dc:creator><![CDATA[Alaaelnakeeb]]></dc:creator>
            <pubDate>Mon, 28 Oct 2024 16:32:49 GMT</pubDate>
            <atom:updated>2024-10-28T17:55:41.902Z</atom:updated>
            <content:encoded><![CDATA[<h4>Extracting the main learning points and examples from my go-to data visualization book.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*FHh3pBOHVvI-I1MwqpuMAw.jpeg" /></figure><p><em>Introduction:</em></p><p>In today’s data-driven world, the ability to effectively tell stories with data has become increasingly important. A strong data visualization can significantly impact decision-making, whether it’s for business success, raising funds, or simply conveying insights to an audience. Many people, however, <strong>face challenges in this area</strong> due to a lack of formal training in design, despite possessing strong analytical skills.</p><p>Communicating data effectively, particularly through visuals, is often overlooked but is critical, as it is the part of the analysis most seen by decision-makers.</p><blockquote><strong><em>Key steps to weave a good story from data are as follows:</em></strong></blockquote><ol><li>Understand the context</li><li>Choose an appropriate display</li><li>Eliminate clutter</li><li>Draw attention where you want it</li><li>Think like a designer</li><li>Tell a story</li></ol><p><em>Chapter one :</em></p><blockquote><strong><em>Understanding the context :</em></strong></blockquote><p>Before creating any data visualizations or content for explanatory analysis, it’s crucial to consider three key factors you need to know:</p><ul><li><strong>Who</strong> is your audience?</li><li><strong>What</strong> do you want them to know or do?</li><li><strong>How </strong>can data support your point?</li></ul><blockquote><strong><em>Notes:</em></strong></blockquote><ul><li><strong><em>Be specific about your audience</em></strong>: Clearly define who you are communicating with for better effectiveness.</li><li><strong><em>Avoid broad audiences</em></strong>: Avoid broad audiences to target your message more effectively. Sometimes, creating separate communications for different audiences is necessary.</li></ul><blockquote><strong><em>Consulting for context : Questions to ask</em></strong></blockquote><p><strong>Often</strong> <em>the analyst may not be given the proper context for a given project so at this point, there is a set of questions that will force you to ensure you are trying to convey the right message </em>:</p><ol><li>What background information is essential?</li><li>Who is or are the decision makers in your audience?</li><li>What biases may the audience have to be supportive or against our case?</li><li>What data do we have and is the audience familiar with it?</li><li>What would a successful outcome look like?</li></ol><p><strong><em>Note :</em></strong> Understanding and employing concepts like <strong>the 3‐minute story</strong> and storyboarding will enable you to clearly and succinctly tell your story and identify the desired flow.</p><p><em>Chapter two:</em></p><blockquote><strong><em>Choosing an effective visual :</em></strong></blockquote><p>There are many different graphs and other types of visual displays of information, but a handful will work for the majority of your needs.</p><ol><li>Simple text</li><li>Table</li><li>Scatterplot</li><li>Line charts (timeseries or slopegraphs)</li><li>Bar charts (horizontal or vertical)</li><li>Stacked Bar charts</li><li>waterfall</li></ol><blockquote><strong><em>Simple Text :</em></strong></blockquote><p>When you have just a <strong>number or two </strong>to share, simple text can be a great way to communicate.</p><p><strong>For Example :<em> the book shows us two options (A &amp;B ) : </em></strong>The fact that you have some numbers does not mean that you need a graph!</p><ul><li><strong><em>(In Option A)</em></strong>, a graph is used to represent two simple numbers, but it takes up too much space and doesn’t help with understanding the data better. it might mislead the viewer because of how the data labels are positioned.</li><li>In contrast, (<strong><em>Option B)</em></strong> presents a more effective alternative. Instead of using a graph, the information could be clearly communicated with a simple sentence: “In 2012, 20% of children had a traditional stay-at-home mother, compared to 41% in 1970.”</li></ul><p><strong>So <em>option B</em> is more concise, easier to understand, and avoids unnecessary visual clutter, making the key point clearer.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*5iBnJZ5RaHVfsOps3l374A.png" /><figcaption>Figures extracted from the book</figcaption></figure><blockquote><strong><em>Tables :</em></strong></blockquote><p>Tables are effective for reading <strong>across rows and comparing values</strong>, making them useful for communicating with a diverse audience. They are also <strong>helpful when presenting multiple units of measurement</strong>, which is often easier to display in a table than in a graph.</p><p><strong><em>Notes:</em></strong></p><ul><li>Using tables in<strong> live presentations </strong>is generally <strong>not a good idea</strong> because it can distract the audience from listening to you.</li><li>The table design should fade into the background, <strong>letting the data take center stage.</strong></li><li><strong>Avoid using heavy borders or shading </strong>that can compete for attention.</li><li><strong>Use light borders or simply </strong>white space to separate elements of the table, making it easier to read and keeping the focus on the data itself.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*ZbmpYoKQ_loG8vMs9i7f1w.png" /><figcaption>Image extracted from the book</figcaption></figure><blockquote><strong><em>Heatmap:</em></strong></blockquote><p>Heatmap means mixing the detail you can include in <strong>a table while also making use of visual cues (colored cells).</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*JqT6ur81AIkTlAQvZ64oZg.png" /><figcaption>Image extracted from the book</figcaption></figure><ul><li>In the <strong>table</strong> in Figure 2.5, you are left to read the data scanning across rows and down columns to get a sense of what I’m looking at, where numbers are higher or lower.</li><li>To reduce this mental processing, we <strong>use color saturation( in heatmap)</strong> to provide visual cues, helping our eyes and brains more quickly target the potential points of interest.</li></ul><blockquote><strong><em>Scatterplot:</em></strong></blockquote><p>Scatterplot<strong><em> </em></strong>uses dots to represent values for<strong> two different numeric variables.</strong> The position of each dot on the <strong>horizontal and vertical axis</strong> indicates values for an individual data point. it is used to observe relationships between variables , also used it to show a <strong>correlation</strong> trend, a clustering pattern or to <strong>find outliers</strong> and show<strong> the general distribution of the data.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*JMcwWzHPJ0jdcGCXrtYK2A.png" /><figcaption>Figures extracted from the book</figcaption></figure><p>The scatterplot in Figure 2.7 shows that the cost per mile is higher than average when fewer than ~1,700 miles or more than ~3,300 miles are driven per month.</p><blockquote><strong><em>Line charts (line graph , Slophegraph) :</em></strong></blockquote><ul><li><strong>Line graph :</strong></li></ul><p>The line graph can show a single series of data, two series of data, or multiple series <strong>in consistent intervals</strong> as in figure (2.8) .It also used to represent a <strong>summary statistic, like the average, or the point estimate of a forecast as in figure (2.9).</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*J0FQ9A6evl536kbMtARcpg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*MJN-VaBwtNJR4MxNz0EvoA.png" /><figcaption>Figures extracted from the book</figcaption></figure><ul><li><strong>Slophegraph :</strong></li></ul><p>Slopegraphs can be useful when<strong> you have two time periods or points of comparison </strong>and want to quickly show relative increases and decreases or differences <strong>across various categories between the two data points.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*zvfJUyJ8rUokQtJ31egYFA.png" /><figcaption>image extracted from the book</figcaption></figure><blockquote><strong><em>Bar Charts:</em></strong></blockquote><p><em>Bar charts are easy for our eyes to read. Our eyes compare the end points of the bars, so it is easy to see quickly which category is the biggest, which is the smallest, and also the incremental difference between categories</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*mXm4NiVUPYWnl1r_njBDFw.png" /><figcaption>Vertical Bar Charts</figcaption></figure><p><strong><em>NOTE: </em></strong><em>The horizontal bar chart is especially useful if your category names are long.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*V-YoOZuGmPmeW4GM.png" /><figcaption>Image extracted from the book</figcaption></figure><p><strong>Stacked Bar Charts </strong>allow you to compare totals across categories and also see the subcomponent pieces within a given category. can be structured as absolute numbers with each column summing to 100% (where you plot the percent of total for each vertical segment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*HQuFtR409FhS_8RIfP5hsw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*4nBmUrYBX2hgKLf9.png" /><figcaption>Figures extracted from the book</figcaption></figure><blockquote><strong><em>Waterfall chart</em></strong></blockquote><p>waterfall chart can be used <strong>to pull apart the pieces of a stacked bar chart to focus on one at a time</strong>, or to show a starting point, increases and decreases, and the resulting ending point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*FF3igokYFZ9LAQQcWPsBEQ.png" /><figcaption>Image extracted from the book</figcaption></figure><blockquote><strong><em>Area Charts :</em></strong></blockquote><p>I avoid most area graph .Humans’ eyes don’t do a great job of attributing quantitative value to two‐dimensional space. but I normally use it in 2 use cases:</p><p>1) If you are dealing with big differences between 2 segments, you <em>could</em> represent this with an area chart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*yNKwIK-f2FCqwNfYEEuQxw.png" /><figcaption>Image extracted from the book</figcaption></figure><p>2) Stacked Area Chart : Stacked Area Graphs displaying multiple data series that start each point from the point left by the previous data series.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/0*eoswzHwis-yHvK69.png" /><figcaption>The entire graph represents the total of all the data plotted</figcaption></figure><p><strong>Notes (To Be Avoided):</strong></p><ul><li>Try to avoid using 3D Visualization charts.</li><li>Don’t show the second y‐axis. Instead, label the data points that belong on this axis directly.</li><li>Pull the graphs apart vertically and have a separate y‐axis for each (both along the left) but leverage the same x‐axis across both</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*STDg8pT7ZBUdkh2bBR7QHw.png" /><figcaption>Image extracted from the book</figcaption></figure><p><em>Chapter Three :</em></p><blockquote>Clutter is your enemy :</blockquote><p>when designing visual communications , it’s crucial to <strong>minimize cognitive load for the audience</strong>. Every element added to a page or screen requires mental effort to process, so unnecessary elements should be removed. This reduces “<strong>clutter</strong>” and <strong>enhances the clarity of the message</strong>.</p><p><strong>Gestalt principles of visual perception</strong> help designers create clear and effective visuals by organizing elements in ways that align with how people naturally perceive order.</p><p>The key principles include:</p><ul><li><strong>Proximity</strong>: Objects close together are seen as part of a group.</li><li><strong>Similarity</strong>: Objects that share characteristics (e.g., color or shape) are perceived as related.</li><li><strong>Enclosure</strong>: Physically enclosed objects are viewed as grouped.</li><li><strong>Closure</strong>: People mentally fill in gaps to perceive complete shapes.</li><li><strong>Continuity</strong>: The eye follows the smoothest visual path, even if it’s implied.</li><li><strong>Connection</strong>: Objects physically connected are seen as part of the same group as in figure(3.12) .</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/1*1FROqAYHZLF4AwkAaUwKug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*kwbaKTR4BBy9sZfTq2UrTQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*rWIjiFHf-sYdQBswdKJXFA.png" /><figcaption>Figures extracted from the book</figcaption></figure><p>What elements can help us reduce clutter?</p><ol><li><strong>Align Text and Elements for Clean Lines</strong>: Left-justified text creates cleaner horizontal and vertical lines, making layouts appear more organized compared to center-aligned text.</li><li><strong>Do not add diagonal text.</strong> If your labels are too long, shift to a horizontal bar chart or add your labels in the y-axis. Do not rotate them with an angle.</li><li><strong>Embrace white space in your designs</strong> — it’s as powerful as pauses in speech. Don’t fill space just for the sake of it. Instead, use it to focus attention on what truly matters and make your visuals clear and impactful.</li><li><strong>Color contrast.</strong> Don’t use 10 colors. If you can use 2, contrasting is way easier</li></ol><blockquote><strong>De cluttering a graph: step‐by‐step to apply Gestalt Principles :</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5et5Jg3PpoOXO1nSCSdwAg.png" /><figcaption>step‐by‐step to apply Gestalt Principles</figcaption></figure><p><em>Chapter Four:</em></p><p>Within the brain, there are three types of memory that are important to understand as we design visual communications: iconic memory, short‐term memory, and long‐term memory.</p><ol><li><strong>Iconic memory </strong><br>“<em>Iconic memory is </em><strong><em>super fast</em></strong><em>. It happens without you consciously realizing it , the ability to quickly pick up differences</em> .” The idea is to leverage our fast recognition brain by using pre-attentive attributes<strong>. Pre-attentive attributes </strong>are just a way to say contrasting attributes. For example, size, color, spatial positioning, white spacing, etc.</li><li><strong>short-term memory </strong><br>“<em>short-term memory has a </em><strong><em>limited capacity,</em></strong><em> allowing people to hold only about </em><strong><em>four chunks</em></strong><em> of visual information at once.” </em>Overloading this capacity with complex visuals, such as graphs with many data series, colors, and shapes, can strain the audience’s cognitive processing.</li><li><strong>Long term memory </strong><br><em>Long term memory mean a quick reaction to something known “Long‐term memory is built up over a lifetime and is vitally important for pattern recognition and general cognitive processing”</em>. Strengthening long-term memory enhances our ability to process information, react effectively, and make informed decisions based on prior knowledge.</li></ol><blockquote><strong><em>Pre-attentive attributes:</em></strong></blockquote><ul><li><strong>Pre-attentive attributes in text</strong> are essential for improving text readability and engagement. These attributes — <strong>such as color, size, italics, boldness, and spacing </strong>— quickly draw attention to important information, with bright colors being particularly effective. They create a visual hierarchy, making it easier for audiences to scan content and reducing cognitive load.</li><li><strong>Pre-attentive attributes in graph :</strong></li></ul><p>As in Figure (4.14) adding data markers and numeric labels to selective data points (not all data points to avoid clutter ) to show and minimalistic design.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*_9QygWrLi779t6SO.png" /><figcaption>Image extracted from the book</figcaption></figure><blockquote><strong>Notes:</strong></blockquote><ul><li><strong>Use Color Sparingly</strong>: Color should be a strategic tool to draw attention, not merely decorative. Overusing colors can dilute their impact, making it harder for key information to stand out as in fig (4.15).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*GJ1ktoxnKax0ZhDsLxi6dg.png" /><figcaption>Figures extracted from the book</figcaption></figure><ul><li><strong>Establish Consistency</strong>: Maintain consistent color usage throughout your visuals to help your audience easily recognize patterns and meanings.</li><li><strong>Consider Colorblindness</strong>: Be mindful of colorblind viewers. Avoid combining shades <strong>of red and green,</strong> and use alternative cues (like saturation or symbols) to ensure accessibility.</li><li><strong>Brand Colors</strong>: If using brand colors, select one or two as attention cues while keeping the overall palette muted to ensure clarity and contrast.</li><li><strong>Top Left Priority</strong>: Audiences typically start reading<strong> from the top left</strong> corner and scan in a zigzag pattern. Place the most important information in this prime area.</li></ul><p><em>Chapter Five:</em></p><p><strong><em>Think like a designer</em></strong></p><blockquote><strong>1. The concept of Affordance </strong>— due to the careful design of an object it becomes easy to understand their utility.</blockquote><ul><li><strong><em>how affordances in design can enhance data visualization :</em></strong></li></ul><ol><li><strong>Highlight the Important Stuff</strong></li></ol><ul><li>Use visual elements, known as “pre-attentive attributes” (like color, size, and bold text), to guide the audience’s attention to key areas.</li><li>Avoid using flashing elements unless necessary, as it can be distracting rather than helpful.</li></ul><p><strong>2. Eliminate Distractions</strong></p><ul><li>Remove unnecessary elements to simplify visuals, focusing only on essential information.</li><li>Apply lighter colors and softer tones for non-essential parts, pushing them into the background.<br> <em>e.g :</em> <strong>rounding numbers</strong> to avoid excessive precision, removing redundant categories, and switching from bar to line graphs to reduce clutter.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*bpFsR8ONJMlfBjn_PvMaGg.png" /><figcaption>Figures extracted from the book</figcaption></figure><p><strong>3. Create a Clear Hierarchy of Information</strong></p><ul><li>“Super-categories” or quadrant labels can help organize information, reducing the need for extra processing.</li></ul><p>These three strategies help create visuals that are easy to understand, engaging, and free from clutter, making it easier for audiences to grasp the intended message.</p><blockquote><strong><em>2. The concept of Accessibility </em>— </strong>designs should be usable by people of diverse abilities.</blockquote><p>How to make our data more accessible to folks with varying degree of technical expertise?</p><ol><li>Don’t over complicate things. “If it’s hard to read, it’s hard to do.”</li><li>Use Text in visuals where ever possible. Use text to label various aspects of a complicated visual. as in figure (5.10)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*q0oUPL0Mgi4sicTGz6Jn5Q.png" /><figcaption>Image extracted from the book</figcaption></figure><blockquote><strong><em>3. The concept of Aesthetics</em></strong><em> </em>— it means our data must be pleasing to see.</blockquote><ol><li><strong><em>Be smart with color</em></strong><em>.</em> The use of color should always be an intentional decision; use color sparingly and strategically to highlight the important parts of your visual.</li><li><strong><em>Pay attention to alignment</em></strong>. Organize elements on the page to create clean vertical and horizontal lines to establish a sense of unity and cohesion.</li><li><strong><em>Leverage white space</em></strong><em>. </em>Preserve margins; don’t stretch your graphics to fill the space, or add things simply because you have extra space.</li></ol><p>Chapter six</p><blockquote><strong>Great examples to keep in mind</strong></blockquote><p>Applying everything that the book mentions and I have summarized, here are a few examples I keep coming back to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*32yJRJHHPS-MV9YpwV7i3Q.png" /><figcaption>Image Source from Book with illustrative Comments .</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*h3P2LkuBffQuwG2WSean6g.png" /><figcaption>Image source from book with illustrative comments.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*shxq9Mtd8iRCtD8x_4jzdQ.png" /><figcaption>Image Source from Book with illustrative Comments .</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*Ms7aPo5gGNLjCkrlGzcd1g.png" /><figcaption>Image Source from Book with illustrative Comments .</figcaption></figure><p>Chapter Seven:</p><blockquote><strong><em>Key Strategies for Ensuring Clarity in Storytelling:</em></strong></blockquote><ol><li><strong>Repetition </strong>: Reinforce key messages throughout the presentation to help the audience retain information.</li><li><strong>Horizontal Logic</strong>: Ensure slide titles tell the overarching story, providing a clear flow of ideas.</li><li><strong>Vertical Logic</strong>: Ensure that the content of each slide supports its title, maintaining coherence and depth.</li><li><strong>Reverse Storyboarding</strong>: Start by envisioning the conclusion and work backward to build a logical, compelling narrative. This helps ensure the final message is well-supported and clear from the beginning.</li><li><strong>A Fresh Perspective</strong>: Seek feedback from someone unfamiliar with the context of your communication. Asking them to share what stands out to them, what they consider important, and where they have questions. This feedback helps identify gaps, misunderstandings, or areas that need clarity.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*KhGd-as22-z366-SjUsOWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*gayog3BOtuaPjHzbGvt5vw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*4f219uPFXNvPoOTRGbmaPQ.png" /><figcaption>Figures extracted from the book</figcaption></figure><blockquote><strong>Here’s some advices you can apply when preparing presentations or reports:</strong></blockquote><p><strong>1.Use the company logo and branding:</strong> Always ensure that the company logo and official colors are included in the presentation to maintain a professional look that aligns with the company’s identity.</p><p><strong>2.Get feedback:</strong> Before delivering the final presentation or report, seek feedback from colleagues or your manager to ensure the presentation meets the team’s or client’s expectations.</p><p><strong>4.Simplify the presentations:</strong> Focus on conveying the idea in the simplest way possible, removing unnecessary details to avoid confusing the audience.</p><p><strong>5.Prepare the presentation professionally:</strong> Create a checklist that includes all the essential elements of the presentation, such as images, titles, charts, and important details.</p><p>6.<strong>Grab audience attention strategically</strong>: Design your visualizations to guide the audience’s focus on the key message or insight.</p><p><strong>7. De-clutter your visuals</strong>: Simplify your charts and remove unnecessary elements to ensure clarity and impact.</p><h3>Reference</h3><ul><li><strong><em>Storytelling with Data by Cole Nussbaumer Knaflic.</em></strong></li><li><strong><em>*All the images in this post are taken from the reference book.</em></strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5934c3082e01" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Cleaning(Methods and Examples) in python :]]></title>
            <link>https://medium.com/@alaaelnakeeb81/data-cleaning-methods-and-examples-in-python-40e36b04e9d3?source=rss-9f4c5ff2cf48------2</link>
            <guid isPermaLink="false">https://medium.com/p/40e36b04e9d3</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[missing-data]]></category>
            <category><![CDATA[data-cleaning-with-python]]></category>
            <category><![CDATA[outliers]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Alaaelnakeeb]]></dc:creator>
            <pubDate>Fri, 05 Jan 2024 00:20:23 GMT</pubDate>
            <atom:updated>2024-01-05T00:20:23.054Z</atom:updated>
            <content:encoded><![CDATA[<h3>Data Cleaning(Methods and Examples) in python :</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/0*TWtgsc6Skx5JkHqZ.jpg" /></figure><p><strong>Data Cleaning</strong> is the process of identifying and correcting or removing errors and inconsistencies in the data. This step is important because errors and inconsistencies in the data can lead to incorrect or misleading results. Data cleaning involves several tasks such as correcting or removing duplicate records, handling missing data, handling outliers, and fixing errors in the data.</p><blockquote><strong><em>Let us take a look at our data:</em></strong></blockquote><pre># modules we&#39;ll use<br>import pandas as pd<br>import numpy as np<br><br># read in all our data<br>nfl_data = pd.read_csv(&quot;../input/nflplaybyplay2009to2016/NFL Play by Play 2009-2017 (v4).csv&quot;)</pre><p>It might be helpful to see what percentage of the values in our dataset were missing to give us a better sense of the scale of this problem</p><pre># how many total missing values do we have?<br>total_cells = np.product(nfl_data.shape)<br>total_missing = missing_values_count.sum()<br><br># percent of data that is missing<br>percent_missing = (total_missing/total_cells) * 100<br>print(percent_missing)</pre><p>The result from this was : 24.87214126835169</p><p>Wow, almost a quarter of the cells in this dataset are empty! so we should clean our data.</p><blockquote>Data Cleaning Techniques with Python:</blockquote><h4><strong>1-Handling Missing values:</strong></h4><p>1-<strong>Droping</strong>: The simplest way to handle missing data is to simply delete the records with missing values. I don’t generally recommend this approach for important projects! because it can result in a loss of information and decrease the sample size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YCFeZpx0HyVy9YXeOz11Hw.png" /></figure><p>it looks like that’s removed all our data! This is because every row in our dataset had at least one missing value. We might have better luck removing all the <em>columns</em> that have at least one missing value instead.</p><pre># remove all columns with at least one missing value<br>columns_with_na_dropped = nfl_data.dropna(axis=1)<br>columns_with_na_dropped.head()</pre><p>2-<strong>Imputation</strong>: Imputation involves replacing missing values with estimated values. There are several imputation methods available, including mean imputation, median imputation, and multiple imputation.</p><p>We can use the Panda’s fillna() function to fill in missing values in a dataframe for us.</p><p><em>Here to replace all the </em><em>NaN values with 0.</em></p><pre># replace all NA&#39;s with 0<br>subset_nfl_data.fillna(0)</pre><p><em>Here to replace missing values with whatever value comes directly after it in the same column.</em></p><pre># replace all NA&#39;s the value that comes directly after it in the same column, <br># then replace all the remaining na&#39;s with 0<br>subset_nfl_data.fillna(method=&#39;bfill&#39;, axis=0).fillna(0)</pre><p>here to replace missing values with the mean of the remaining values in a pandas DataFrame:</p><pre># Replace missing values with the mean<br>subset_nf1_data.fillna(subset_nf1_data.mean(), inplace=True)</pre><p><strong>3-Interpolation</strong>: Interpolation is a statistical method used to estimate unknown data points between two known data points. For example, if you have data that shows the price of two items at $12 and $14 each with a missing value, interpolation estimates the missing value price at $13.</p><ul><li>Linear Interpolation</li></ul><pre># Replace missing values with linear interpolation<br>data.interpolate(method=&#39;linear&#39;, inplace=True)</pre><ul><li>Polynomial Interpolation</li></ul><pre># Replace missing values with polynomial interpolation<br>data.interpolate(method=&quot;polynomial&quot;, order=2)</pre><p><strong>4-Regression</strong>: Regression is a statistical method that involves using the values of other variables to predict the missing values.</p><pre># Split the dataset into two parts: one with missing values and one without<br>missing_data = data[data[&#39;missing_column&#39;].isnull()]<br>complete_data = data.dropna(subset=[&#39;missing_column&#39;])<br><br># Separate the features and target for complete data<br>X_complete = complete_data.drop(&#39;missing_column&#39;, axis=1)<br>y_complete = complete_data[&#39;missing_column&#39;]<br><br># Initialize the Linear Regression model<br>reg = LinearRegression()<br><br># Fit the model to the complete data<br>reg.fit(X_complete, y_complete)<br><br># Use the fitted model to predict missing values<br>predictions = reg.predict(missing_data.drop(&#39;missing_column&#39;, axis=1))<br><br># Update the missing values in the original DataFrame<br>data.loc[data[&#39;missing_column&#39;].isnull(), &#39;missing_column&#39;] = predictions</pre><blockquote>2-<strong>Data Transformation: </strong>data needs to be transformed to better fit the assumptions of a specific algorithm or to improve model performance.</blockquote><ul><li>Scaling: changing the <em>range</em> of your data</li><li>Normaization: changing the <em>shape of the distribution</em> of your data.</li></ul><pre>from sklearn.preprocessing import StandardScaler, MinMaxScaler, PowerTransformer<br><br># Standard scaling<br>scaler = StandardScaler()<br>data_scaled = scaler.fit_transform(subset_nf1_data)<br><br># Min-Max scaling<br>scaler = MinMaxScaler()<br>data_normalized = scaler.fit_transform(subset_nf1_data)<br><br># Power transformation (e.g., Box-Cox)<br>transformer = PowerTransformer(method=&quot;box-cox&quot;)<br>data_transformed = transformer.fit_transform(subset_nf1_data)</pre><p>3-<strong>Removing Duplicates:</strong></p><p>Duplicate records can skew your analysis. To remove duplicates, use the drop_duplicates() function:</p><pre>#droping duplicated data<br>data_no_duplicates = subset_nf1_data.drop_duplicates()</pre><blockquote>4-<strong>Correcting Data Types : </strong>Ensure that columns have the correct data types.</blockquote><p>if your data containing date but we found after checking using (.dtype) that it is object you need to make “parsing date” :</p><pre># create a new column, date_parsed, with the parsed dates<br>landslides[&#39;date_parsed&#39;] = pd.to_datetime(landslides[&#39;date&#39;], format=&quot;%m/%d/%y&quot;)</pre><p>Use the astype() method to convert other data types:</p><pre># Converting a column to numeric <br>data[&#39;numeric_column&#39;] = data[&#39;numeric_column&#39;].astype(float)</pre><blockquote><strong>5-Categorical Data Encoding : </strong>Categorical data, such as text labels or categories, need to be <strong>encoded into numerical values for many machine learning algorithms</strong>. Common encoding techniques include one-hot encoding(get_dummies) and label encoding:</blockquote><pre># One-hot encoding<br>data_encoded = pd.get_dummies(data, columns=[&quot;categorical_column&quot;])<br><br># Label encoding<br>from sklearn.preprocessing import LabelEncoder<br><br>le = LabelEncoder()<br>data[&quot;categorical_column&quot;] = le.fit_transform(data[&quot;categorical_column&quot;])</pre><blockquote><strong>6- Dealing with Inconsistent Data : </strong>Sometimes, data entries are inconsistent. You can standardize them using Pandas’ replace() function.</blockquote><pre># convert to lower case<br>data[&#39;Country&#39;] = data[&#39;Country&#39;].str.lower()<br># Standardize country names<br>data[&#39;country&#39;] = data[&#39;country&#39;].replace({&#39;USA&#39;: &#39;United States&#39;, &#39;UK&#39;: &#39;United Kingdom&#39;})</pre><blockquote>7- Handling Outliers : To detect outliers, you can use methods like the <strong>IQR </strong>(interquartile range) or <strong>Z-score</strong>:</blockquote><pre># Detect outliers using z-scores<br>Out = np.abs((data[&#39;num_column&#39;] - data[&#39;num_column&#39;].mean()) / data[&#39;num_column&#39;].std())<br># Remove outliers ( with z-score &gt; 4)<br>data = data[Out &lt;= 4]</pre><p>In conclusion, data cleaning is a critical step in the data analysis process. Handling missing data correctly during the cleaning process is important to ensure the accuracy of the final results.</p><p>Remember that data cleaning is not a one-size-fits-all process. It requires a deep understanding of your data and domain knowledge to make informed decisions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40e36b04e9d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>