<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mark Glemba</title>
    <description>The latest articles on DEV Community by Mark Glemba (@mark_glemba_962f6bc8a12dd).</description>
    <link>https://dev.to/mark_glemba_962f6bc8a12dd</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3851972%2Faa71fd54-fff1-4c78-87fc-fdf71f8dd473.jpg</url>
      <title>DEV Community: Mark Glemba</title>
      <link>https://dev.to/mark_glemba_962f6bc8a12dd</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mark_glemba_962f6bc8a12dd"/>
    <language>en</language>
    <item>
      <title>Window functions vs Aggregate functions</title>
      <dc:creator>Mark Glemba</dc:creator>
      <pubDate>Thu, 24 Sep 2026 09:50:31 +0000</pubDate>
      <link>https://dev.to/mark_glemba_962f6bc8a12dd/window-functions-vs-aggregate-functions-556g</link>
      <guid>https://dev.to/mark_glemba_962f6bc8a12dd/window-functions-vs-aggregate-functions-556g</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;SQL is often introduced as a language for retrieving data, but for data scientists it is much more than that. It is a powerful analytical tool for transforming raw event data into metrics, comparisons, rankings, cohorts, trends, and features for downstream modeling. Two of the most important tools in that analytical toolkit are aggregate functions and window functions.&lt;/p&gt;

&lt;p&gt;Aggregate functions reduce rows into summaries. Window functions calculate summaries while preserving the original rows.&lt;/p&gt;

&lt;p&gt;That distinction sounds small, but it changes how you design queries, interpret results, and avoid analytical mistakes.&lt;/p&gt;

&lt;p&gt;This article explains the difference, using practical examples and discussing when each approach is appropriate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Aggregate functions: turning many rows into fewer rows
&lt;/h2&gt;

&lt;p&gt;Aggregate functions summarize multiple rows into a single value. Common examples include:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;MIN&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;MAX&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Suppose you have a table called &lt;code&gt;orders&lt;/code&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;order_id&lt;/th&gt;
&lt;th&gt;customer_id&lt;/th&gt;
&lt;th&gt;order_date&lt;/th&gt;
&lt;th&gt;category&lt;/th&gt;
&lt;th&gt;revenue&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;2026-01-01&lt;/td&gt;
&lt;td&gt;Electronics&lt;/td&gt;
&lt;td&gt;500&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;2026-01-05&lt;/td&gt;
&lt;td&gt;Books&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;td&gt;2026-01-03&lt;/td&gt;
&lt;td&gt;Electronics&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;103&lt;/td&gt;
&lt;td&gt;2026-01-04&lt;/td&gt;
&lt;td&gt;Books&lt;/td&gt;
&lt;td&gt;45&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;td&gt;2026-01-06&lt;/td&gt;
&lt;td&gt;Books&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If you want the total revenue across every order, an aggregate query is appropriate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;total_revenue&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result is one row:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;total_revenue&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;800&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The original five order rows have been collapsed into one summary row.&lt;/p&gt;

&lt;p&gt;More often, analysts aggregate by a dimension. For example, to calculate revenue by product category:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;category&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;total_revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;average_order_value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;order_count&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;category&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This returns one row for each category:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;category&lt;/th&gt;
&lt;th&gt;total_revenue&lt;/th&gt;
&lt;th&gt;average_order_value&lt;/th&gt;
&lt;th&gt;order_count&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Books&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;33.33&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Electronics&lt;/td&gt;
&lt;td&gt;700&lt;/td&gt;
&lt;td&gt;350.00&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This is the core behavior of aggregation: the &lt;code&gt;GROUP BY&lt;/code&gt; clause establishes the grain of the output.&lt;/p&gt;

&lt;p&gt;Before the query, the data was at the order level. After the query, it is at the category level.&lt;/p&gt;

&lt;p&gt;For data analysis, this concept is essential. Every table and query has a level of detail:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One row per event&lt;/li&gt;
&lt;li&gt;One row per order&lt;/li&gt;
&lt;li&gt;One row per customer&lt;/li&gt;
&lt;li&gt;One row per day&lt;/li&gt;
&lt;li&gt;One row per product category&lt;/li&gt;
&lt;li&gt;One row per customer-month&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Aggregate functions intentionally change that level of detail. This is useful when the business question is itself summarized:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What was total revenue last month?&lt;/li&gt;
&lt;li&gt;How many active users did each country have?&lt;/li&gt;
&lt;li&gt;Which product category has the highest sales?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In all these cases, the desired output is a summary table, not a record-level dataset.&lt;/p&gt;

&lt;h2&gt;
  
  
  The limitation of aggregation
&lt;/h2&gt;

&lt;p&gt;The challenge appears when you want both the original row-level data and a summary statistic.&lt;/p&gt;

&lt;p&gt;Imagine you want to look at every individual order while also seeing the customer’s lifetime spending. An ordinary aggregate query cannot do both in one straightforward result.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;customer_lifetime_revenue&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This correctly calculates customer-level revenue:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;customer_id&lt;/th&gt;
&lt;th&gt;customer_lifetime_revenue&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;530&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;td&gt;225&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;103&lt;/td&gt;
&lt;td&gt;45&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;But all order-level information has disappeared. You can no longer see the individual purchases, dates, or categories associated with each customer.&lt;/p&gt;

&lt;p&gt;A common workaround is to write an aggregate query in a common table expression or subquery and join it back to the original table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;customer_totals&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt;
        &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;customer_lifetime_revenue&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
    &lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;category&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_lifetime_revenue&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;
&lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;customer_totals&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;ct&lt;/span&gt;
    &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works, but it is more redundant than necessary. It also becomes cumbersome when you need several related metrics: customer totals, category averages, rank within country, previous purchase values, rolling averages, and so on.&lt;/p&gt;

&lt;p&gt;This is where window functions become invaluable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Window functions: calculations without collapsing rows
&lt;/h2&gt;

&lt;p&gt;A window function performs a calculation across a related set of rows while retaining every row in the result.&lt;/p&gt;

&lt;p&gt;The general syntax looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;function_name&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="k"&gt;ROWS&lt;/span&gt; &lt;span class="k"&gt;BETWEEN&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;OVER()&lt;/code&gt; clause turns a normal function into a window function.&lt;/p&gt;

&lt;p&gt;Here is the earlier customer lifetime revenue example, now written with a window function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;category&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;customer_lifetime_revenue&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result keeps all order-level records:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;order_id&lt;/th&gt;
&lt;th&gt;customer_id&lt;/th&gt;
&lt;th&gt;order_date&lt;/th&gt;
&lt;th&gt;category&lt;/th&gt;
&lt;th&gt;revenue&lt;/th&gt;
&lt;th&gt;customer_lifetime_revenue&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;2026-01-01&lt;/td&gt;
&lt;td&gt;Electronics&lt;/td&gt;
&lt;td&gt;500&lt;/td&gt;
&lt;td&gt;530&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;2026-01-05&lt;/td&gt;
&lt;td&gt;Books&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;td&gt;530&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;td&gt;2026-01-03&lt;/td&gt;
&lt;td&gt;Electronics&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;td&gt;225&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;103&lt;/td&gt;
&lt;td&gt;2026-01-04&lt;/td&gt;
&lt;td&gt;Books&lt;/td&gt;
&lt;td&gt;45&lt;/td&gt;
&lt;td&gt;45&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;td&gt;2026-01-06&lt;/td&gt;
&lt;td&gt;Books&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;225&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each order remains visible, but each one now carries an additional feature: the customer’s total spending.&lt;/p&gt;

&lt;p&gt;From a data science standpoint, this is powerful because it allows you to add contextual variables without destroying the original dataset grain. These values can support exploratory analysis, customer segmentation, anomaly detection, feature engineering, and model preparation.&lt;/p&gt;

&lt;h2&gt;
  
  
  The most important distinction: output grain
&lt;/h2&gt;

&lt;h2&gt;
  
  
  The easiest way to remember the difference is this:
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function type&lt;/th&gt;
&lt;th&gt;What happens to rows?&lt;/th&gt;
&lt;th&gt;Typical use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Aggregate function&lt;/td&gt;
&lt;td&gt;Rows are collapsed into grouped summaries&lt;/td&gt;
&lt;td&gt;Reporting and high-level metrics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Window function&lt;/td&gt;
&lt;td&gt;Rows remain; calculations are added alongside them&lt;/td&gt;
&lt;td&gt;Comparison, ranking, time-series features, row-level analysis&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;Consider a question such as: “What percentage of category revenue did each order represent?”&lt;/p&gt;

&lt;p&gt;You need the individual order revenue, but you also need total revenue for the order’s category. If you use an aggregate query alone, you lose the individual order values. A window function is ideal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;category&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;category&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;category_revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;revenue&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;
        &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;category&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;percent_of_category_revenue&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the Electronics category, the two orders contribute to a total of 700. Each row can now be interpreted relative to its category-level context.&lt;/p&gt;

&lt;p&gt;This is a recurring pattern in analytical work: retain the observation, then attach the benchmark.&lt;/p&gt;

&lt;h2&gt;
  
  
  PARTITION BY: defining the comparison group
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;PARTITION BY&lt;/code&gt; clause divides rows into logical groups for the window calculation.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;category&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This calculates the average order revenue within each category.&lt;/p&gt;

&lt;p&gt;If &lt;code&gt;PARTITION BY&lt;/code&gt; is omitted, the window includes all rows returned by the query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;overall_average_revenue&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That allows direct comparisons between each row and the global average:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;overall_average_revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;revenue&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;difference_from_average&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This can be useful for finding unusually large or small transactions.&lt;/p&gt;

&lt;p&gt;In practice, data scientists frequently partition by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customer ID for customer behavior analysis&lt;/li&gt;
&lt;li&gt;User ID for product analytics&lt;/li&gt;
&lt;li&gt;Country, region, or market for geographic comparison&lt;/li&gt;
&lt;li&gt;Product category for merchandising analysis&lt;/li&gt;
&lt;li&gt;Experiment group for A/B test reporting&lt;/li&gt;
&lt;li&gt;Account ID for B2B usage behavior&lt;/li&gt;
&lt;li&gt;Month or week for period-based comparisons&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The choice of partition is analytical, not merely technical. It defines the peer group against which a row is being evaluated.&lt;/p&gt;

&lt;h2&gt;
  
  
  ORDER BY: making the window sequential
&lt;/h2&gt;

&lt;p&gt;Aggregate functions generally do not care about row order. The sum of sales is the same whether Monday’s data appears before Friday’s.&lt;/p&gt;

&lt;p&gt;Window functions often do care about order, especially for time-based analysis.&lt;/p&gt;

&lt;p&gt;Suppose you want each customer’s running total spending over time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;
        &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;order_date&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;running_customer_revenue&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For customer 101, the results would look like this:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;customer_id&lt;/th&gt;
&lt;th&gt;order_date&lt;/th&gt;
&lt;th&gt;revenue&lt;/th&gt;
&lt;th&gt;running_customer_revenue&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;2026-01-01&lt;/td&gt;
&lt;td&gt;500&lt;/td&gt;
&lt;td&gt;500&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;2026-01-05&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;td&gt;530&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The window is no longer the entire customer history at once. It expands through ordered rows.&lt;/p&gt;

&lt;p&gt;This is especially useful for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cumulative revenue&lt;/li&gt;
&lt;li&gt;Cumulative sign-ups&lt;/li&gt;
&lt;li&gt;Cumulative conversion counts&lt;/li&gt;
&lt;li&gt;Running account balances&lt;/li&gt;
&lt;li&gt;User engagement over time&lt;/li&gt;
&lt;li&gt;Inventory movement&lt;/li&gt;
&lt;li&gt;Daily active user trends&lt;/li&gt;
&lt;li&gt;Progress toward monthly targets&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When multiple events can occur at the same timestamp or date, add a tie-breaker to ensure deterministic ordering:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order_id&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without a stable ordering rule, running totals and row sequence functions can produce ambiguous results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Window frames: controlling which rows are included
&lt;/h2&gt;

&lt;p&gt;A window frame refines the set of rows considered around the current row.&lt;/p&gt;

&lt;p&gt;For example, a rolling three-day average might be written as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;daily_revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;order_date&lt;/span&gt;
    &lt;span class="k"&gt;ROWS&lt;/span&gt; &lt;span class="k"&gt;BETWEEN&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="k"&gt;PRECEDING&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="k"&gt;CURRENT&lt;/span&gt; &lt;span class="k"&gt;ROW&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;rolling_3_day_average&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This calculates an average using the current row and the two prior rows.&lt;/p&gt;

&lt;p&gt;Frames are especially valuable in time-series analysis. Common examples include:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ROWS&lt;/span&gt; &lt;span class="k"&gt;BETWEEN&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="k"&gt;PRECEDING&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="k"&gt;CURRENT&lt;/span&gt; &lt;span class="k"&gt;ROW&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for a seven-row rolling average, or:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ROWS&lt;/span&gt; &lt;span class="k"&gt;BETWEEN&lt;/span&gt; &lt;span class="n"&gt;UNBOUNDED&lt;/span&gt; &lt;span class="k"&gt;PRECEDING&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="k"&gt;CURRENT&lt;/span&gt; &lt;span class="k"&gt;ROW&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for a running total from the start of the partition.&lt;/p&gt;

&lt;p&gt;However, one should be careful with the difference between row-based and time-based frames. A frame of “six preceding rows” is not always equivalent to “the previous six calendar days.” If dates are missing, there may be fewer than seven days represented. Some SQL systems support range-based or interval-based frames, while others require generating a complete date spine first.&lt;/p&gt;

&lt;p&gt;This distinction matters a great deal in production metrics. A “seven-day moving average” should normally mean seven calendar days, not simply seven available observations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ranking functions: a major window-function use case
&lt;/h2&gt;

&lt;p&gt;Ranking is one of the clearest examples of a task that window functions solve elegantly.&lt;/p&gt;

&lt;p&gt;Suppose you want to rank customers by their total spending:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;customer_revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;revenue_rank&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, aggregate and window functions work together. The query first produces one row per customer with &lt;code&gt;SUM(revenue)&lt;/code&gt;. The window function then ranks those customer-level rows.&lt;/p&gt;

&lt;p&gt;You might use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;DENSE_RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;ROW_NUMBER&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;NTILE&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The differences matter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ROW_NUMBER()&lt;/code&gt; gives every row a unique sequential number.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;RANK()&lt;/code&gt; gives tied rows the same rank and leaves gaps afterward.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;DENSE_RANK()&lt;/code&gt; gives tied rows the same rank but does not leave gaps.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;NTILE(n)&lt;/code&gt; divides ordered rows into approximately equal-sized buckets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, &lt;code&gt;NTILE(10)&lt;/code&gt; is frequently used to assign customers to deciles based on lifetime value, engagement, risk score, or predicted propensity.&lt;/p&gt;

&lt;p&gt;A practical customer segmentation query could look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;customer_metrics&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt;
        &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;lifetime_value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;order_count&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
    &lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;lifetime_value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;order_count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;NTILE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;lifetime_value&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;value_quartile&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customer_metrics&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This produces a straightforward first-pass segmentation of customers into value quartiles.&lt;/p&gt;

&lt;h2&gt;
  
  
  LAG and LEAD: comparing rows across time
&lt;/h2&gt;

&lt;p&gt;Window functions also enable comparisons between one row and nearby rows. &lt;code&gt;LAG()&lt;/code&gt; retrieves a previous row’s value; &lt;code&gt;LEAD()&lt;/code&gt; retrieves a later row’s value.&lt;/p&gt;

&lt;p&gt;For a daily revenue table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;daily_revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;LAG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;daily_revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;order_date&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;previous_day_revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;daily_revenue&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;
        &lt;span class="n"&gt;LAG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;daily_revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;order_date&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;day_over_day_change&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;daily_sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This lets you calculate changes over time without a self-join.&lt;/p&gt;

&lt;p&gt;You can also calculate percentage change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;daily_revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;daily_revenue&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;
        &lt;span class="n"&gt;LAG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;daily_revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;
    &lt;span class="k"&gt;NULLIF&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;LAG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;daily_revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;day_over_day_growth_pct&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;daily_sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;NULLIF&lt;/code&gt; prevents a division-by-zero error.&lt;/p&gt;

&lt;p&gt;For customer behavior, &lt;code&gt;LAG()&lt;/code&gt; can help answer questions such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How many days passed between purchases?&lt;/li&gt;
&lt;li&gt;Was this customer’s order larger than their previous order?&lt;/li&gt;
&lt;li&gt;Has user activity increased or declined?&lt;/li&gt;
&lt;li&gt;Did a customer upgrade or downgrade their plan?&lt;/li&gt;
&lt;li&gt;Did a product’s weekly demand change materially?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;LAG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;
        &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;order_date&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;previous_order_date&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can then calculate purchase intervals and use them in recency-frequency-monetary analysis, churn modeling, or customer lifecycle reporting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Aggregates and windows often work best together
&lt;/h2&gt;

&lt;p&gt;The question should not be “Which one should I use?” in an absolute sense. Mature analytical queries often use both.&lt;/p&gt;

&lt;p&gt;For instance, imagine you want to calculate each category’s monthly sales, then determine each category’s share of total monthly sales:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;monthly_category_sales&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt;
        &lt;span class="n"&gt;DATE_TRUNC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'month'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="k"&gt;month&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;category&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;category_revenue&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
    &lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt;
        &lt;span class="n"&gt;DATE_TRUNC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'month'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;category&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="k"&gt;month&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;category&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;category_revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;category_revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="k"&gt;month&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;total_monthly_revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;category_revenue&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;
        &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;category_revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="k"&gt;month&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;monthly_revenue_share&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;monthly_category_sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The aggregate stage establishes the desired analytical grain: one row per category per month. The window stage adds context: each category’s contribution to the month’s total.&lt;/p&gt;

&lt;p&gt;This two-stage pattern is extremely common in analytics engineering and data science:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Aggregate raw event data to the correct grain.&lt;/li&gt;
&lt;li&gt;Use window functions to compare groups, rank them, calculate rolling statistics, or create relative measures.&lt;/li&gt;
&lt;li&gt;Feed the resulting table into a dashboard, statistical analysis, or machine-learning workflow.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Common mistakes to avoid
&lt;/h2&gt;

&lt;p&gt;One common mistake is mixing grouped and ungrouped columns incorrectly. This query is invalid in most SQL engines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problem is that &lt;code&gt;order_date&lt;/code&gt; is neither grouped nor aggregated. SQL does not know which order date to choose for each customer.&lt;/p&gt;

&lt;p&gt;Another common mistake is using an aggregate when a window is needed. If you need to see every transaction plus a customer average, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;rather than grouping by customer and losing the transaction records.&lt;/p&gt;

&lt;p&gt;A third mistake is filtering window-function results in &lt;code&gt;WHERE&lt;/code&gt;. Window functions are calculated after the &lt;code&gt;WHERE&lt;/code&gt; clause in the logical query-processing order. For example, this usually will not work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;revenue&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;revenue_rank&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;revenue_rank&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead, place the window calculation in a subquery or common table expression:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;ranked_orders&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt;
        &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;revenue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;revenue&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;revenue_rank&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;ranked_orders&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;revenue_rank&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some databases provide a &lt;code&gt;QUALIFY&lt;/code&gt; clause that makes this pattern more concise, but it is not universally available.&lt;/p&gt;

&lt;p&gt;Finally, be cautious about unintended partitions. Leaving out &lt;code&gt;PARTITION BY&lt;/code&gt; means the calculation runs across all rows. Including the wrong partition can create misleading results that appear plausible. Always ask: “Which rows should count as this row’s peers?”&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion(Choosing the right tool)
&lt;/h2&gt;

&lt;p&gt;Use aggregate functions when you want to reduce a dataset into a summary at a new grain. They are excellent for dashboard metrics, grouped reports, and compact analytical tables.&lt;/p&gt;

&lt;p&gt;Use window functions when you need row-level detail plus group-level or time-based context. They are particularly valuable for ranks, percent-of-total calculations, running totals, rolling averages, prior-period comparisons, sessionization, and feature engineering.&lt;/p&gt;

&lt;p&gt;Aggregate functions tell you what happened at a summary level. Window functions help explain how each observation fits into the broader pattern. Together, they turn SQL from a reporting language into a flexible system for analytical reasoning.&lt;/p&gt;

</description>
      <category>analytics</category>
      <category>database</category>
      <category>datascience</category>
      <category>sql</category>
    </item>
    <item>
      <title>Scikit-Learn, Pipeline Fundamentals: A Titanic Survival Prediction Guide</title>
      <dc:creator>Mark Glemba</dc:creator>
      <pubDate>Sat, 12 Sep 2026 20:36:52 +0000</pubDate>
      <link>https://dev.to/mark_glemba_962f6bc8a12dd/scikit-learn-pipeline-fundamentals-a-titanic-survival-prediction-guide-2nlp</link>
      <guid>https://dev.to/mark_glemba_962f6bc8a12dd/scikit-learn-pipeline-fundamentals-a-titanic-survival-prediction-guide-2nlp</guid>
      <description>&lt;p&gt;Machine learning workflows often suffer from code duplication, data leakage, and hyperparameter tuning complexities. Scikit-Learn's &lt;code&gt;Pipeline&lt;/code&gt; and &lt;code&gt;ColumnTransformer&lt;/code&gt; modules simplify this by combining feature preprocessing and model estimation into an integrated, reproducible object.&lt;/p&gt;

&lt;p&gt;This guide demonstrates a complete predictive modeling workflow using the classic &lt;strong&gt;Titanic: Machine Learning from Disaster&lt;/strong&gt; dataset, covering exploratory data analysis, pipeline-based feature engineering, model selection, and cross-validation.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Environment Setup &amp;amp; Data Loading
&lt;/h2&gt;

&lt;p&gt;Begin by importing the necessary libraries for data manipulation, visualization, preprocessing, modeling, and evaluation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;seaborn&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;sns&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;

&lt;span class="c1"&gt;# Model selection &amp;amp; evaluation
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.model_selection&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;train_test_split&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;StratifiedKFold&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cross_val_score&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.metrics&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;roc_auc_score&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;classification_report&lt;/span&gt;

&lt;span class="c1"&gt;# Preprocessing &amp;amp; Pipelines
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.pipeline&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Pipeline&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.impute&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;SimpleImputer&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.preprocessing&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;StandardScaler&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;OneHotEncoder&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.compose&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ColumnTransformer&lt;/span&gt;

&lt;span class="c1"&gt;# Classifiers
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.linear_model&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;LogisticRegression&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.neighbors&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;KNeighborsClassifier&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.ensemble&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;RandomForestClassifier&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;GradientBoostingClassifier&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.svm&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;SVC&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;xgboost&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;XGBClassifier&lt;/span&gt;

&lt;span class="c1"&gt;# Load dataset
&lt;/span&gt;&lt;span class="n"&gt;titanic_df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;data/train.csv&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  2. Exploratory Data Analysis &amp;amp; Data Sanitation
&lt;/h2&gt;

&lt;p&gt;A quick inspection of the dataset structure reveals the feature types, missing values, and potential columns to drop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;basic_checks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Shape:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shape&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Missing Values:&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isnull&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Data Types:&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dtypes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;basic_checks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;titanic_df&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Missing Value Analysis
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;Age&lt;/code&gt;&lt;/strong&gt;: Missing &lt;strong&gt;19.87%&lt;/strong&gt; of data (177 missing values).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;Embarked&lt;/code&gt;&lt;/strong&gt;: Missing &lt;strong&gt;0.22%&lt;/strong&gt; of data (2 missing values).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;Cabin&lt;/code&gt;&lt;/strong&gt;: Missing &lt;strong&gt;77.10%&lt;/strong&gt; of data (687 missing values).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Due to the extreme proportion of missing data, the &lt;code&gt;Cabin&lt;/code&gt; column is dropped.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;titanic_df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;titanic_df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Cabin&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  3. Train-Test Split &amp;amp; Data Partitioning
&lt;/h2&gt;

&lt;p&gt;Identifiers such as &lt;code&gt;PassengerId&lt;/code&gt;, &lt;code&gt;Name&lt;/code&gt;, and &lt;code&gt;Ticket&lt;/code&gt; carry no predictive power for survival and are excluded from the feature set $X$. We split the data using a &lt;strong&gt;80/20 train-test split&lt;/strong&gt; stratified by the target column &lt;code&gt;Survived&lt;/code&gt; to maintain class proportions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Separate features and target
&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;titanic_df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;PassengerId&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Name&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Ticket&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Survived&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;titanic_df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Survived&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# Categorize feature types
&lt;/span&gt;&lt;span class="n"&gt;numeric_columns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Age&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;SibSp&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Parch&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Fare&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;categorical_columns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Pclass&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Sex&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Embarked&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# Stratified split
&lt;/span&gt;&lt;span class="n"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;train_test_split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;test_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;random_state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stratify&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  4. Building Scikit-Learn Preprocessing Pipelines
&lt;/h2&gt;

&lt;p&gt;To avoid &lt;strong&gt;data leakage&lt;/strong&gt; (such as calculating the mean or standard deviation on the entire dataset before splitting), transformations must be learned only on the training set. Using &lt;code&gt;Pipeline&lt;/code&gt; and &lt;code&gt;ColumnTransformer&lt;/code&gt; ensures these transformations are safely applied during cross-validation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# 1. Numerical Pipeline: Impute missing values with median, then scale
&lt;/span&gt;&lt;span class="n"&gt;numerical_pipeline&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Pipeline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;steps&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;imputer&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;SimpleImputer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strategy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;median&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;scaler&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;StandardScaler&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="c1"&gt;# 2. Categorical Pipeline: Impute missing values with mode, then One-Hot Encode
&lt;/span&gt;&lt;span class="n"&gt;categorical_pipeline&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Pipeline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;steps&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;imputer&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;SimpleImputer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strategy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;most_frequent&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;onehot&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;OneHotEncoder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;handle_unknown&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ignore&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="c1"&gt;# 3. Combine Preprocessing Steps
&lt;/span&gt;&lt;span class="n"&gt;preprocessor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ColumnTransformer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;transformers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;num&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numerical_pipeline&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numeric_columns&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;cat&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;categorical_pipeline&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;categorical_columns&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;])&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  5. Model Candidate Comparison &amp;amp; Stratified Cross-Validation
&lt;/h2&gt;

&lt;p&gt;Evaluate multiple classification algorithms using &lt;strong&gt;5-Fold Stratified Cross-Validation&lt;/strong&gt; evaluated on the $F_1$-score metric.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Define candidate models
&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Logistic Regression&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;LogisticRegression&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_iter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;K-Nearest Neighbors&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;KNeighborsClassifier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n_neighbors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;metric&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;euclidean&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Random Forest&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;RandomForestClassifier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n_estimators&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_depth&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;random_state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Support Vector Machine&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;SVC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;kernel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;rbf&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;probability&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;random_state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Gradient Boosting&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;GradientBoostingClassifier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n_estimators&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_depth&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;random_state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# Cross-Validation setup
&lt;/span&gt;&lt;span class="n"&gt;cv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;StratifiedKFold&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n_splits&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shuffle&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;random_state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="c1"&gt;# Chain preprocessing and model estimation into a single pipeline
&lt;/span&gt;    &lt;span class="n"&gt;full_pipeline&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Pipeline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;steps&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;preprocessor&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;preprocessor&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;model&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;])&lt;/span&gt;

    &lt;span class="n"&gt;cv_scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;cross_val_score&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;full_pipeline&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cv&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cv&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scoring&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;f1&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n_jobs&lt;/span&gt;&lt;span class="o"&gt;=-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Mean F1 Score&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cv_scores&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Std Dev&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cv_scores&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;std&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# Display results in a table
&lt;/span&gt;&lt;span class="n"&gt;results_df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DataFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort_values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;by&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Mean F1 Score&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ascending&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Model Performance Metrics
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model Classifier&lt;/th&gt;
&lt;th&gt;Mean $F_1$ Score&lt;/th&gt;
&lt;th&gt;Standard Deviation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Support Vector Machine (SVM)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0.7447&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0.0311&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Random Forest&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0.7374&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0.0200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Logistic Regression&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0.7301&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0.0217&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;K-Nearest Neighbors&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0.7194&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0.0229&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Gradient Boosting&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0.7002&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0.0233&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  6. Key Takeaways &amp;amp; Best Practices
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Preventing Data Leakage&lt;/strong&gt;: Wrapping feature engineering steps inside a &lt;code&gt;Pipeline&lt;/code&gt; guarantees that statistics (e.g., mean/median for imputation, standard deviations for scaling) are calculated strictly on training folds during cross-validation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Handling Mixed Data Types&lt;/strong&gt;: &lt;code&gt;ColumnTransformer&lt;/code&gt; cleanly routes numerical features to continuous scaling modules and categorical variables to encoding blocks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Model Verdict&lt;/strong&gt;: The &lt;strong&gt;Support Vector Machine (SVM)&lt;/strong&gt; achieved the highest mean $F_1$-score ($0.7447$), with &lt;strong&gt;Random Forest&lt;/strong&gt; displaying the highest stability across folds with the lowest variance ($\sigma = 0.0200$).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>datascience</category>
      <category>machinelearning</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Machine Learning and Its Real-World Impacts</title>
      <dc:creator>Mark Glemba</dc:creator>
      <pubDate>Sat, 12 Sep 2026 17:47:11 +0000</pubDate>
      <link>https://dev.to/mark_glemba_962f6bc8a12dd/machine-learning-and-its-real-world-impacts-2j3n</link>
      <guid>https://dev.to/mark_glemba_962f6bc8a12dd/machine-learning-and-its-real-world-impacts-2j3n</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;Machine learning is one of the most important areas of modern technology. It is behind many tools people use every day, including search engines, social media recommendations, voice assistants, online shopping suggestions, fraud detection systems, and navigation apps. Although the phrase may sound complex at first, the central idea is quite simple: machine learning enables computers to learn patterns from data and use those patterns to make predictions, decisions, or recommendations.&lt;/p&gt;

&lt;p&gt;For a new student, machine learning can be understood as teaching a computer through examples rather than giving it every rule manually. Instead of writing thousands of instructions explaining how to identify a cat in a photo, developers can show a computer many labeled images of cats and non-cats. Over time, the system learns useful visual patterns, such as ears, fur, eyes, and body shapes. It can then make a reasonable guess when shown a new image.&lt;/p&gt;

&lt;p&gt;This article introduces the main ideas of machine learning, explains common types of learning, discusses the usual development process, and explores how machine learning is applied in the real world.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. What Exactly is Machine Learning?
&lt;/h2&gt;

&lt;p&gt;At its core, Machine Learning is a branch of Artificial Intelligence (AI) focused on building applications that learn from data and improve their accuracy over time without being explicitly programmed.&lt;/p&gt;

&lt;p&gt;Machine learning is one way to achieve AI. It focuses on creating algorithms that improve their performance by learning from data.&lt;/p&gt;

&lt;p&gt;Machine learning does not mean that a computer thinks exactly like a person. It means that the computer uses mathematical methods to learn from examples and make useful outputs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Data Matters
&lt;/h3&gt;

&lt;p&gt;Data is the foundation of machine learning. A model can only learn from the information it receives, so the quality of the data strongly affects the quality of the result.&lt;/p&gt;

&lt;p&gt;Data can come in many forms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Numbers, such as house prices or temperatures&lt;/li&gt;
&lt;li&gt;Text, such as emails, reviews, and news articles&lt;/li&gt;
&lt;li&gt;Images, such as medical scans or photographs&lt;/li&gt;
&lt;li&gt;Audio, such as voice recordings and music&lt;/li&gt;
&lt;li&gt;Video, such as security-camera footage&lt;/li&gt;
&lt;li&gt;Records of behavior, such as purchases, clicks, or travel routes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, more data is not always better if the data is poor, incomplete, outdated, or unfair. If a model is trained using biased data, it may produce biased results. This is why collecting, cleaning, checking, and protecting data are important parts of machine-learning work.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. The Main Types of Machine Learning
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Supervised Learning
&lt;/h3&gt;

&lt;p&gt;The algorithm is provided with a training dataset that contains both the input data (features) and the correct output labels (targets). The goal of the algorithm is to learn a function that maps inputs to outputs so accurately that it can predict the label for brand-new, unseen data.&lt;/p&gt;

&lt;p&gt;Supervised learning generally splits into two sub-categories:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;1. Classification:&lt;/em&gt; The output target is a discrete category or class.&lt;/p&gt;

&lt;p&gt;Examples: Is this image a cat or a dog? &lt;/p&gt;

&lt;p&gt;&lt;em&gt;2. Regression:&lt;/em&gt; The output target is a continuous numeric value.&lt;/p&gt;

&lt;p&gt;Examples: Predicting house prices based on size and location, or estimating temperature.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Unsupervised Learning
&lt;/h3&gt;

&lt;p&gt;Here, the algorithm is given input data without any target labels and is tasked with finding inherent structures, patterns, or groupings on its own.&lt;/p&gt;

&lt;p&gt;Key techniques in unsupervised learning include:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;1. Clustering:&lt;/em&gt; Grouping similar data points together based on shared characteristics.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;2. Dimensionality Reduction:&lt;/em&gt; Simplifying complex datasets with hundreds of features into fewer features while preserving essential information.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;3. Anomaly Detection:&lt;/em&gt; Identifying data points that deviate significantly from the norm.&lt;/p&gt;

&lt;p&gt;Example: Spotting unusual system logs or structural flaws in industrial equipment.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Reinforcement Learning
&lt;/h3&gt;

&lt;p&gt;Reinforcement learning is inspired by learning through experience. In this approach, an agent takes actions in an environment and receives rewards or penalties based on the results.&lt;/p&gt;

&lt;p&gt;The agent’s goal is to learn which actions lead to the best long-term reward.&lt;/p&gt;

&lt;p&gt;A simple example is training a computer program to play a game. The program tries different moves. If a move helps it win, it receives a positive reward. If it loses, it receives a negative reward. After many attempts, it learns strategies that improve its chances of winning.&lt;/p&gt;

&lt;p&gt;Reinforcement learning is used in areas such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Game-playing systems&lt;/li&gt;
&lt;li&gt;Robotics&lt;/li&gt;
&lt;li&gt;Traffic-signal optimization&lt;/li&gt;
&lt;li&gt;Resource management&lt;/li&gt;
&lt;li&gt;Some autonomous systems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It can be powerful, but it is often more difficult to train than supervised learning because the system may need many attempts before discovering successful behavior.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. The Lifecycle of a Machine Learning Project
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;1. Problem Formulation:&lt;/em&gt; Defining what we want to predict or discover. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;2. Data Collection:&lt;/em&gt; Gathering relevant, high-quality data.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;3. Data Preprocessing and Cleaning:&lt;/em&gt; Cleaning messy data, handling missing values, normalizing numerical scales, and converting raw inputs into mathematical vectors that algorithms can work with.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;4. Model Training:&lt;/em&gt; Selecting an appropriate algorithm (e.g., Linear Regression, Decision Trees, Neural Networks) and letting it iteratively compute the mathematical weights that best represent the patterns in the training set.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;5. Model Evaluation:&lt;/em&gt; Testing the trained model against a separate "test dataset" that the model has never seen before. This step checks whether the model actually learned general concepts or merely memorized the training data ( known as overfitting).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;6. Deployment and Continuous Monitoring:&lt;/em&gt; Integrating the validated model into a production system and monitoring its performance over time to ensure its predictions remain accurate as real-world conditions evolve.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Real-World Applications: Machine Learning in Everyday Life
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;A. Healthcare and Biomedical Science&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Machine learning is driving some of its most meaningful breakthroughs in medicine. By acting as an advanced diagnostic assistant, ML empowers medical professionals to detect diseases earlier and tailor treatments to individual patients.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Medical Imaging Analysis:&lt;/em&gt; Convolutional Neural Networks (CNNs)—a class of deep learning models designed for processing visual data—can analyze X-rays, MRIs, and CT scans to detect early-stage tumors, bone fractures, or diabetic retinopathy. In many studies, these models achieve diagnostic accuracy on par with seasoned radiologists.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Drug Discovery:&lt;/em&gt; ML algorithms can simulate molecular structures, predict how potential drug compounds will interact with biological targets, and narrow down candidate molecules in days rather than years.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Predictive Diagnostics:&lt;/em&gt; By evaluating electronic health records, heart rate metrics from wearables, and blood markers, predictive models can flag patients at high risk of developing conditions like sepsis or heart failure before acute symptoms manifest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B. Finance and Banking&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Fraud Detection:&lt;/em&gt; Every time you swipe your credit card, a machine learning model evaluates the transaction in milliseconds. It compares the location, dollar amount, merchant type, and purchase velocity against your historical habits. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Algorithmic Trading:&lt;/em&gt; Financial institutions use complex ML models to analyze market trends, sentiment from financial news releases, and economic indicators to execute trades at optimized prices and microsecond speeds.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Credit Scoring and Risk Assessment:&lt;/em&gt; Rather than relying solely on rigid rule-based credit scores, modern fintech companies use ML models to evaluate alternative data sources, allowing them to extend credit safely to underbanked individuals who lack traditional financial histories.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C. E-Commerce and Personal Entertainment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Streaming Services (Netflix, Spotify):&lt;/em&gt; Recommendation systems utilize techniques like Collaborative Filtering and Content-Based Filtering. By comparing your watching or listening history with millions of other users who share similar tastes, the system can predict with surprising accuracy which movie or song you are likely to enjoy next.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Dynamic Pricing:&lt;/em&gt; Companies like Uber, Airbnb, and airlines use ML algorithms to adjust prices dynamically based on real-time factors including current demand, local weather conditions, traffic flow, time of day, and historical booking patterns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;D. Autonomous Systems and Transportation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Autonomous Vehicles:&lt;/em&gt; Companies building self-driving cars rely on computer vision models to identify lane markings, interpret traffic signals, track pedestrians, and predict the movements of surrounding vehicles in real time.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Smart Logistics:&lt;/em&gt; Global shipping companies use machine learning to optimize delivery routes, forecast inventory demands at regional warehouses, and minimize fuel consumption across global supply chains.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;E. Natural Language Processing (NLP) and Generative AI&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Large Language Models (LLMs) and Assistants:&lt;/em&gt; Virtual assistants, automated translation services, and modern generative AI tools utilize massive neural network architectures (specifically Transformers) to parse human context, summarize complex documents, write functional code, and engage in natural conversations.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Sentiment Analysis:&lt;/em&gt; Brands use NLP algorithms to analyze millions of social media posts, product reviews, and customer support tickets to gauge public sentiment toward products or services in real time.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Key Challenges and Ethical Considerations
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌─────────────────────────────────────────────────────────────┐
│                Ethical &amp;amp; Practical Challenges               │
├──────────────────────────────┬──────────────────────────────┤
│ ⚖️ Algorithmic Bias          │ Models inherit and amplify   │
│                              │ human biases in data.        │
├──────────────────────────────┼──────────────────────────────┤
│ 🔍 Lack of Transparency      │ "Black Box" models make      │
│                              │ decisions hard to explain.   │
├──────────────────────────────┼──────────────────────────────┤
│ 🔒 Privacy Concerns          │ Training requires vast amounts│
│                              │ of sensitive personal data.  │
├──────────────────────────────┼──────────────────────────────┤
│ ⚡ Overfitting &amp;amp; Reliability  │ Models can fail unexpectedly  │
│                              │ when real-world data shifts. │
└──────────────────────────────┴──────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;1. Data Bias and Fairness&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If training data does not represent all groups fairly, the model may perform better for some people than others. For example, a facial-recognition system trained on limited types of faces may be less accurate for underrepresented groups.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The "Black Box" Problem (Explainability)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While simple algorithms like decision trees are easy to audit, complex deep neural networks consist of millions—or even billions—of mathematical parameters. This creates a "black box" scenario: the model may yield highly accurate outputs, but engineers cannot easily trace why or how it reached a specific decision. In high-stakes environments like criminal justice sentencing or medical diagnoses, this lack of transparency presents major safety and legal hurdles.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Data Privacy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Many machine-learning systems depend on personal data, including location, browsing history, medical records, and purchasing behavior. Organizations must collect and use this data responsibly.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Conclusion
&lt;/h2&gt;

&lt;p&gt;Machine learning is a way of building computer systems that learn from data. Instead of writing a separate rule for every possible situation, developers train models using examples. These models can then make predictions, classify information, recognize patterns, and support decisions.&lt;/p&gt;

&lt;p&gt;It is a combination of data, mathematics, algorithms, testing, and human judgment. A good machine-learning system depends not only on technical skill, but also on responsible design, high-quality data, fairness, privacy, and careful evaluation.&lt;/p&gt;

&lt;p&gt;It is already used in healthcare, banking, transportation, education, agriculture, entertainment, cybersecurity, and many other fields. Its influence will likely continue to grow as more data, computing power, and research become available.&lt;/p&gt;

&lt;p&gt;Learning the basics of machine learning opens the door to understanding many technologies that shape daily life. It also gives students the opportunity to think critically about how these technologies should be designed and used in the future.&lt;/p&gt;

</description>
      <category>datascience</category>
    </item>
    <item>
      <title>Understanding Unsupervised Machine Learning</title>
      <dc:creator>Mark Glemba</dc:creator>
      <pubDate>Wed, 09 Sep 2026 09:57:48 +0000</pubDate>
      <link>https://dev.to/mark_glemba_962f6bc8a12dd/understanding-unsupervised-machine-learning-4j7d</link>
      <guid>https://dev.to/mark_glemba_962f6bc8a12dd/understanding-unsupervised-machine-learning-4j7d</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Machine learning is a branch of artificial intelligence that allows computers to learn patterns from data. Instead of writing every rule manually, we provide a computer with examples and let it discover useful relationships. Machine learning is used in many parts of daily life, including recommendation systems, fraud detection, voice assistants, online shopping, medical research, social media, and banking.&lt;/p&gt;

&lt;p&gt;There are several major types of machine learning. One of the most important is called &lt;strong&gt;unsupervised machine learning&lt;/strong&gt;. It is especially useful when we have a large amount of data but do not already know the correct answers or categories for that data.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Unsupervised Machine Learning?
&lt;/h2&gt;

&lt;p&gt;In traditional Supervised Machine Learning, models learn with a teacher or a supervisor. We feed the computer input data paired with correct answers (called labels). For example, we show thousands of pictures labeled "Cat" or "Dog", and the model learns the relationship between the pixels and the labels.In Unsupervised Machine Learning, there is no teacher, no supervisor, and—most importantly—no ground truth labels.We feed the algorithm raw data without target outputs. The algorithm's sole goal is to inspect the data, uncover hidden mathematical structures, detect repeating patterns, and group similar data points together.&lt;/p&gt;

&lt;h3&gt;
  
  
  Supervised vs. Unsupervised Learning
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5roxm4wepn0nda1hoks1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5roxm4wepn0nda1hoks1.png" alt=" " width="800" height="303"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Do We Need Unsupervised Learning?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Data Labeling is Expensive and Slow:&lt;/strong&gt; In the real world, human annotation is time-consuming and costly. Unsupervised learning allows us to make sense of vast datasets before or without labeling them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discovering Unknown Patterns:&lt;/strong&gt; Humans are inherently limited by their own biases and domain knowledge. Unsupervised learning can discover connections in data that humans never thought to look for.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Compression and Feature Extraction:&lt;/strong&gt; Unsupervised techniques help simplify complex datasets, making them easier to visualize, store, and feed into downstream predictive models.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Branch 1: Clustering
&lt;/h2&gt;

&lt;p&gt;Clustering is the task of partitioning a dataset into distinct groups (or clusters) such that data points in the same group are more similar to each other than to those in other groups.       &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4c5fl73hpo1viumh6r8u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4c5fl73hpo1viumh6r8u.png" alt=" " width="623" height="145"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Three most important clustering algorithms.&lt;/p&gt;

&lt;h3&gt;
  
  
  A. K-Means Clustering
&lt;/h3&gt;

&lt;p&gt;K-Means is the workhorse of clustering algorithms due to its speed and simplicity.&lt;br&gt;
How K-Means Works Step-by-Step:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Choose &lt;code&gt;$K$&lt;/code&gt;: Decide how many clusters ($K$) you want to discover.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Initialize Centroids: Randomly place $K$ points in the feature space. These points act as the initial center points (centroids) of your clusters.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Assign Points: Calculate the distance (usually Euclidean distance) between every data point and all &lt;code&gt;$K$&lt;/code&gt; centroids. Assign each data point to its nearest centroid.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update Centroids: Recompute the position of each centroid by taking the average (mean) of all data points assigned to that cluster.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Repeat: Repeat steps 3 and 4 until the centroids stop moving (convergence) or a maximum number of iterations is reached.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;The Math Behind Distance Calculation&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To measure how close two data points $A = (a_1, a_2, \dots, a_n)$ and $B = (b_1, b_2, \dots, b_n)$ are, K-Means uses the standard Euclidean distance formula:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$d(A, B) = \sqrt{\sum_{i=1}^{n} (a_i - b_i)^2}$$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;Finding the Right $K$:&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Elbow Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We plot the Within-Cluster Sum of Squares (WCSS) against various values of &lt;code&gt;$K$&lt;/code&gt;. As &lt;code&gt;$K$&lt;/code&gt; increases, WCSS decreases because clusters become smaller and tighter. The optimal $K$ is located at the "elbow" point—where the rate of decrease dramatically slows down.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$$\text{WCSS} = \sum_{k=1}^{K} \sum_{x \in C_k} \vert{}\vert{}x - \mu_k\vert{}\vert{}^2$$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Where &lt;code&gt;$C_k$&lt;/code&gt; is the set of points in cluster &lt;code&gt;$k$&lt;/code&gt;, and &lt;code&gt;$\mu_k$&lt;/code&gt; &lt;br&gt;
 is the mean/centroid of cluster &lt;code&gt;$k$&lt;/code&gt;.)&lt;/p&gt;
&lt;h3&gt;
  
  
  B. Hierarchical Clustering
&lt;/h3&gt;

&lt;p&gt;Unlike K-Means, which requires you to pre-define &lt;code&gt;$K$&lt;/code&gt;, Hierarchical Clustering creates a nested hierarchy of clusters presented as a tree-like diagram called a Dendrogram.&lt;br&gt;
There are two primary approaches:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Agglomerative (Bottom-Up):&lt;/em&gt; Starts with every single data point as its own individual cluster. In each step, the two closest clusters are merged until only one grand cluster remains.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Divisive (Top-Down):&lt;/em&gt; Starts with all data points inside a single master cluster and recursively splits them into smaller sub-clusters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Dendrogram?&lt;/strong&gt;&lt;br&gt;
A dendrogram illustrates how clusters are progressively combined or split. By drawing a horizontal line across the dendrogram at a specific height threshold, you can "cut" the tree and choose the number of clusters that best fits your problem.&lt;/p&gt;
&lt;h3&gt;
  
  
  C. DBSCAN (Density-Based Spatial Clustering of Applications with Noise)
&lt;/h3&gt;

&lt;p&gt;Both K-Means and Hierarchical Clustering struggle when clusters have arbitrary, non-spherical shapes (like concentric circles or crescent shapes) or when data contains significant background noise.DBSCAN clusters points based on local data density rather than centroid distances.&lt;br&gt;
&lt;strong&gt;Key Concepts of DBSCAN:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;$\epsilon$&lt;/code&gt; (Epsilon):&lt;/em&gt; The maximum radius around a point to search for neighbors.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;MinPts:&lt;/em&gt; The minimum number of points required within the $\epsilon$-neighborhood to consider that area a "dense region".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Point Classification in DBSCAN:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;1. Core Point:&lt;/em&gt; Has at least &lt;code&gt;MinPts&lt;/code&gt; within its &lt;code&gt;$\epsilon$&lt;/code&gt;-radius.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;2. Border Point:&lt;/em&gt; Lies within the &lt;code&gt;$\epsilon$&lt;/code&gt;-radius of a Core Point but has fewer than &lt;code&gt;MinPts&lt;/code&gt; in its own radius.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;3. Noise Point (Outlier):&lt;/em&gt; Any point that is neither a Core Point nor a Border Point.      &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantage of DBSCAN:&lt;/strong&gt; It automatically identifies outliers as noise and can discover complex cluster topologies without needing &lt;code&gt;$K$&lt;/code&gt; specified upfront&lt;/p&gt;
&lt;h2&gt;
  
  
  Core Branch 2: Dimensionality Reduction
&lt;/h2&gt;

&lt;p&gt;Modern datasets often suffer from the Curiosity of High Dimensionality. &lt;br&gt;
Dimensionality Reduction reduces the number of random variables under consideration by obtaining a set of principal features, compressing the data while retaining as much critical information as possible.&lt;/p&gt;
&lt;h3&gt;
  
  
  A. Principal Component Analysis (PCA)
&lt;/h3&gt;

&lt;p&gt;PCA is a linear dimensionality reduction technique. It reorients the dataset into a new coordinate system such that maximum variance is captured in the fewest possible axes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How PCA Works (Intuition):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Center the Data:&lt;/em&gt; Subtract the mean from each feature vector so the data centers around the origin &lt;code&gt;$(0,0)$&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Compute Covariance Matrix:&lt;/em&gt; Calculate how each variable correlates with every other variable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Find Eigenvectors and Eigenvalues:&lt;/em&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Eigenvectors&lt;/em&gt; represent the directions of the new coordinate axes (called Principal Components).&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Eigenvalues&lt;/em&gt; represent the amount of variance captured along each Principal Component.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Select Top Components:&lt;/em&gt; Sort the components by their eigenvalues and select the top &lt;code&gt;$k$&lt;/code&gt; components that explain most of the total variance (e.g., &lt;code&gt;$95\%$&lt;/code&gt; of original variance).  &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  B. t-SNE (t-Distributed Stochastic Neighbor Embedding)
&lt;/h3&gt;

&lt;p&gt;While PCA searches for global linear relationships, t-SNE is a non-linear technique designed specifically for visualizing high-dimensional data in 2D or 3D space.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Intuition Behind t-SNE:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Computes similarity probabilities between pairs of data points in high-dimensional space using a Gaussian distribution.&lt;/li&gt;
&lt;li&gt;Constructs a low-dimensional map (usually 2D) with points positioned such that neighboring points in the high-dimensional space remain close neighbors in the low-dimensional map.&lt;/li&gt;
&lt;li&gt;Uses a Student-t distribution in the low-dimensional space to solve the "crowding problem," allowing clusters to spread out nicely for clear visualization.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Core Branch 3: Anomaly Detection
&lt;/h2&gt;

&lt;p&gt;Anomaly Detection (or Outlier Detection) is the process of identifying rare events, items, or observations that raise suspicion by differing significantly from the vast majority of the data.&lt;br&gt;
Because anomalies are rare by definition, labeled anomaly datasets are extremely scarce. Unsupervised algorithms excel here by learning what "normal" data looks like and flagging anything that deviates from the norm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Algorithms for Anomaly Detection:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Isolation Forest:&lt;/em&gt; An tree-based algorithm that isolates anomalies instead of profiling normal points. Because anomalies are rare and different, they require fewer splits in a decision tree to be isolated compared to normal points.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;One-Class SVM:&lt;/em&gt; A variation of Support Vector Machines that fits a tight boundary around normal data points. Anything falling outside this decision boundary is flagged as an anomaly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Isolation Forest Split Tree Depth:

       Normal Points:  Root -&amp;gt; Split 1 -&amp;gt; Split 2 -&amp;gt; Split 3 -&amp;gt; Split 4 (Deep)
       Anomaly Point:  Root -&amp;gt; Split 1 (Isolated early!)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Core Branch 4: Autoencoders (Deep Unsupervised Learning)
&lt;/h2&gt;

&lt;p&gt;When we combine unsupervised concepts with Deep Neural Networks, we get Autoencoders.&lt;br&gt;
An Autoencoder is a neural network designed to copy its input to its output through a constrained bottleneck layer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; [ Input Data X ] ---&amp;gt; ( Encoder ) ---&amp;gt; [ Bottleneck / Latent Space ] ---&amp;gt; ( Decoder ) ---&amp;gt; [ Reconstruction X' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Architecture:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Encoder:&lt;/strong&gt; A series of layers that compresses the input data &lt;code&gt;$X$&lt;/code&gt; into a lower-dimensional representation (the Latent Space or Code).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Bottleneck:&lt;/strong&gt; The narrowest layer of the network that restricts the flow of information, forcing the network to learn only the most essential features.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Decoder:&lt;/strong&gt; A series of layers that attempts to reconstruct the original input from the latent code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Loss Function:
&lt;/h3&gt;

&lt;p&gt;The loss function measures how closely the reconstructed output &lt;code&gt;$\hat{X}$&lt;/code&gt; matches the original input &lt;code&gt;$X$&lt;/code&gt; (often measured via Mean Squared Error):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$$\text{Reconstruction Loss} = \vert{}\vert{}X - \hat{X}\vert{}\vert{}^2$$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Applications of Autoencoders:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Image Denoising:&lt;/strong&gt; Train the network using noisy images as input and clean images as output; the network learns to strip out background noise.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dimensionality Reduction:&lt;/strong&gt; Non-linear compression that often outperforms linear PCA.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Anomaly Reconstruction:&lt;/strong&gt; If an autoencoder is trained only on normal data, it will fail to reconstruct abnormal inputs, yielding a high reconstruction error that alerts operators.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-World Applications
&lt;/h2&gt;

&lt;p&gt;Unsupervised Machine Learning powers dozens of critical services across modern industries:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Customer Segmentation in Marketing:&lt;/em&gt; E-commerce platforms group customers by browsing behavior, purchase history, and spending habits to build personalized marketing campaigns.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Fraud Detection in Banking:&lt;/em&gt; Credit card processors monitor transactional patterns and flag unusual purchases occurring in unexpected geographical locations.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Gene Expression Analysis in Genomics:&lt;/em&gt; Scientists cluster human genetic patterns to uncover previously unknown biological sub-types of complex diseases.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Recommendation Engine Pre-processing:&lt;/em&gt; Streaming platforms use dimensionality reduction to handle massive user-item interaction matrices before generating recommendations.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Document Topic Modeling:&lt;/em&gt; Natural Language Processing (NLP) models organize millions of unstructured news articles into distinct topic groups automatically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary &amp;amp; Key Takeaways
&lt;/h2&gt;

&lt;p&gt;Unsupervised machine learning provides the toolkit to transform raw, unlabeled chaos into structured knowledge.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Clustering (K-Means, Hierarchical, DBSCAN) groups similar data points together based on distance or density metrics.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dimensionality Reduction (PCA, t-SNE) compresses high-dimensional feature spaces down to manageable components while preserving critical structural information.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Anomaly Detection isolates rare events by measuring deviations from learned normal distributions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Autoencoders leverage deep learning bottlenecks to extract rich latent representations from complex, unstructured data like images and video.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Unsupervised machine learning is a powerful way of learning from data that does not have predefined answers or labels. Instead of being told exactly what to look for, the model searches for hidden structures, similarities, relationships, and unusual observations.&lt;/p&gt;

&lt;p&gt;Its main uses include clustering similar items, finding products that occur together, simplifying complex data, and detecting unusual behavior. It is useful in business, health, cybersecurity, research, education, online platforms, and many other fields.&lt;/p&gt;

&lt;p&gt;The most important idea to remember is this:&lt;/p&gt;

&lt;p&gt;Unsupervised machine learning helps computers discover patterns in data when no one has already provided the correct categories or answers.&lt;/p&gt;

</description>
      <category>datascience</category>
    </item>
    <item>
      <title>Understanding Neural Networks and The Core Idea Behind Them</title>
      <dc:creator>Mark Glemba</dc:creator>
      <pubDate>Mon, 07 Sep 2026 22:18:22 +0000</pubDate>
      <link>https://dev.to/mark_glemba_962f6bc8a12dd/understanding-neural-networks-and-the-core-idea-behind-them-4n3p</link>
      <guid>https://dev.to/mark_glemba_962f6bc8a12dd/understanding-neural-networks-and-the-core-idea-behind-them-4n3p</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Neural networks work by building a system inspired by the human brain that can learn how to solve the problem by looking at examples.If you are new to machine learning, neural networks might seem like an impenetrable black box full of dense mathematics. However, the core idea behind them is surprisingly simple, intuitive, and beautiful. &lt;/p&gt;

&lt;p&gt;In this guide, we will unpack neural networks from first principles, stripping away the hype to see how they truly work.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The Core Idea: Function Approximation and Pattern Recognition
&lt;/h2&gt;

&lt;p&gt;Mathematically, a neural network is just a giant, adjustable mathematical function.&lt;/p&gt;

&lt;p&gt;A neural network is a tool for Function Approximation. It begins as a blank slate—a mathematical machine full of adjustable "knobs" and "dials." Initially, these dials are set randomly, meaning the network gives terrible guesses. But by feeding it thousands of examples (inputs paired with correct outputs), we gradually tweak those knobs until the network’s output matches the desired result.In essence: A neural network learns to approximate the invisible mathematical rule that connects inputs to outputs.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. The Biological Inspiration: From Neurons to Code
&lt;/h2&gt;

&lt;p&gt;The name "Neural Network" comes from biological neuroscience. Our brains contain approximately 86 billion interconnected biological cells called neurons.Biological Neuron Flow:&lt;br&gt;
[ Dendrites ] ---&amp;gt; ( Cell Body ) ---&amp;gt; [ Axon ] ---&amp;gt; &lt;a href="https://dev.toInputs"&gt; Synapses &lt;/a&gt;            (Processing)            (Output)       (Connections)&lt;/p&gt;

&lt;p&gt;Dendrites receive electrical signals from other neurons.The Cell Body aggregates these incoming signals. If the combined electrical charge crosses a certain threshold, the neuron "fires". The Axon carries the fired signal down toward the end of the cell.Synapses transmit the signal across junctions to neighboring neurons.In artificial intelligence, we do not build actual biological structures. Instead, we create a mathematical simplified abstraction called an Artificial Neuron (or a Perceptron).&lt;/p&gt;
&lt;h2&gt;
  
  
  3. The Anatomy of an Artificial Neuron
&lt;/h2&gt;

&lt;p&gt;To understand how a complex deep network functions, we must first understand its smallest building block: a single artificial neuron.&lt;/p&gt;

&lt;p&gt;An artificial neuron performs four fundamental operations:&lt;/p&gt;

&lt;p&gt;Receives Inputs, Multiplies each input by a Weight, Adds a constant called Bias, Passes the result through an Activation Function, to produce the final Output. &lt;/p&gt;

&lt;p&gt;Let’s break down each of these components in plain language:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A. Inputs (&lt;code&gt;$x$&lt;/code&gt;)&lt;/strong&gt; Inputs represent the features of the data you want to analyze. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B. Weights (&lt;code&gt;$w$&lt;/code&gt;)&lt;/strong&gt; Weights are the "knobs and dials" of the network. They determine how much influence a given input has on the neuron’s final decision: A large positive weight means the input strongly drives the decision upward. A weight close to zero means the input is mostly ignored. A negative weight means as the input increases, the prediction goes down.&lt;/p&gt;

&lt;p&gt;Mathematically, we multiply each input by its weight&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C. Bias (&lt;code&gt;$b$&lt;/code&gt;)&lt;/strong&gt; The Bias is an extra adjustable parameter added to the weighted sum. It acts as a base threshold, shifting the calculation up or down regardless of the inputs. &lt;/p&gt;

&lt;p&gt;It gives the neuron the freedom to trigger even when inputs are low, or remain quiet even when inputs are high.Adding the bias gives us the linear equation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$z = \left( \sum_{i=1}^{n} w_i x_i \right) + b$

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;D. Activation Function (&lt;code&gt;$f(z)$&lt;/code&gt;)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If a neural network consisted only of weights and biases, it would just be doing linear algebra—drawing straight lines through data. But real-world data is non-linear, full of curves, twists, and subtle thresholds.&lt;/p&gt;

&lt;p&gt;The Activation Function introduces non-linearity into the network. It decides whether the neuron should  activate and by how much.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Here are three common activation functions:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The Step FunctionHistorically&lt;/strong&gt;, early neurons used a binary switch: if &lt;code&gt;$z &amp;gt; 0$&lt;/code&gt;, output &lt;code&gt;$1$&lt;/code&gt;; otherwise output &lt;code&gt;$0$&lt;/code&gt;. This mirrors a simple on/off switch, but it lacks nuance because small changes in inputs can cause sudden, wild jumps in output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The Sigmoid Function&lt;/strong&gt; The Sigmoid function squashes any real number input into a smooth range between 0 and 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$\sigma(z) = \frac{1}{1 + e^{-z}}$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;. It is often used when predicting probabilities &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. ReLU (Rectified Linear Unit)&lt;/strong&gt; Despite its fancy name, ReLU is remarkably simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$f(z) = \max(0, z)$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;$z$&lt;/code&gt; is negative, output 0. If &lt;code&gt;$z$&lt;/code&gt; is positive, return &lt;code&gt;$z$&lt;/code&gt; as it is. &lt;/p&gt;

&lt;p&gt;Because it is computationally efficient and works incredibly well, ReLU is the most popular activation function used inside modern neural networks today.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Tanh(Hyperbolic Tangent)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$\tanh(x) = \frac{e^z - e^{-z}}{e^z + e^{-z}}$  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Output range for the hyperbolic tangent is between (-1, 1)&lt;/li&gt;
&lt;li&gt;Still suffers from vanishing gradients at the extremes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. Leaky ReLU&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$f(x) = \max(\alpha x, x)$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Output range for leaky relu is -∞ to ∞ &lt;/li&gt;
&lt;li&gt;A small modificationof ReLU that allows a small, non-zero gradient when the input is negative
&lt;/li&gt;
&lt;li&gt;Helps mitigate the dying ReLU problem&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;6. SoftMax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$\sigma (\mathbf{z})_{i}=\frac{e^{z_{i}}}{\sum _{j=1}^{K}e^{z_{j}}}$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output range is between 0 and 1 and they sum up to 1.      &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Converts a vector of raw scores(logits) into a probability distribution across multiple classes.
&lt;/li&gt;
&lt;li&gt;Used almost exclusively in the output layer for multiclass classification problems.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Organizing Neurons into Layers
&lt;/h2&gt;

&lt;p&gt;A single neuron can make basic linear decisions (like drawing a straight line to divide two groups of points). However, real intelligence requires combining hundreds, thousands, or millions of these neurons into a network.A typical neural network is structured in vertical slices called Layers:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The Input Layer:&lt;/strong&gt; This is where raw data enters the network. It doesn't perform calculations; it simply passes feature values forward. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The Hidden Layer:&lt;/strong&gt; Located between input and output, these layers are called "hidden" simply because their intermediate processing values are not directly observed in the dataset. &lt;br&gt;
Early hidden layers learn simple, fundamental patterns (e.g., detecting horizontal, vertical, or diagonal edges in an image).&lt;br&gt;
Middle hidden layers combine those basic edges to detect shapes (e.g., circles, corners, texture patterns).&lt;br&gt;
Deeper hidden layers combine shapes into high-level concepts (e.g., eyes, noses, wheels, or ears).&lt;br&gt;
When a network has multiple hidden layers stacked on top of each other, we call it a Deep Neural Network — hence the term Deep Learning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. The Output Layer:&lt;/strong&gt; The final layer produces the network's answer.For a regression task (predicting a house price), it might contain 1 single neuron outputting a raw number like $350,000.&lt;br&gt;
For a classification task (identifying an animal as a Cat, Dog, or Bird), it might contain 3 neurons, each outputting a probability score for its category.&lt;/p&gt;
&lt;h2&gt;
  
  
  5. How Neural Networks Learn:The Training Loop
&lt;/h2&gt;

&lt;p&gt;When you initialize a neural network, its weights (&lt;code&gt;$w$&lt;/code&gt;) and biases (&lt;code&gt;$b$&lt;/code&gt;) are filled with random numbers. Learning happens through a continuous loop consisting of four major steps:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5bz2m1iexzd863joelko.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5bz2m1iexzd863joelko.png" alt=" " width="511" height="145"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 1: Forward Propagation&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;During forward propagation, data flows in one direction—from input to output: Inputs are fed into the input layer. Neurons calculate weighted sums, add biases, apply activation functions, and pass their results forward to the next layer.&lt;br&gt;
This process continues layer by layer until the final output layer generates a prediction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 2: Measuring Error (The Loss Function)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once the network makes a prediction, we compare it against the real target answer (&lt;code&gt;$y$&lt;/code&gt;) using a Loss Function (also called a Cost Function). &lt;br&gt;
The Loss Function measures how wrong the network is.&lt;br&gt;
A simple example is &lt;em&gt;Mean Squared Error (MSE)&lt;/em&gt;, commonly used for predicting numerical values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$\text{Loss} = \frac{1}{2} (\hat{y} - y)^2$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The goal of training is simple: Adjust the network's weights and biases to make the Loss as close to zero as possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 3: Gradient Descent (Finding the Way Down)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Mathematically, the gradient is calculated using calculus (derivatives). It tells us two crucial pieces of information: &lt;em&gt;Direction:&lt;/em&gt; Which way does the error increase or decrease?&lt;br&gt;
&lt;em&gt;Steepness:&lt;/em&gt; How fast is the error changing relative to changes in weight? &lt;br&gt;
If we move our parameters in the opposite direction of the gradient, we walk downhill toward lower loss. The Learning Rate (&lt;code&gt;$\eta$&lt;/code&gt;) The size of the step we take in each iteration is controlled by a hyperparameter called the Learning Rate (&lt;code&gt;$\eta$&lt;/code&gt;): If the learning rate is too small: The network takes tiny steps and takes days or weeks to train.If the learning rate is too large: The network takes giant leaps and might overshoot the valley completely, bouncing wildly without ever learning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 4: Backpropagation (Assigning Blame)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Backpropagation uses the mathematical Chain Rule from calculus to work backward through the network: Calculate the final error at the output layer, Determine how much the output layer weights contributed to that error, Pass the error metric back to the previous hidden layer, Determine how much that hidden layer's weights contributed and Repeat all the way back to the input layer. &lt;br&gt;
By working backward, every single weight in the network receives a precise update instruction based on how much it contributed to the overall error.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Key Challenges in Neural Networks
&lt;/h2&gt;

&lt;p&gt;While neural networks are extremely powerful, they are not without flaws. Working with them involves handling several distinct challenges:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Overfitting:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Overfitting happens when a network learns its training data too well.  Instead of discovering general rules, it essentially memorizes the training examples, including their noise and random quirks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Analogy:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;A student who memorizes every practice question and answer key word-for-word, but fails completely on the actual test when questions are rephrased.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Solution:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Techniques like Regularization, Dropout (randomly disabling neurons during training), and collecting more diverse training data help prevent overfitting.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The Black Box Problem&lt;/em&gt;&lt;br&gt;
 When a traditional software system makes a decision, a developer can read the lines of code to understand why. But when a deep neural network with 175 billion weights makes a decision, it is nearly impossible for a human to look at those floating-point numbers and understand its exact reasoning. This lack of interpretability is a challenge in fields like healthcare, finance, and legal decision-making.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Data and Compute Requirements&lt;/em&gt;&lt;br&gt;
Unlike simple statistical models, neural networks thrive on massive amounts of data. They also require significant computational power, often requiring specialized hardware like &lt;em&gt;GPUs (Graphics Processing Units)&lt;/em&gt; or &lt;em&gt;TPUs (Tensor Processing Units)&lt;/em&gt; to perform billions of matrix multiplications efficiently.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Summary Checklist
&lt;/h2&gt;

&lt;p&gt;To consolidate what we've learned, here is a quick summary of the core pipeline:&lt;br&gt;
| Concept | What It Is | Role in the Network |&lt;br&gt;
| Neuron | Basic computational unit | Multiplies inputs by weights, adds bias, applies activation |&lt;br&gt;
| Weight (&lt;code&gt;$w$&lt;/code&gt;) | Adjustable strength factor | Controls how much importance an input has |&lt;br&gt;
| Bias (&lt;code&gt;$b$&lt;/code&gt;) | Base offset term | Allows the neuron to shift outputs up or down |&lt;br&gt;
| Activation Function | Non-linear transform (&lt;code&gt;$f$&lt;/code&gt;) | Enables network to learn complex, non-linear relationships |&lt;br&gt;
| Forward Propagation | Data pass from input &lt;code&gt;$\to$&lt;/code&gt; output | Computes the network's current prediction |&lt;br&gt;
| Loss Function | Error measurement | Quantifies how far off predictions are from truth |&lt;br&gt;
| Backpropagation | Error distribution algorithm | Uses calculus to determine how to tweak each parameter |&lt;br&gt;
| Gradient Descent | Optimization technique | Iteratively updates weights to reduce overall error |&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;A neural network is a system of connected mathematical units that learns patterns by adjusting numerical weights after making predictions and receiving feedback.&lt;/p&gt;

&lt;p&gt;It receives information, processes that information through layers, makes a prediction, measures its error, and adjusts itself. Repeated enough times with good data, this process can produce systems capable of solving complex problems.&lt;/p&gt;

&lt;p&gt;Neural networks are not copies of the human brain. They are tools built from mathematics, data, and computation. Their power comes from their ability to learn complicated patterns that would be difficult to describe using hand-written rules.&lt;/p&gt;

</description>
      <category>datascience</category>
    </item>
    <item>
      <title>Python Distributions and Their Impact on Data Science</title>
      <dc:creator>Mark Glemba</dc:creator>
      <pubDate>Mon, 07 Sep 2026 19:42:26 +0000</pubDate>
      <link>https://dev.to/mark_glemba_962f6bc8a12dd/python-distributions-and-their-impact-on-data-science-2g5h</link>
      <guid>https://dev.to/mark_glemba_962f6bc8a12dd/python-distributions-and-their-impact-on-data-science-2g5h</guid>
      <description>&lt;h1&gt;
  
  
  Understanding Statistical Distributions and Their Impact on Data Science
&lt;/h1&gt;

&lt;p&gt;In the world of data science, data is the foundation of every decision, model, and prediction. However, raw data on its own often appears chaotic and difficult to interpret. This is where statistical distributions become important. Statistical distributions help data scientists understand how data is spread, identify patterns, and make informed decisions based on probabilities. Without understanding distributions, analyzing data effectively would be nearly impossible.&lt;/p&gt;

&lt;p&gt;Statistical distributions are one of the most fundamental concepts in statistics and data science. They describe how values in a dataset are arranged and how frequently they occur. From predicting customer behavior to detecting fraud, statistical distributions influence nearly every data-driven process.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Statistical Distribution?
&lt;/h2&gt;

&lt;p&gt;A statistical distribution is a mathematical representation of how data points are spread across possible values. It shows the frequency or probability of different outcomes.&lt;/p&gt;

&lt;p&gt;For example, consider the heights of students in a class. If you plot these heights on a graph, you may notice that most students have average heights, while only a few are extremely short or tall. This pattern forms a distribution.&lt;/p&gt;

&lt;p&gt;A distribution answers important questions such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Where is the center of the data?&lt;/li&gt;
&lt;li&gt;How spread out is the data?&lt;/li&gt;
&lt;li&gt;Are there unusual values (outliers)?&lt;/li&gt;
&lt;li&gt;Is the data symmetric or skewed?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These insights are essential for data analysis and machine learning.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Components of a Distribution
&lt;/h2&gt;

&lt;p&gt;To understand distributions, it is important to know the following concepts:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Mean
&lt;/h3&gt;

&lt;p&gt;The mean is the average value of the data. It represents the central point of a distribution.&lt;/p&gt;

&lt;p&gt;Formula:&lt;/p&gt;

&lt;p&gt;[&lt;br&gt;
Mean = \frac{\sum x}{n}&lt;br&gt;
]&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
If the values are 2, 4, 6, 8:&lt;/p&gt;

&lt;p&gt;Mean = (2 + 4 + 6 + 8) / 4 = 5&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Median
&lt;/h3&gt;

&lt;p&gt;The median is the middle value when data is arranged in order. It is less affected by outliers.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
For 2, 4, 6, 100:&lt;/p&gt;

&lt;p&gt;Median = 5&lt;br&gt;
Mean = 28&lt;/p&gt;

&lt;p&gt;This shows how outliers affect the mean.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Variance
&lt;/h3&gt;

&lt;p&gt;Variance measures how far data points are from the mean.&lt;/p&gt;

&lt;p&gt;Low variance means data points are close together.&lt;br&gt;
High variance means data points are spread out.&lt;/p&gt;
&lt;h3&gt;
  
  
  4. Standard Deviation
&lt;/h3&gt;

&lt;p&gt;This is the square root of variance and gives a measure of spread in the same units as the data.&lt;/p&gt;
&lt;h3&gt;
  
  
  5. Skewness
&lt;/h3&gt;

&lt;p&gt;Skewness tells us whether the distribution leans left or right.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Positive skew: Tail on the right&lt;/li&gt;
&lt;li&gt;Negative skew: Tail on the left&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  6. Kurtosis
&lt;/h3&gt;

&lt;p&gt;Kurtosis measures how heavy the tails of a distribution are compared to a normal distribution.&lt;/p&gt;
&lt;h2&gt;
  
  
  Types of Statistical Distributions
&lt;/h2&gt;

&lt;p&gt;There are many statistical distributions, but some are more common in data science.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Normal Distribution
&lt;/h2&gt;

&lt;p&gt;The Normal Distribution is the most important distribution in statistics. It is also called the Gaussian distribution.&lt;/p&gt;

&lt;p&gt;It has these properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bell-shaped curve&lt;/li&gt;
&lt;li&gt;Symmetrical around the mean&lt;/li&gt;
&lt;li&gt;Mean = Median = Mode&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Human heights&lt;/li&gt;
&lt;li&gt;Exam scores&lt;/li&gt;
&lt;li&gt;Measurement errors&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why it matters in data science:&lt;br&gt;
Many machine learning algorithms assume data is normally distributed. Examples include linear regression and logistic regression.&lt;/p&gt;

&lt;p&gt;The probability density function is:&lt;/p&gt;

&lt;p&gt;[&lt;br&gt;
f(x) = \frac{1}{σ\sqrt{2π}} e^{-\frac{(x-μ)^2}{2σ^2}}&lt;br&gt;
]&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Uniform Distribution
&lt;/h2&gt;

&lt;p&gt;The Uniform Distribution occurs when all values have an equal probability of occurring.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
Rolling a fair dice.&lt;/p&gt;

&lt;p&gt;Each number (1–6) has an equal chance.&lt;/p&gt;

&lt;p&gt;Impact in data science:&lt;br&gt;
Used in random sampling and simulations.&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Binomial Distribution
&lt;/h2&gt;

&lt;p&gt;The Binomial Distribution represents the probability of success in a fixed number of independent trials.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
Flipping a coin 10 times.&lt;/p&gt;

&lt;p&gt;Possible outcomes:&lt;br&gt;
How many heads occur?&lt;/p&gt;

&lt;p&gt;Applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A/B testing&lt;/li&gt;
&lt;li&gt;Customer conversion rates&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  4. Poisson Distribution
&lt;/h2&gt;

&lt;p&gt;The Poisson Distribution models the number of events occurring in a fixed interval.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Number of website visits per minute&lt;/li&gt;
&lt;li&gt;Number of accidents in a day&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Applications:&lt;br&gt;
Useful in event prediction.&lt;/p&gt;
&lt;h2&gt;
  
  
  5. Exponential Distribution
&lt;/h2&gt;

&lt;p&gt;The Exponential Distribution models the time between events.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
Time between customer arrivals.&lt;/p&gt;

&lt;p&gt;Applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Queue systems&lt;/li&gt;
&lt;li&gt;Reliability analysis&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  6. Power Law Distribution
&lt;/h2&gt;

&lt;p&gt;The Power Law describes data where a small number of occurrences are very common while most are rare.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Social media followers&lt;/li&gt;
&lt;li&gt;Wealth distribution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Impact:&lt;br&gt;
Helps in network analysis and anomaly detection.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why Statistical Distributions Matter in Data Science
&lt;/h2&gt;

&lt;p&gt;Understanding distributions has a major impact on data science workflows.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Data Cleaning
&lt;/h2&gt;

&lt;p&gt;Distributions help detect anomalies and outliers.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
If salaries in a dataset are mostly between $500 and $2000 but one entry is $500,000, this may be an error.&lt;/p&gt;

&lt;p&gt;Outlier detection improves model quality.&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Feature Engineering
&lt;/h2&gt;

&lt;p&gt;Data transformations are often applied based on distributions.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log transformation for skewed data&lt;/li&gt;
&lt;li&gt;Normalization for scaling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This makes data easier for models to learn.&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Choosing the Right Model
&lt;/h2&gt;

&lt;p&gt;Different models assume different distributions.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Linear regression assumes normality&lt;/li&gt;
&lt;li&gt;Naive Bayes often assumes Gaussian distribution&lt;/li&gt;
&lt;li&gt;Poisson regression assumes Poisson distribution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using the wrong assumptions can reduce accuracy.&lt;/p&gt;
&lt;h2&gt;
  
  
  4. Hypothesis Testing
&lt;/h2&gt;

&lt;p&gt;Many statistical tests depend on distributions.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;t-test uses normal distribution&lt;/li&gt;
&lt;li&gt;Chi-square test uses chi-square distribution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These tests help validate findings.&lt;/p&gt;
&lt;h2&gt;
  
  
  5. Probability Predictions
&lt;/h2&gt;

&lt;p&gt;Distributions allow us to calculate probabilities.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
What is the probability that sales exceed 100 units?&lt;/p&gt;

&lt;p&gt;This supports risk assessment and forecasting.&lt;/p&gt;
&lt;h2&gt;
  
  
  Real-Life Applications in Data Science
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Finance
&lt;/h3&gt;

&lt;p&gt;Stock returns are often analyzed using distributions to measure volatility and risk.&lt;/p&gt;

&lt;p&gt;Relevant entity: Quantitative Finance&lt;/p&gt;
&lt;h3&gt;
  
  
  Healthcare
&lt;/h3&gt;

&lt;p&gt;Patient recovery times may follow an exponential distribution.&lt;/p&gt;

&lt;p&gt;Relevant entity: Biostatistics&lt;/p&gt;
&lt;h3&gt;
  
  
  E-commerce
&lt;/h3&gt;

&lt;p&gt;Customer purchase behavior often follows a power law distribution.&lt;/p&gt;

&lt;p&gt;Companies like Amazon use distribution analysis for recommendations.&lt;/p&gt;
&lt;h3&gt;
  
  
  Fraud Detection
&lt;/h3&gt;

&lt;p&gt;Unusual patterns that deviate from expected distributions may indicate fraud.&lt;/p&gt;

&lt;p&gt;Banks use this to detect suspicious transactions.&lt;/p&gt;
&lt;h3&gt;
  
  
  Machine Learning
&lt;/h3&gt;

&lt;p&gt;Algorithms like Gradient Descent perform better when data is standardized and distributed properly.&lt;/p&gt;
&lt;h2&gt;
  
  
  Visualizing Distributions
&lt;/h2&gt;

&lt;p&gt;Data scientists use visualization tools to understand distributions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Histograms&lt;/li&gt;
&lt;li&gt;Box plots&lt;/li&gt;
&lt;li&gt;Density plots&lt;/li&gt;
&lt;li&gt;Scatter plots&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Python, libraries such as Matplotlib and Pandas help visualize distributions.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hist&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a histogram to show how values are distributed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges in Understanding Distributions
&lt;/h2&gt;

&lt;p&gt;Although distributions are useful, they can be challenging because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real-world data is often messy&lt;/li&gt;
&lt;li&gt;Some datasets do not follow standard distributions&lt;/li&gt;
&lt;li&gt;Mixed distributions can complicate analysis&lt;/li&gt;
&lt;li&gt;Small datasets may not show clear patterns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Data scientists must often transform data before analysis.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Statistical distributions are the backbone of data science. They provide a framework for understanding how data behaves, identifying trends, and making predictions. Whether it is the normal distribution for machine learning, the binomial distribution for testing, or the Poisson distribution for event modeling, distributions guide decision-making in almost every area of data science.&lt;/p&gt;

&lt;p&gt;A strong understanding of statistical distributions allows data scientists to clean data more effectively, choose better models, improve accuracy, and generate meaningful insights. As data continues to grow in importance across industries, mastering statistical distributions remains an essential skill for every aspiring data scientist.&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>learning</category>
      <category>python</category>
    </item>
    <item>
      <title>Statistics, Parametric and Non-Parametric Tests in Python</title>
      <dc:creator>Mark Glemba</dc:creator>
      <pubDate>Tue, 07 Jul 2026 20:01:44 +0000</pubDate>
      <link>https://dev.to/mark_glemba_962f6bc8a12dd/statistics-parametric-and-non-parametric-tests-in-python-40c6</link>
      <guid>https://dev.to/mark_glemba_962f6bc8a12dd/statistics-parametric-and-non-parametric-tests-in-python-40c6</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
Statistics is one of the fundamental pillars of data science, machine learning, artificial intelligence, business intelligence, scientific research, healthcare analytics, finance, engineering, and many other disciplines. Every day, organizations collect enormous amounts of data from customers, sensors, websites, social media platforms, financial transactions, and business operations. However, raw data alone provides little value unless it can be analyzed and interpreted correctly. Statistics provides the mathematical framework that enables analysts and researchers to extract meaningful insights from data, identify patterns, test hypotheses, and make evidence-based decisions.&lt;br&gt;
Python has become one of the world’s most popular programming languages for statistical analysis due to its simplicity, extensive libraries, and powerful data manipulation capabilities. Libraries such as NumPy, Pandas, SciPy, Statsmodels, and Scikit-learn provide researchers and analysts with comprehensive tools for performing descriptive statistics, inferential statistics, hypothesis testing, regression analysis, and machine learning.&lt;br&gt;
Among the most important concepts in statistical analysis are parametric and non-parametric statistical tests. Choosing the correct statistical test is essential because using an inappropriate test may produce misleading conclusions. Parametric tests assume that the underlying data follow specific statistical distributions, usually the normal distribution, while non-parametric tests make fewer assumptions and are particularly useful when those assumptions are violated.&lt;br&gt;
This article explores statistics, parametric tests, non-parametric tests, their assumptions, advantages, disadvantages, practical applications, and demonstrates how these tests can be implemented using Python.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Understanding Statistics&lt;/strong&gt;&lt;br&gt;
Statistics is the science of collecting, organizing, analyzing, interpreting, and presenting data. It helps transform raw numbers into meaningful information that supports decision-making.&lt;br&gt;
Statistics is generally divided into two major branches:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Descriptive Statistics&lt;/strong&gt;&lt;br&gt;
Descriptive statistics summarize and describe the characteristics of a dataset without making conclusions beyond the data collected.&lt;br&gt;
Common descriptive statistics include:&lt;br&gt;
• Mean&lt;br&gt;
• Median&lt;br&gt;
• Mode&lt;br&gt;
• Range&lt;br&gt;
• Variance&lt;br&gt;
• Standard deviation&lt;br&gt;
• Quartiles&lt;br&gt;
• Percentiles&lt;br&gt;
• Skewness&lt;br&gt;
• Kurtosis&lt;br&gt;
For example, a company may calculate the average monthly salary of employees or the average customer spending per transaction.&lt;br&gt;
Python Example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6ualb6h4wxvdf65b3fqm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6ualb6h4wxvdf65b3fqm.png" alt=" " width="800" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Inferential Statistics&lt;/strong&gt;&lt;br&gt;
Inferential statistics goes beyond describing data by drawing conclusions about an entire population using a sample.&lt;br&gt;
Inferential statistics helps answer questions such as:&lt;br&gt;
• Is a new medicine more effective than the old one?&lt;br&gt;
• Does education level influence salary?&lt;br&gt;
• Is customer satisfaction different between two stores?&lt;br&gt;
• Does gender affect purchasing behavior?&lt;br&gt;
Inferential statistics relies heavily on probability theory and hypothesis testing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hypothesis Testing&lt;/strong&gt;&lt;br&gt;
Hypothesis testing is a statistical method used to determine whether there is sufficient evidence to support a claim.&lt;br&gt;
Every hypothesis test begins with two hypotheses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Null Hypothesis (H₀)&lt;/strong&gt;&lt;br&gt;
The null hypothesis states that there is no significant difference or relationship.&lt;br&gt;
Example:&lt;br&gt;
“There is no difference in average salaries between male and female employees.”&lt;br&gt;
&lt;strong&gt;Alternative Hypothesis (H₁)&lt;/strong&gt;&lt;br&gt;
The alternative hypothesis states that there is a significant difference or relationship.&lt;br&gt;
Example:&lt;br&gt;
“There is a significant difference in average salaries between male and female employees.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding the p-value&lt;/strong&gt;&lt;br&gt;
The p-value measures how likely the observed data would occur if the null hypothesis were true.&lt;br&gt;
General interpretation:&lt;br&gt;
• p ≤ 0.05 → Reject H₀&lt;br&gt;
• p &amp;gt; 0.05 → Fail to reject H₀&lt;br&gt;
For example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Four4n360ofszw9l33gif.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Four4n360ofszw9l33gif.png" alt=" " width="799" height="179"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parametric Statistical Tests&lt;/strong&gt;&lt;br&gt;
Parametric tests are statistical methods that make assumptions about the population distribution.&lt;br&gt;
The most common assumption is that the data follow a normal distribution.&lt;br&gt;
Because they use more information from the data, parametric tests are generally more powerful than non-parametric tests when their assumptions are satisfied.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Assumptions of Parametric Tests&lt;/strong&gt;&lt;br&gt;
Before applying a parametric test, several assumptions should be checked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Normality&lt;/strong&gt;&lt;br&gt;
Data should approximately follow a normal distribution.&lt;br&gt;
Python example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0wpj0rca6jeofk7tk2qt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0wpj0rca6jeofk7tk2qt.png" alt=" " width="800" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If&lt;br&gt;
p &amp;gt; 0.05&lt;br&gt;
the data are considered approximately normal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Homogeneity of Variance&lt;/strong&gt;&lt;br&gt;
Groups should have similar variances.&lt;br&gt;
Python example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F21yc4g8ywhhtcnea53kg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F21yc4g8ywhhtcnea53kg.png" alt=" " width="800" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Independence&lt;/strong&gt;&lt;br&gt;
Observations should be independent of one another.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Continuous Data&lt;/strong&gt;&lt;br&gt;
Most parametric tests require interval or ratio-level data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common Parametric Tests&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;1. Independent Samples t-Test&lt;/strong&gt;&lt;br&gt;
Purpose:&lt;br&gt;
Compare the means of two independent groups.&lt;br&gt;
Example:&lt;br&gt;
Compare salaries of male and female employees&lt;br&gt;
Python:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpyj0m5hauvsg48wu1pqd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpyj0m5hauvsg48wu1pqd.png" alt=" " width="800" height="181"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Paired t-Test&lt;/strong&gt;&lt;br&gt;
Purpose:&lt;br&gt;
Compare measurements taken from the same individuals before and after an intervention.&lt;br&gt;
Example:&lt;br&gt;
Employee productivity before and after training.&lt;br&gt;
Python:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5yf9si6l98i56vxlis7j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5yf9si6l98i56vxlis7j.png" alt=" " width="800" height="170"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. One-Sample t-Test&lt;/strong&gt;&lt;br&gt;
Purpose:&lt;br&gt;
Determine whether a sample mean differs from a known population mean.&lt;br&gt;
Python:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxx9w3hahmjm5ktwaakox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxx9w3hahmjm5ktwaakox.png" alt=" " width="799" height="175"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. ANOVA (Analysis of Variance)&lt;/strong&gt;&lt;br&gt;
Purpose:&lt;br&gt;
Compare means of three or more groups.&lt;br&gt;
Example:&lt;br&gt;
Compare salaries across departments.&lt;br&gt;
Python:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmg59rlrsf0zgst9wuj1k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmg59rlrsf0zgst9wuj1k.png" alt=" " width="799" height="183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Pearson Correlation&lt;/strong&gt;&lt;br&gt;
Purpose:&lt;br&gt;
Measure the linear relationship between two continuous variables.&lt;br&gt;
Python:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F37safjfbs43mkud5avy8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F37safjfbs43mkud5avy8.png" alt=" " width="800" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Correlation values range from -1 to +1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Linear Regression&lt;/strong&gt;&lt;br&gt;
Purpose:&lt;br&gt;
Model the relationship between independent and dependent variables.&lt;br&gt;
Python:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F05zprd1hx18j7dzdknue.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F05zprd1hx18j7dzdknue.png" alt=" " width="800" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Regression is widely used for prediction and identifying significant predictors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of Parametric Tests&lt;/strong&gt;&lt;br&gt;
Some benefits include:&lt;br&gt;
• Higher statistical power&lt;br&gt;
• More precise estimates&lt;br&gt;
• Efficient with normally distributed data&lt;br&gt;
• Suitable for predictive modeling&lt;br&gt;
• Widely accepted in scientific research&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages of Parametric Tests&lt;/strong&gt;&lt;br&gt;
Limitations include:&lt;br&gt;
• Sensitive to outliers&lt;br&gt;
• Require normality assumptions&lt;br&gt;
• Require continuous data&lt;br&gt;
• Can produce misleading results when assumptions are violated  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Non-Parametric Statistical Tests&lt;/strong&gt;&lt;br&gt;
Non-parametric tests are statistical procedures that do not assume a specific population distribution.&lt;br&gt;
They are often called distribution-free tests.&lt;br&gt;
These tests are especially useful when:&lt;br&gt;
• Data are skewed&lt;br&gt;
• Sample size is small&lt;br&gt;
• Data contain outliers&lt;br&gt;
• Data are ordinal&lt;br&gt;
• Normality assumptions fail&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of Non-Parametric Tests&lt;/strong&gt;&lt;br&gt;
Advantages include:&lt;br&gt;
• Few assumptions&lt;br&gt;
• Handle skewed data&lt;br&gt;
• Robust against outliers&lt;br&gt;
• Suitable for ordinal data&lt;br&gt;
• Useful with small sample sizes&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages of Non-Parametric Tests&lt;/strong&gt;&lt;br&gt;
Disadvantages include:&lt;br&gt;
• Lower statistical power than parametric tests&lt;br&gt;
• May ignore some information contained in the data&lt;br&gt;
• Less effective for normally distributed datasets&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common Non-Parametric Tests&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;1. Mann-Whitney U Test&lt;/strong&gt;&lt;br&gt;
Equivalent to the independent t-test.&lt;br&gt;
Used for comparing two independent groups.&lt;br&gt;
Python:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzrf1ooyeq4p7k71yg1l3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzrf1ooyeq4p7k71yg1l3.png" alt=" " width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Wilcoxon Signed-Rank Test&lt;/strong&gt;&lt;br&gt;
Equivalent to the paired t-test.&lt;br&gt;
Python:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmlfur83r8rrfzce89af6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmlfur83r8rrfzce89af6.png" alt=" " width="800" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Kruskal-Wallis Test&lt;/strong&gt;&lt;br&gt;
Equivalent to one-way ANOVA.&lt;br&gt;
Python:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj44hcvt1eeio3j1q4f43.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj44hcvt1eeio3j1q4f43.png" alt=" " width="799" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Friedman Test&lt;/strong&gt;&lt;br&gt;
Equivalent to repeated-measures ANOVA.&lt;br&gt;
Python:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9xult7q2450fxmu37ms0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9xult7q2450fxmu37ms0.png" alt=" " width="799" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Spearman Rank Correlation&lt;/strong&gt;&lt;br&gt;
Equivalent to Pearson correlation when data are not normally distributed.&lt;br&gt;
Python:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fic6mep6eanx2pnlbz6w5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fic6mep6eanx2pnlbz6w5.png" alt=" " width="799" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Chi-Square Test of Independence&lt;/strong&gt;&lt;br&gt;
Used for categorical variables.&lt;br&gt;
Example:&lt;br&gt;
Determine whether education level is associated with employment status.&lt;br&gt;
Python:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F040xv2fkuhefvv0tp7rd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F040xv2fkuhefvv0tp7rd.png" alt=" " width="799" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Choosing Between Parametric and Non-Parametric Tests&lt;/strong&gt;&lt;br&gt;
Selecting the appropriate statistical test depends on several factors, including the type of data, the number of groups, whether observations are independent or paired, and whether the assumptions of parametric tests are satisfied.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdvbt2nln14ynmrfg6qtk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdvbt2nln14ynmrfg6qtk.png" alt=" " width="730" height="304"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before choosing a test, analysts should perform exploratory data analysis (EDA), inspect visualizations such as histograms and box plots, and conduct assumption checks including tests for normality and homogeneity of variance. If assumptions hold, parametric tests are generally preferred because they provide greater statistical power. When assumptions are violated or the data are ordinal or heavily skewed, non-parametric tests offer a more reliable alternative.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python Libraries for Statistical Analysis&lt;/strong&gt;&lt;br&gt;
Python offers a rich ecosystem of libraries that simplify statistical analysis and hypothesis testing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;NumPy&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Used for numerical computations and array operations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9j64w6enf91wmv8aivs0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9j64w6enf91wmv8aivs0.png" alt=" " width="800" height="233"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Pandas&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Provides powerful data structures for data manipulation and descriptive statistics.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy7uo1jgbc635sdodv4dn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy7uo1jgbc635sdodv4dn.png" alt=" " width="798" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;SciPy&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Contains numerous statistical functions and hypothesis tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhi98q8k7xtuxd3e12xhk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhi98q8k7xtuxd3e12xhk.png" alt=" " width="800" height="205"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Statsmodels&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Used for regression analysis, ANOVA, generalized linear models, and other advanced statistical techniques.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgluye1dxqlhzz23cbewl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgluye1dxqlhzz23cbewl.png" alt=" " width="800" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Matplotlib&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Creates visualizations that aid in understanding data distributions and statistical results.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Feu1hih5n5l2gatjmcohy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Feu1hih5n5l2gatjmcohy.png" alt=" " width="799" height="203"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These libraries work seamlessly together, making Python one of the most comprehensive environments for statistical computing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practical Applications of Statistical Tests&lt;/strong&gt;&lt;br&gt;
Parametric and non-parametric tests are widely used across industries to solve real-world problems.&lt;br&gt;
In healthcare, researchers use t-tests and ANOVA to compare treatment effectiveness between patient groups, while non-parametric tests are applied when medical data are skewed or involve ordinal pain scores.&lt;br&gt;
In finance, analysts use correlation and regression to examine relationships between stock prices, interest rates, and economic indicators. Statistical tests help determine whether observed trends are significant or due to random variation.&lt;br&gt;
Businesses rely on hypothesis testing to evaluate marketing campaigns, compare customer satisfaction across branches, and assess employee performance after training programs. A/B testing, a common practice in digital marketing, is fundamentally based on statistical hypothesis testing.&lt;br&gt;
Educational institutions analyze examination results to compare teaching methods or determine whether interventions improve student performance. Government agencies apply statistical methods to census data, unemployment rates, and public health studies to guide policy decisions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices for Statistical Testing in Python&lt;/strong&gt;&lt;br&gt;
To ensure valid and reliable results, analysts should follow several best practices:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Understand the research question before selecting a statistical test.&lt;/li&gt;
&lt;li&gt; Perform exploratory data analysis to identify missing values, outliers, and unusual patterns.&lt;/li&gt;
&lt;li&gt; Check assumptions such as normality, independence, and equal variances before applying parametric tests.&lt;/li&gt;
&lt;li&gt; Choose non-parametric alternatives when assumptions are violated or when working with ordinal data.&lt;/li&gt;
&lt;li&gt; Report both the test statistic and the p-value, and where appropriate include confidence intervals and effect sizes to provide a more complete interpretation of the findings.&lt;/li&gt;
&lt;li&gt; Interpret statistical significance alongside practical significance, recognizing that a statistically significant result may not always have meaningful real-world implications.&lt;/li&gt;
&lt;li&gt; Document the methodology and Python code to ensure that analyses are transparent, reproducible, and easy to verify.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Statistics plays an indispensable role in transforming raw data into meaningful knowledge. Through descriptive statistics, analysts summarize and understand datasets, while inferential statistics enables them to make predictions and draw conclusions about larger populations from sample data. Hypothesis testing forms the foundation of inferential analysis by providing an objective framework for evaluating claims and determining whether observed differences or relationships are statistically significant.&lt;br&gt;
Parametric tests, including t-tests, ANOVA, Pearson correlation, and linear regression, are powerful methods when their underlying assumptions—such as normality, homogeneity of variance, and independence—are satisfied. Their higher statistical power makes them the preferred choice for many research applications involving continuous, normally distributed data. In contrast, non-parametric tests such as the Mann-Whitney U test, Wilcoxon signed-rank test, Kruskal-Wallis test, Friedman test, Spearman correlation, and Chi-square test provide flexible and robust alternatives when data violate these assumptions or are measured on an ordinal scale.&lt;br&gt;
Python has revolutionized statistical analysis by offering an accessible and efficient ecosystem of libraries, including NumPy, Pandas, SciPy, Statsmodels, and Matplotlib. These tools enable users to clean data, perform sophisticated statistical tests, visualize results, and build predictive models with relatively little code. As organizations increasingly rely on data-driven decision-making, proficiency in statistical methods and Python programming has become an essential skill for data scientists, researchers, analysts, and professionals across numerous fields. Understanding when to apply parametric or non-parametric methods ensures that analyses are both statistically valid and practically meaningful, ultimately leading to more accurate conclusions and better-informed decisions.&lt;/p&gt;

</description>
      <category>datascience</category>
    </item>
    <item>
      <title>Understanding DDL, DML, and Key SQL Concepts</title>
      <dc:creator>Mark Glemba</dc:creator>
      <pubDate>Tue, 14 Apr 2026 07:11:57 +0000</pubDate>
      <link>https://dev.to/mark_glemba_962f6bc8a12dd/understanding-ddl-dml-and-key-sql-concepts-omg</link>
      <guid>https://dev.to/mark_glemba_962f6bc8a12dd/understanding-ddl-dml-and-key-sql-concepts-omg</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
Structured Query Language (SQL) is essential for managing and manipulating data in relational databases. In this article, we explore two important categories of SQL commands—Data Definition Language (DDL) and Data Manipulation Language (DML)—along with practical operations such as CREATE, INSERT, UPDATE, DELETE, filtering with WHERE, and the use of CASE WHEN for data transformation.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What DDL and DML Are (and Their Differences)&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Data Definition Language (DDL) refers to SQL commands used to define and manage the structure of a database. These commands deal with creating, modifying, and deleting database objects such as tables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common DDL commands include&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CREATE&lt;/strong&gt; – used to create new tables or databases&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ALTER&lt;/strong&gt; – used to modify existing structures&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DROP&lt;/strong&gt;– used to delete tables or databases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, using "CREATE TABLE" allows you to define columns, data types, and constraints for storing data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Manipulation Language (DML)&lt;/strong&gt;, on the other hand, is used to manage the data within those structures. It focuses on inserting, updating, retrieving, and deleting records.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common DML commands include:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;INSERT&lt;/strong&gt; – adds new records&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UPDATE&lt;/strong&gt;– modifies existing data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DELETE&lt;/strong&gt; – removes records&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SELECT&lt;/strong&gt;– retrieves data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Key Difference:&lt;br&gt;
DDL deals with the structure of the database, while DML deals with the data inside the database.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Using CREATE, INSERT, UPDATE, and DELETE&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In a typical database assignment, these commands are used as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CREATE&lt;/strong&gt;: I used this command to define tables such as students, subjects, or exam results. It involved specifying column names, data types (e.g., INTEGER, VARCHAR), and primary keys.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;INSERT&lt;/strong&gt;: This command was used to add records into the tables. For example, inserting student names, subject details, and exam scores into the respective tables.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;: I used UPDATE to modify existing records. For instance, correcting a student’s score or updating a subject name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DELETE&lt;/strong&gt;: This command helped remove unwanted or incorrect records from the database, such as deleting a student entry or clearing outdated data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These commands are fundamental for maintaining accurate and up-to-date data in any database system.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Filtering Data with WHERE&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The WHERE clause is used in SQL to filter records based on specific conditions. It helps retrieve only the data that meets certain criteria.&lt;/p&gt;

&lt;p&gt;Some commonly used operators include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;= (Equal to)&lt;/strong&gt;: Selects records that match a specific value&lt;br&gt;
Example: "WHERE score = 80"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&amp;gt; (Greater than)&lt;/strong&gt;: Selects values greater than a given number&lt;br&gt;
Example: "WHERE score &amp;gt; 70"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;BETWEEN&lt;/strong&gt;: Filters values within a range&lt;br&gt;
Example: "WHERE score BETWEEN 50 AND 90"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;IN&lt;/strong&gt;: Matches values within a list&lt;br&gt;
Example: "WHERE subject IN ('Math', 'Science')"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;LIKE&lt;/strong&gt;: Used for pattern matching&lt;br&gt;
Example: "WHERE name LIKE 'J%'" (names starting with J)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The WHERE clause is powerful because it allows precise data retrieval, making queries more meaningful and efficient.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;How CASE WHEN Helps in Transforming Data&lt;/strong&gt;
The CASE WHEN statement in SQL is used to perform conditional logic within queries. It allows you to transform data by assigning values based on conditions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For example, you can categorize student performance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If score ≥ 70 → “Pass”&lt;/li&gt;
&lt;li&gt;If score &amp;lt; 70 → “Fail”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This helps in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating calculated columns&lt;/li&gt;
&lt;li&gt;Categorizing or grouping data&lt;/li&gt;
&lt;li&gt;Improving readability of query results&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;CASE WHEN is especially useful in reports, where raw data needs to be interpreted into meaningful insights.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Understanding DDL and DML is crucial for working with databases effectively. While DDL defines the structure of the database, DML allows you to interact with the data itself. Commands like CREATE, INSERT, UPDATE, and DELETE form the backbone of database operations. Additionally, tools like the WHERE clause and CASE WHEN statement enhance your ability to filter and transform data, making SQL a powerful language for data management and analysis.&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>ai</category>
    </item>
    <item>
      <title>HOW TO PUBLISH A POWER BI REPORT AND EMBED IT INTO A WEBSITE</title>
      <dc:creator>Mark Glemba</dc:creator>
      <pubDate>Mon, 06 Apr 2026 14:10:43 +0000</pubDate>
      <link>https://dev.to/mark_glemba_962f6bc8a12dd/how-to-publish-a-power-bi-report-and-embed-it-into-a-website-3gcc</link>
      <guid>https://dev.to/mark_glemba_962f6bc8a12dd/how-to-publish-a-power-bi-report-and-embed-it-into-a-website-3gcc</guid>
      <description>&lt;p&gt;&lt;strong&gt;INTRODUCTION&lt;/strong&gt;&lt;br&gt;
Power BI is an analytics tool developed by Microsoft that lets a user visualize and share insights on certain data. Power BI is also used transform and clean data using Power Query Editor. Data transformation occurs through; shaping data by filtering, sorting and grouping, adding columns and changing data types through conversion to; numeric, text etc. Data cleaning is done through; handling blanks, standardizing and removing errors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PUBLISHING PROCESS IN POWER BI&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create a workspace&lt;/strong&gt;
A workspace is like a folder where one stores reports, dashboards and datasets.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;. Go to [&lt;a href="https://app.powerbi.com/" rel="noopener noreferrer"&gt;https://app.powerbi.com/&lt;/a&gt;]&lt;br&gt;
. Sign into your account&lt;br&gt;
. Once your logged in, on the left far side click on workspaces&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh0wexji1b99t2wcz77sr.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh0wexji1b99t2wcz77sr.jpeg" alt=" " width="800" height="312"&gt;&lt;/a&gt;&lt;br&gt;
. Click on; + New workspace&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu0uonbpc9y9u7d4mprhb.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu0uonbpc9y9u7d4mprhb.jpeg" alt=" " width="800" height="248"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2 .&lt;strong&gt;Uploading and publishing&lt;/strong&gt;&lt;br&gt;
. In the power bi desktop in the home page click on publish on the far right.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0g0mm33clmyhmpeuqpor.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0g0mm33clmyhmpeuqpor.png" alt=" " width="800" height="107"&gt;&lt;/a&gt;&lt;br&gt;
. Select your workspace where the report will be uploaded&lt;br&gt;
. Once uploaded the dataset will appear on your workspace.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxeibqz93wystqevtpbkg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxeibqz93wystqevtpbkg.png" alt=" " width="714" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Generating embedding code&lt;/strong&gt;
. Open the report you want embedded
. Click on File ~~~~ Embed report
. Choose embedding option; either Public (Publish to Web), OR Secure Embed; which requires log in and is more secure.
. After clicking on Publish to web, Power BI will generate an embed link + iframe code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqtbvaswep896vx5pz9r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqtbvaswep896vx5pz9r.png" alt=" " width="540" height="402"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4.&lt;strong&gt;Embedding code into website&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgachdvgtcvtotj2w7qum.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgachdvgtcvtotj2w7qum.png" alt=" " width="704" height="175"&gt;&lt;/a&gt;&lt;br&gt;
. Copy entire code&lt;br&gt;
. Open your website HTML file&lt;br&gt;
. Paste the iframe code where you want your report to appear&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9fbbn0xir27ct4lcl17r.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9fbbn0xir27ct4lcl17r.jpeg" alt=" " width="800" height="728"&gt;&lt;/a&gt;&lt;br&gt;
. Save and open your website where your report will display.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CONCLUSION&lt;/strong&gt;&lt;br&gt;
Using Power BI with embedding capabilities promotes better collaboration, transparency and efficiency. This empowers users to embrace data-driven solutions that support smarter strategies and improved outcomes.&lt;/p&gt;

</description>
      <category>datascience</category>
    </item>
    <item>
      <title>HOW EXCEL IS USED IN REAL-WORLD DATA ANALYSIS</title>
      <dc:creator>Mark Glemba</dc:creator>
      <pubDate>Tue, 31 Mar 2026 19:39:06 +0000</pubDate>
      <link>https://dev.to/mark_glemba_962f6bc8a12dd/how-excel-is-used-in-real-world-data-analysis-364</link>
      <guid>https://dev.to/mark_glemba_962f6bc8a12dd/how-excel-is-used-in-real-world-data-analysis-364</guid>
      <description>&lt;p&gt;&lt;strong&gt;INTRODUCTION&lt;/strong&gt;&lt;br&gt;
Excel is a tool one can use to organize data for work or any other specific software functions. It allows one to develop graphs for comparison of data and create charts to organize and visualize data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HOW EXCEL IS USED IN REAL WORLD SCENARIOS&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DATA CLEANING&lt;/strong&gt;&lt;br&gt;
Excel is in various ways for data cleaning by performing functions such as; removing duplicates, trimming spaces, fixing formatting, finding errors, standardizing data, splitting data and filling blanks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DATA SUMMARIZATION&lt;/strong&gt;&lt;br&gt;
Excel summarizes large data sets to offer quick insights by use of; pivot tables, formulas and functions, instead of users manually going through large data sets.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;VISUALIZING TRENDS&lt;/strong&gt;&lt;br&gt;
Done by the use of charts; pie, line and bar charts.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;FORMULAS USED IN EXCEL&lt;/strong&gt;&lt;br&gt;
Basic formulas in excel include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Add&lt;/strong&gt;: Used to add values of two or more cells. The &lt;strong&gt;(+)&lt;/strong&gt; is used.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Subtract&lt;/strong&gt;: Used to subtract values of two or more cells. The &lt;strong&gt;(-)&lt;/strong&gt; is used.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multiply&lt;/strong&gt;: Used to multiply values of two or more cells. The &lt;strong&gt;(*)&lt;/strong&gt; is used.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Divide&lt;/strong&gt;: Used to divide values of two or more cells. The &lt;strong&gt;(/)&lt;/strong&gt; is used.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;BASIC FUNCTIONS USED IN EXCEL&lt;/strong&gt;&lt;br&gt;
Functions are used to automate tasks normally performed by formulas in excel. Some popular and basic functions include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;AVERAGE&lt;/strong&gt;: It sums up and calculate the mean of values within a range given. For example,&lt;strong&gt;=AVERAGE(A1:A15)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;SUM&lt;/strong&gt;: It adds up a range of cells. For example,&lt;strong&gt;=SUM(A1:A15)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;IF&lt;/strong&gt;: Used to arrange values based on a logical test. The syntax for IF ; =IF(logical_test, value_if_true, [value_if_false]). For example, &lt;strong&gt;=IF(N2&amp;gt;30, "young", "old")&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;COUNTIF&lt;/strong&gt;: Used to return the number of cells that meeet a certain criteria. The syntax is; =COUNTIF(range, criteria). For example, &lt;strong&gt;=COUNTIF(A1:A27, "Nairobi")&lt;/strong&gt;.
NOTE: COUNTIFS function counts the number of cells that meet multiple criteria.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;VLOOKUP&lt;/strong&gt;: Allows one to search for a value on a spreadsheet. Its syntax ; =VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup]). For example, &lt;strong&gt;=VLOOKUP(300,A1:A20, 3, "False")&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;CONCLUSION&lt;/strong&gt;&lt;br&gt;
In conclusion Excel's versatility makes it an efficient tool for quick analysis and reporting. Its availability allows users to efficiently handle large data sets through processes such as performing calculations and creating meaningful visuals.&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding Data Modelling in Power BI: Joins, Relationships and Schemes Explained</title>
      <dc:creator>Mark Glemba</dc:creator>
      <pubDate>Tue, 31 Mar 2026 19:13:12 +0000</pubDate>
      <link>https://dev.to/mark_glemba_962f6bc8a12dd/understanding-data-modelling-in-power-bi-joins-relationships-and-schemes-explained-290o</link>
      <guid>https://dev.to/mark_glemba_962f6bc8a12dd/understanding-data-modelling-in-power-bi-joins-relationships-and-schemes-explained-290o</guid>
      <description>&lt;p&gt;&lt;strong&gt;DATA MODELLING&lt;/strong&gt;&lt;br&gt;
This is a detailed process that involves creating a visual representation of data and its relationships.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TYPES OF TABLES&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;FACT TABLE&lt;/strong&gt;&lt;br&gt;
It contains quantitative data for analysis.&lt;br&gt;
&lt;strong&gt;DIMENSIONS TABLE&lt;/strong&gt;&lt;br&gt;
Provides context to fact table data.&lt;br&gt;
&lt;strong&gt;STAR SCHEMA&lt;/strong&gt;&lt;br&gt;
It contains a single fact table in the center that connects to multiple other dimensiontables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhnqptmrm9lwn09l1c6p6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhnqptmrm9lwn09l1c6p6.png" alt=" " width="800" height="501"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;SNOW FLAKE&lt;/strong&gt;&lt;br&gt;
Is an extension of a star schema where dimension tables are broken down into subdimensions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frmgjq5uw3m618mmypbu5.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frmgjq5uw3m618mmypbu5.jpeg" alt=" " width="783" height="391"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;FLAT TABLE&lt;/strong&gt;&lt;br&gt;
A table that displays data in a simple, two-dimensional format without any relationships to other tables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcuh1hfu2hlsjwvys5wqa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcuh1hfu2hlsjwvys5wqa.png" alt=" " width="800" height="525"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;SQL JOINS IN POWER BI&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;INNER JOIN:&lt;/strong&gt; Returns rows present in both tables if there is a match.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LEFT JOIN:&lt;/strong&gt; Returns all rows present in the left table and matching rows from the right table.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RIGHT JOIN:&lt;/strong&gt; Returns matching rows from the left table and all rows present in the SQL right table.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;FULL OUTER:&lt;/strong&gt; Returns all rows present in both right and left tables.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LEFT ANTI:&lt;/strong&gt; Returns rows from the left table that don't have matches in the right table.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RIGHT ANTI:&lt;/strong&gt;Returns rows from the right table that don't have matches in the left table.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;POWER BI RELATIONSHIPS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One-to-Many (1:M)&lt;/strong&gt;&lt;br&gt;
One row in table A matches many in table B. For example, &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhelnult1lnrvrbes04n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhelnult1lnrvrbes04n.png" alt=" " width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Many-to Many (M:M)&lt;/strong&gt;&lt;br&gt;
Here one is recommended to use a bridge table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;0ne-to-One (1:1)&lt;/strong&gt;&lt;br&gt;
One row in table A matches one in table B. For example,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftqgau1iya4upchk3qxp1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftqgau1iya4upchk3qxp1.png" alt=" " width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Many-to-One (M:M)&lt;/strong&gt;&lt;br&gt;
Many rows in table A match one in table B. For example,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhvkik8sqappibthjegf8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhvkik8sqappibthjegf8.png" alt=" " width="800" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Active and Inactive relationships&lt;/strong&gt;&lt;br&gt;
The active relationship is used by default in reports and calculations, while the inactive relationship is not used unless specified. It is also useful for alternate paths such as multiple dates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DIFFERENCE BETWEEN JOINS AND RELATIONSHIPS&lt;/strong&gt;&lt;br&gt;
Joins; combine tables based on a condition, result in new tables with combined columns and are used in power query steps. Relationships; define connections between tables in a data model and are used for; filtering, calculations and visuals across tables.&lt;/p&gt;

</description>
      <category>datascience</category>
    </item>
  </channel>
</rss>
