<?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: EricMWaimiri</title>
    <description>The latest articles on DEV Community by EricMWaimiri (@ericmwaimiri).</description>
    <link>https://dev.to/ericmwaimiri</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%2F3818862%2Fbe3f8deb-62cf-48ba-aa8c-f5fa79569d76.png</url>
      <title>DEV Community: EricMWaimiri</title>
      <link>https://dev.to/ericmwaimiri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ericmwaimiri"/>
    <language>en</language>
    <item>
      <title>A Quick Look at Unsupervised Learning</title>
      <dc:creator>EricMWaimiri</dc:creator>
      <pubDate>Fri, 21 Aug 2026 08:01:26 +0000</pubDate>
      <link>https://dev.to/ericmwaimiri/a-quick-look-at-unsupervised-learning-4fk5</link>
      <guid>https://dev.to/ericmwaimiri/a-quick-look-at-unsupervised-learning-4fk5</guid>
      <description>&lt;p&gt;If supervised learning is like studying with an answer key, unsupervised learning is like being handed a pile of unlabeled data and told: "find something interesting in here." No correct answers, no guidance — just patterns waiting to be discovered.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Makes It "Unsupervised"
&lt;/h2&gt;

&lt;p&gt;In supervised learning, every training example comes with a label — this email is "spam," this house sold for "$250,000." Unsupervised learning drops the labels entirely. You feed the algorithm raw data, and it has to find structure on its own: groupings, relationships, or a simpler way to represent the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Data (no labels) → Algorithm → Hidden Structure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This matters because in the real world, labeled data is expensive and rare. Someone has to manually tag thousands of examples before supervised learning even becomes possible. Unsupervised learning skips that requirement, which is exactly why it's so widely used for exploration and preprocessing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Two Main Problems It Solves
&lt;/h2&gt;

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

&lt;p&gt;Clustering groups similar data points together without knowing in advance what the groups should be. The algorithm looks at the data's features and decides which points "belong together."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common algorithms:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;K-Means&lt;/strong&gt; — partitions data into a fixed number of clusters based on distance from a central point.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hierarchical Clustering&lt;/strong&gt; — builds a tree of nested clusters, useful when you don't know how many groups exist.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DBSCAN&lt;/strong&gt; — groups points based on density, good for irregularly shaped clusters and detecting outliers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example use case:&lt;/strong&gt; A telecom company clusters customers by usage patterns (call frequency, data usage, time of day) to design targeted retention offers, without ever having predefined customer "types."&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Dimensionality Reduction
&lt;/h3&gt;

&lt;p&gt;Real-world datasets often have dozens or hundreds of features, many of which are redundant or noisy. Dimensionality reduction compresses that into fewer, more meaningful dimensions while preserving as much information as possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common algorithms:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PCA (Principal Component Analysis)&lt;/strong&gt; — finds the directions of maximum variance in the data and projects it onto fewer dimensions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;t-SNE&lt;/strong&gt; — good for visualizing high-dimensional data in 2D or 3D.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Autoencoders&lt;/strong&gt; — neural networks that learn a compressed representation of the input.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example use case:&lt;/strong&gt; Compressing a dataset with 500 gene-expression features down to 10 principal components so a downstream model can train faster without losing predictive power.&lt;/p&gt;

&lt;h2&gt;
  
  
  How It's Different from Supervised Learning
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Supervised&lt;/th&gt;
&lt;th&gt;Unsupervised&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Labels&lt;/td&gt;
&lt;td&gt;Required&lt;/td&gt;
&lt;td&gt;Not required&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Goal&lt;/td&gt;
&lt;td&gt;Predict a known outcome&lt;/td&gt;
&lt;td&gt;Discover hidden structure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Evaluation&lt;/td&gt;
&lt;td&gt;Accuracy, precision, recall&lt;/td&gt;
&lt;td&gt;Harder — often subjective (cluster quality, variance explained)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Example&lt;/td&gt;
&lt;td&gt;Spam detection&lt;/td&gt;
&lt;td&gt;Customer segmentation&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;One of the trickiest parts of unsupervised learning is evaluation — there's no ground truth to check against, so you often rely on domain judgment and metrics like silhouette score or explained variance rather than a clean accuracy number.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Customer segmentation&lt;/strong&gt; — Marketing teams cluster users by behavior to personalize campaigns without manually defining every segment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Anomaly detection&lt;/strong&gt; — Fraud detection and network security systems flag transactions or traffic that don't fit normal clusters, which is often more effective than trying to label every possible fraud pattern in advance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recommendation systems&lt;/strong&gt; — Many recommendation engines use clustering or matrix factorization (a form of unsupervised learning) to group similar users or items.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Image compression and organization&lt;/strong&gt; — Photo apps cluster similar images together (e.g., grouping photos by scene or face) without needing labeled training data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Genomics&lt;/strong&gt; — Researchers cluster gene expression data to discover previously unknown subtypes of diseases like cancer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Hands-On
&lt;/h2&gt;

&lt;p&gt;A good first project: take a public dataset (retail transactions, iris dataset, or a Kaggle customer dataset), run K-Means with &lt;code&gt;scikit-learn&lt;/code&gt;, and visualize the clusters with &lt;code&gt;matplotlib&lt;/code&gt; or &lt;code&gt;seaborn&lt;/code&gt;. Then try PCA on a high-dimensional dataset and see how much variance you can preserve in just 2 components.&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;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.cluster&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;KMeans&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="n"&gt;X_scaled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;StandardScaler&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;fit_transform&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;kmeans&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;KMeans&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n_clusters&lt;/span&gt;&lt;span class="o"&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;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;clusters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;kmeans&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit_predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X_scaled&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Small, hands-on experiments like this teach you more about how clustering behaves than reading the theory alone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Unsupervised learning is less about prediction and more about discovery — it's the tool you reach for when you don't yet know what questions to ask of your data. It's foundational for exploratory analysis, and often the first step before building more targeted supervised models.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Have you used clustering or dimensionality reduction in a real project? Share what you built in the comments.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>My Understanding of Machine Learning and Its Real-World Applications</title>
      <dc:creator>EricMWaimiri</dc:creator>
      <pubDate>Fri, 21 Aug 2026 07:56:34 +0000</pubDate>
      <link>https://dev.to/ericmwaimiri/my-understanding-of-machine-learning-and-its-real-world-applications-5nb</link>
      <guid>https://dev.to/ericmwaimiri/my-understanding-of-machine-learning-and-its-real-world-applications-5nb</guid>
      <description>&lt;p&gt;Machine learning (ML) shows up everywhere now — the recommendations under a YouTube video, the fraud alert your bank sends you, the autocomplete in your email. But for a lot of developers just getting into the field, "machine learning" still feels like a vague buzzword. This article breaks down what ML actually is, how it works at a conceptual level, and where it's genuinely making an impact today.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Machine Learning Actually Is
&lt;/h2&gt;

&lt;p&gt;At its core, machine learning is a way of teaching computers to find patterns in data and make decisions or predictions without being explicitly programmed for every scenario.&lt;/p&gt;

&lt;p&gt;Traditional programming looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Rules + Data → Output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You write the logic, feed in data, and get a result. Machine learning flips that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Data + Output → Rules (Model)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of writing rules by hand, you give the algorithm a bunch of examples (data) along with the correct answers (outputs), and it figures out the underlying rules itself. Those learned rules are stored in what's called a &lt;strong&gt;model&lt;/strong&gt;, which can then make predictions on new, unseen data.&lt;/p&gt;

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

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

&lt;p&gt;You train a model on labeled data — meaning every training example has a known correct answer. Think of predicting house prices based on square footage, location, and number of bedrooms, where you already have historical sales data to learn from.&lt;/p&gt;

&lt;p&gt;Common algorithms: Linear Regression, Decision Trees, Random Forests, Support Vector Machines.&lt;/p&gt;

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

&lt;p&gt;Here, the data has no labels. The model's job is to find hidden structure or groupings on its own — like clustering customers into segments based on purchasing behavior, without being told in advance what those segments should be.&lt;/p&gt;

&lt;p&gt;Common algorithms: K-Means Clustering, Hierarchical Clustering, PCA.&lt;/p&gt;

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

&lt;p&gt;The model (called an "agent") learns by interacting with an environment and receiving rewards or penalties based on its actions. This is how systems learn to play games or control robots — through trial, error, and feedback.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Simple Way to Think About the ML Workflow
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Collect data&lt;/strong&gt; — the raw material everything else depends on.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clean and prepare it&lt;/strong&gt; — handle missing values, remove noise, format consistently.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Choose a model&lt;/strong&gt; — pick an algorithm suited to the problem type.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Train the model&lt;/strong&gt; — let it learn patterns from the data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Evaluate performance&lt;/strong&gt; — test it on data it hasn't seen before.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deploy&lt;/strong&gt; — put it into a real application where it can make live predictions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monitor and retrain&lt;/strong&gt; — real-world data changes, so models need updates over time.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;h3&gt;
  
  
  Healthcare
&lt;/h3&gt;

&lt;p&gt;ML models help detect diseases earlier by analyzing medical images (X-rays, MRIs) for patterns too subtle for the human eye to catch consistently. They're also used to predict patient readmission risk and personalize treatment plans.&lt;/p&gt;

&lt;h3&gt;
  
  
  Finance
&lt;/h3&gt;

&lt;p&gt;Banks use ML for fraud detection by spotting unusual transaction patterns in real time. Credit scoring models assess loan risk, and algorithmic trading systems use ML to react to market signals faster than any human could.&lt;/p&gt;

&lt;h3&gt;
  
  
  E-commerce and Retail
&lt;/h3&gt;

&lt;p&gt;Recommendation engines (like the ones on Amazon or Netflix) use collaborative filtering and other ML techniques to suggest products or content based on your behavior and the behavior of similar users.&lt;/p&gt;

&lt;h3&gt;
  
  
  Transportation
&lt;/h3&gt;

&lt;p&gt;Self-driving car systems rely heavily on ML for object detection, lane recognition, and decision-making. Ride-sharing apps use it to predict demand and optimize pricing and routing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Natural Language Processing (NLP)
&lt;/h3&gt;

&lt;p&gt;Chatbots, translation tools, sentiment analysis, and voice assistants like Siri or Alexa are all powered by ML models trained on massive amounts of text and speech data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Agriculture
&lt;/h3&gt;

&lt;p&gt;ML is used to predict crop yields, detect plant diseases from images, and optimize irrigation schedules using sensor and satellite data — genuinely useful in regions where farming is a major part of the economy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started as a Developer
&lt;/h2&gt;

&lt;p&gt;If you're a developer looking to get into ML, here's a practical path:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Learn Python&lt;/strong&gt; — it's the dominant language in the ML ecosystem.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Get comfortable with data manipulation&lt;/strong&gt; — libraries like Pandas and NumPy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Understand the math intuitively&lt;/strong&gt; — you don't need to derive every equation, but grasp what concepts like gradient descent and loss functions are doing conceptually.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use scikit-learn&lt;/strong&gt; for classical ML algorithms before jumping into deep learning frameworks like TensorFlow or PyTorch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Work on real datasets&lt;/strong&gt; — Kaggle is a great place to practice with actual messy data instead of toy examples.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build small projects&lt;/strong&gt; — predicting something simple end-to-end teaches you more than reading ten tutorials.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Machine learning isn't magic — it's pattern recognition at scale, powered by data and statistics. The real value comes from applying it to real problems: catching fraud before it happens, diagnosing illness earlier, or helping farmers get better yields. If you're a developer, you don't need a PhD to start — you need curiosity, some Python, and a dataset to experiment with.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;What ML application are you most interested in building? Let me know in the comments.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>machinelearning</category>
    </item>
    <item>
      <title>I Built My First Machine Learning API — Here's Everything I Learned</title>
      <dc:creator>EricMWaimiri</dc:creator>
      <pubDate>Thu, 13 Aug 2026 22:49:39 +0000</pubDate>
      <link>https://dev.to/ericmwaimiri/i-built-my-first-machine-learning-api-heres-everything-i-learned-1f7</link>
      <guid>https://dev.to/ericmwaimiri/i-built-my-first-machine-learning-api-heres-everything-i-learned-1f7</guid>
      <description>&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/EricMWaimiri" rel="noopener noreferrer"&gt;
        EricMWaimiri
      &lt;/a&gt; / &lt;a href="https://github.com/EricMWaimiri/Telco-Customer-Churn-Prediction" rel="noopener noreferrer"&gt;
        Telco-Customer-Churn-Prediction
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Customer Churn Prediction&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;Predicts whether a telecom customer will churn using the Telco Customer Churn
dataset. The project covers data cleaning and EDA, comparison of three
classifiers, and a FastAPI service that serves the final model.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Project Structure&lt;/h2&gt;
&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;.
├── API/
│   └── main.py                                 # FastAPI app serving the model
├── Data/
│   └── WA_Fn-UseC_-Telco-Customer-Churn.csv    # raw dataset (7,043 customers)
├── Models/
│   ├── ml_pipeline.joblib                      # fitted preprocessing + classifier pipeline
│   └── target_labels.joblib                    # LabelEncoder for the churn target
├── Notebooks/
│   └── customer_churn_prediction.ipynb         # data cleaning, EDA, model training
├── cpp/                                        # (Python virtual environment)
├── .env                                        # environment variables (not committed)
├── .gitignore
├── requirements.txt
└── README.md
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code&gt;main.py&lt;/code&gt; loads &lt;code&gt;../models/ml_pipeline.joblib&lt;/code&gt; and &lt;code&gt;../models/target_labels.joblib&lt;/code&gt;,
so it must be run from inside &lt;code&gt;API/&lt;/code&gt; for those relative paths to resolve.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Dataset&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;The raw data is the &lt;a href="https://www.kaggle.com/datasets/blastchar/telco-customer-churn" rel="nofollow noopener noreferrer"&gt;Telco Customer Churn dataset&lt;/a&gt;
7,043 rows and 21 columns covering customer demographics, account…&lt;/p&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/EricMWaimiri/Telco-Customer-Churn-Prediction" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;If you've ever trained a model in a Jupyter notebook and then wondered "okay... now what?" — this post is for you. I recently built a &lt;strong&gt;Customer Churn Prediction API&lt;/strong&gt;, and I want to walk you through it the way I wish someone had walked me through my first one: no jargon dump, just what each piece does and why it's there.&lt;/p&gt;

&lt;p&gt;Think of it like a Safaricom customer care team trying to figure out &lt;strong&gt;which subscribers are about to switch to Airtel&lt;/strong&gt; — before they actually leave. That's churn prediction. And instead of leaving that insight trapped inside a notebook, I turned it into an API anyone (or any app) can call.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem: A Notebook Is Not a Product
&lt;/h2&gt;

&lt;p&gt;I started, like most people do, in a Jupyter notebook. I had a dataset of telecom customers — their contract type, monthly charges, whether they had streaming services, and so on — with a label saying whether they churned (left) or not.&lt;/p&gt;

&lt;p&gt;I cleaned the data, explored it, trained a few models, and picked a winner. Cool. But here's the thing: &lt;strong&gt;a trained model sitting in a notebook is useless to anyone else.&lt;/strong&gt; A frontend developer can't "import your notebook" into an app. A business analyst can't click a button in your &lt;code&gt;.ipynb&lt;/code&gt; file to get a prediction.&lt;/p&gt;

&lt;p&gt;That's the gap an API fills.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: From Raw Data to a Trained Model
&lt;/h2&gt;

&lt;p&gt;Before any API talk, the notebook had to do its job. Here's the flow, in plain English:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Load the data&lt;/strong&gt; — a CSV of ~7,000 customers with columns like &lt;code&gt;gender&lt;/code&gt;, &lt;code&gt;tenure&lt;/code&gt;, &lt;code&gt;Contract&lt;/code&gt;, &lt;code&gt;MonthlyCharges&lt;/code&gt;, and the target column, &lt;code&gt;Churn&lt;/code&gt; (Yes/No).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clean it up&lt;/strong&gt; — column names get lowercased and stripped of spaces (&lt;code&gt;TotalCharges&lt;/code&gt; becomes &lt;code&gt;totalcharges&lt;/code&gt;), and a numeric column that was secretly stored as text gets converted properly. A handful of broken rows get dropped.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explore it (EDA)&lt;/strong&gt; — check the churn rate, look at unique values in each category, plot the class balance. This is where you catch surprises before they wreck your model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Split the data&lt;/strong&gt; — into training and testing sets, so you can honestly check how well the model generalizes instead of just memorizing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Preprocess&lt;/strong&gt; — numeric columns (like &lt;code&gt;tenure&lt;/code&gt; and &lt;code&gt;MonthlyCharges&lt;/code&gt;) get scaled, and categorical columns (like &lt;code&gt;Contract&lt;/code&gt; or &lt;code&gt;PaymentMethod&lt;/code&gt;) get one-hot encoded, because models only understand numbers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Train and compare models&lt;/strong&gt; — I tried Logistic Regression, K-Nearest Neighbors, and a Random Forest, then compared their classification reports.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Save the winner&lt;/strong&gt; — using &lt;code&gt;joblib&lt;/code&gt;, I saved the entire fitted pipeline (preprocessing + model, bundled together) plus the label encoder, so predictions later come back as "Yes"/"No" instead of &lt;code&gt;1&lt;/code&gt;/&lt;code&gt;0&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That last step is the bridge to everything that follows. Once your pipeline is saved to disk, it stops being "notebook code" and becomes a &lt;strong&gt;reusable artifact&lt;/strong&gt; — a file any Python program can load and use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: What Even Is an API, in Plain Terms?
&lt;/h2&gt;

&lt;p&gt;An API is just a way for two programs to talk to each other over the web, using a set of agreed-upon rules. You send it something, it sends something back.&lt;/p&gt;

&lt;p&gt;For this project, the deal is simple:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Send me a customer's details, and I'll tell you whether they're likely to churn."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's it. No magic. Just a structured request in, a structured response out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Enter FastAPI
&lt;/h2&gt;

&lt;p&gt;I used &lt;a href="https://fastapi.tiangolo.com/" rel="noopener noreferrer"&gt;FastAPI&lt;/a&gt;, a Python framework built specifically for creating APIs quickly, with automatic validation and interactive documentation baked in.&lt;/p&gt;

&lt;p&gt;Here's the skeleton of what's happening in &lt;code&gt;main.py&lt;/code&gt;:&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;joblib&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;fastapi&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;FastAPI&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pydantic&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BaseModel&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="c1"&gt;# Load the model and target labels
&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;joblib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;../models/target_labels.joblib&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="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;joblib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;../models/ml_pipeline.joblib&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FastAPI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Customer Churn Prediction API&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;An API for predicting customer churn using a pre-trained machine learning model.&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;p&gt;Two things happen right at the top, before the API even starts handling requests:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;trained pipeline&lt;/strong&gt; (&lt;code&gt;ml_pipeline.joblib&lt;/code&gt;) is loaded into memory. This is the exact same preprocessing + model combo we saved from the notebook.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;label encoder&lt;/strong&gt; (&lt;code&gt;target_labels.joblib&lt;/code&gt;) is loaded too, so we can turn a &lt;code&gt;0&lt;/code&gt;/&lt;code&gt;1&lt;/code&gt; prediction back into a human-readable "No"/"Yes".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This only happens &lt;strong&gt;once&lt;/strong&gt;, when the server starts — not on every request. That's important for speed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Defining What "Valid Input" Looks Like
&lt;/h2&gt;

&lt;p&gt;This is the part that impressed me most as a beginner. FastAPI uses something called &lt;strong&gt;Pydantic&lt;/strong&gt; to define exactly what shape your input data must be:&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;class&lt;/span&gt; &lt;span class="nc"&gt;InputData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;gender&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;seniorcitizen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;partner&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;dependents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;tenure&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;phoneservice&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;multiplelines&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;internetservice&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;onlinesecurity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;onlinebackup&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;deviceprotection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;techsupport&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;streamingtv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;streamingmovies&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;paperlessbilling&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;paymentmethod&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;monthlycharges&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;
    &lt;span class="n"&gt;totalcharges&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every field here mirrors a column the model was trained on. If someone sends &lt;code&gt;tenure&lt;/code&gt; as &lt;code&gt;"twelve"&lt;/code&gt; instead of &lt;code&gt;12&lt;/code&gt;, FastAPI rejects the request automatically — before it ever reaches your model. You don't write a single line of manual validation code. That alone saved me from a bunch of silent bugs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: The Actual Endpoints
&lt;/h2&gt;

&lt;p&gt;An API exposes "endpoints" — specific URLs that do specific things. This project has two.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A health check&lt;/strong&gt;, so you (or a monitoring tool) can confirm the API is alive:&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="nd"&gt;@app.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/health&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tags&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;Health Check&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;health_check&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&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;API is running&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;p&gt;&lt;strong&gt;The actual prediction endpoint&lt;/strong&gt;:&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="nd"&gt;@app.post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/predict&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tags&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;Prediction&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;predict_churn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;InputData&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Convert input data to DataFrame
&lt;/span&gt;    &lt;span class="n"&gt;input_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;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;model_dump&lt;/span&gt;&lt;span class="p"&gt;()])&lt;/span&gt;

    &lt;span class="c1"&gt;# Make prediction
&lt;/span&gt;    &lt;span class="n"&gt;prediction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input_df&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Decode the prediction
&lt;/span&gt;    &lt;span class="n"&gt;decoded_prediction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;inverse_transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prediction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;prediction&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;decoded_prediction&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Walking through it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;FastAPI already validated and parsed the incoming JSON into &lt;code&gt;payload&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;payload.model_dump()&lt;/code&gt; turns it into a plain dictionary, which gets wrapped into a one-row pandas DataFrame — because that's the format the trained pipeline expects.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;model.predict(...)&lt;/code&gt; runs that row through the &lt;strong&gt;exact same preprocessing steps&lt;/strong&gt; used during training (scaling, one-hot encoding), then through the classifier.&lt;/li&gt;
&lt;li&gt;The result comes back as a number (&lt;code&gt;0&lt;/code&gt; or &lt;code&gt;1&lt;/code&gt;), so &lt;code&gt;labels.inverse_transform(...)&lt;/code&gt; converts it back into &lt;code&gt;"No"&lt;/code&gt; or &lt;code&gt;"Yes"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;We return it as JSON.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's the whole loop: &lt;strong&gt;JSON in → DataFrame → pipeline → prediction → JSON out.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Trying It Out
&lt;/h2&gt;

&lt;p&gt;Once you run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uvicorn main:app &lt;span class="nt"&gt;--reload&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;FastAPI gives you a free interactive docs page at &lt;code&gt;http://127.0.0.1:8000/docs&lt;/code&gt;, where you can literally fill in a form and hit "Execute" to test &lt;code&gt;/predict&lt;/code&gt; without writing a single line of client code. As a beginner, this is where it finally clicked for me — seeing my model respond to a request in real time made it feel like a real product, not just a school notebook exercise.&lt;/p&gt;

&lt;p&gt;Send it something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"gender"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Female"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"seniorcitizen"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"partner"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Yes"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"dependents"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"No"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"tenure"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"phoneservice"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"No"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"multiplelines"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"No phone service"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"internetservice"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"DSL"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"onlinesecurity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"No"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"onlinebackup"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Yes"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"deviceprotection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"No"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"techsupport"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"No"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"streamingtv"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"No"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"streamingmovies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"No"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"contract"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Month-to-month"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"paperlessbilling"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Yes"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"paymentmethod"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Electronic check"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"monthlycharges"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;29.85&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"totalcharges"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;29.85&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you get back:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"prediction"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"No"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Lesson That Stuck With Me
&lt;/h2&gt;

&lt;p&gt;Training a model answers the question "does this work?" Building an API answers a completely different question: &lt;strong&gt;"can anyone else use this?"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Those are two separate skills, and honestly, the second one felt more like real software engineering — dependency management, input validation, documentation, deployment thinking — than the modeling part did. If you've been putting off learning how to serve your models, don't. It's a smaller leap than it looks, and FastAPI in particular makes it a genuinely beginner-friendly one.&lt;/p&gt;

&lt;p&gt;If you're working through something similar — maybe predicting M-Pesa transaction fraud, or matatu route demand — the pattern is identical: train, save the pipeline, load it in an API, validate input, predict, respond. Once you've done it once, you'll do it in your sleep.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Have you built your first ML API yet? What tripped you up the most — validation, deployment, or something else entirely? Let me know in the comments.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>python</category>
      <category>fastapi</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A Beginner’s Guide to Regression and Regularization</title>
      <dc:creator>EricMWaimiri</dc:creator>
      <pubDate>Tue, 21 Jul 2026 14:57:54 +0000</pubDate>
      <link>https://dev.to/ericmwaimiri/a-beginners-guide-to-regression-and-regularization-554b</link>
      <guid>https://dev.to/ericmwaimiri/a-beginners-guide-to-regression-and-regularization-554b</guid>
      <description>&lt;p&gt;Machine learning often starts with a simple question: Can we predict a number from data?&lt;br&gt;&lt;br&gt;
That’s where regression comes in. It’s one of the most fundamental techniques in data science, and understanding it opens the door to more advanced models.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Regression?
&lt;/h2&gt;

&lt;p&gt;Regression is about predicting a continuous target variable (like salary, house price, or temperature) based on one or more input features.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simple Linear Regression&lt;/strong&gt;: Predicts using one feature.&lt;br&gt;&lt;br&gt;
Example: Predicting house price from square footage.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multiple Linear Regression&lt;/strong&gt;: Uses several features.&lt;br&gt;&lt;br&gt;
&lt;em&gt;Example: Predicting salary from years of experience, education level, and certifications.&lt;/em&gt;&lt;br&gt;
The general form looks like this:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  General form of a multiple linear regression model:
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;y = β0 + β1*x1 + β2*x2 + ... + βn*xn + ε
Where:
y      - target (the value we want to predict)
x1..xn - features (input variables)
β      - coefficients (weights learned by the model)
ε      - error term (the part the model cannot explain)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Why Regularization?
&lt;/h2&gt;

&lt;p&gt;Regression models can sometimes overfit — they learn the training data too well, including noise, and fail to generalize to new data.&lt;br&gt;&lt;br&gt;
This happens especially when you have many features or multicollinearity (features highly correlated with each other).&lt;/p&gt;

&lt;p&gt;Regularization is a technique to prevent overfitting by adding a penalty to the size of the coefficients.&lt;/p&gt;




&lt;h2&gt;
  
  
  Types of Regularization
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Ridge Regression
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Adds a penalty proportional to the square of coefficients.
&lt;/li&gt;
&lt;li&gt;Encourages smaller, more stable coefficients.
&lt;/li&gt;
&lt;li&gt;Formula:
&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Ridge Regression Loss Function:
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Loss = RSS + λ * Σ(β_j^2)
Where:
RSS   - Residual Sum of Squares (error between predictions and actual values)
λ     - Regularization parameter (controls penalty strength)
β_j   - Coefficients of the regression model
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Lasso Regression
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Adds a penalty proportional to the absolute value of coefficients.
&lt;/li&gt;
&lt;li&gt;Can shrink some coefficients to zero, effectively performing feature selection.
&lt;/li&gt;
&lt;li&gt;Formula:
&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Lasso Regression Loss Function:
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Loss = RSS + λ * Σ|β_j|
Where:
RSS   - Residual Sum of Squares (error between predictions and actual values)
λ     - Regularization parameter (controls penalty strength)
β_j   - Coefficients of the regression model
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note:&lt;br&gt;
 The absolute value penalty (|β_j|) can shrink some coefficients exactly to zero.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This makes Lasso useful for feature selection as well as preventing overfitting.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Elastic Net
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Combines Ridge and Lasso penalties.
&lt;/li&gt;
&lt;li&gt;Useful when you want both stability and feature selection.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Choosing Between Them
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use Ridge when you have many correlated features.
&lt;/li&gt;
&lt;li&gt;Use Lasso when you suspect only a few features are truly important.
&lt;/li&gt;
&lt;li&gt;Use Elastic Net when you want a balance of both.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Practical Example in Python
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
python
from sklearn.linear_model import LinearRegression, Ridge, Lasso

# Simple regression
lin_reg = LinearRegression().fit(X_train, y_train)

# Ridge regression
ridge_reg = Ridge(alpha=1.0).fit(X_train, y_train)

# Lasso regression
lasso_reg = Lasso(alpha=0.1).fit(X_train, y_train)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>machinelearning</category>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>Power BI DAX Essential Functions — Explained with Examples</title>
      <dc:creator>EricMWaimiri</dc:creator>
      <pubDate>Sun, 12 Jul 2026 18:20:08 +0000</pubDate>
      <link>https://dev.to/ericmwaimiri/power-bi-dax-essential-functions-explained-with-examples-kif</link>
      <guid>https://dev.to/ericmwaimiri/power-bi-dax-essential-functions-explained-with-examples-kif</guid>
      <description>&lt;p&gt;If you’ve ever struggled with &lt;code&gt;CALCULATE()&lt;/code&gt; or wondered why &lt;code&gt;SUMX()&lt;/code&gt; behaves differently from &lt;code&gt;SUM()&lt;/code&gt;, this guide is for you.&lt;br&gt;&lt;br&gt;
DAX (Data Analysis Expressions) is the language that powers &lt;strong&gt;Power BI&lt;/strong&gt;, &lt;strong&gt;Analysis Services&lt;/strong&gt;, and &lt;strong&gt;Power Pivot&lt;/strong&gt; — enabling dynamic calculations, filtering, and time intelligence.&lt;/p&gt;

&lt;p&gt;Below is a categorized cheat sheet of &lt;strong&gt;essential DAX functions&lt;/strong&gt;, plus examples showing how to use each in real-world Power BI scenarios.&lt;/p&gt;




&lt;h2&gt;
  
  
  Filtering &amp;amp; Context
&lt;/h2&gt;

&lt;p&gt;These functions control how filters are applied and evaluated in your calculations.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CALCULATE()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CALCULATE(SUM(Sales[Amount]), Region[Name] = "Nairobi")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Changes filter context to calculate total sales for Nairobi.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;FILTER()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;FILTER(Sales, Sales[Amount] &amp;gt; 10000)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns a table filtered by condition.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ALL()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CALCULATE(SUM(Sales[Amount]), ALL(Region))&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Ignores filters on Region.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;REMOVEFILTERS()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CALCULATE(SUM(Sales[Amount]), REMOVEFILTERS(Region))&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Removes filters from Region.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;VALUES()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;VALUES(Customer[City])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns unique list of cities.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SELECTEDVALUE()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SELECTEDVALUE(Product[Category], "All")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns selected category or “All” if none.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;TREATAS()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;TREATAS(VALUES(Temp[City]), Customer[City])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Applies one table’s values as filters on another.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;KEEPFILTERS()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CALCULATE(SUM(Sales[Amount]), KEEPFILTERS(Product[Category] = "Electronics"))&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Keeps existing filters and adds new ones.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ALLSELECTED()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CALCULATE(SUM(Sales[Amount]), ALLSELECTED(Region))&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Respects user selections in visuals.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ALLEXCEPT()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CALCULATE(SUM(Sales[Amount]), ALLEXCEPT(Sales, Sales[Year]))&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Removes all filters except Year.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Aggregation
&lt;/h2&gt;

&lt;p&gt;Summarize or aggregate data across rows or columns.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SUM()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SUM(Sales[Amount])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Adds all sales amounts.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;AVERAGE()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;AVERAGE(Sales[Amount])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Calculates mean value.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;COUNT()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;COUNT(Customer[ID])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Counts non-blank entries.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;COUNTROWS()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;COUNTROWS(Sales)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Counts rows in a table.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DISTINCTCOUNT()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DISTINCTCOUNT(Customer[ID])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Counts unique customers.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MIN()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;MIN(Sales[Amount])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Finds smallest sale.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MAX()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;MAX(Sales[Amount])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Finds largest sale.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Iterator (X) Functions
&lt;/h2&gt;

&lt;p&gt;Perform row-by-row calculations before aggregation.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SUMX()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SUMX(Sales, Sales[Quantity] * Sales[Price])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Calculates total revenue per row, then sums.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;AVERAGEX()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;AVERAGEX(Products, Products[ProfitMargin])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Averages profit margins across products.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MINX()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;MINX(Orders, Orders[DeliveryDays])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Finds minimum delivery days.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MAXX()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;MAXX(Orders, Orders[DeliveryDays])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Finds maximum delivery days.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Logical Functions
&lt;/h2&gt;

&lt;p&gt;Control flow and conditional logic.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;IF()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;IF(Sales[Amount] &amp;gt; 10000, "High", "Low")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns “High” or “Low” based on condition.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SWITCH()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SWITCH(TRUE(), Sales[Amount] &amp;gt; 10000, "High", Sales[Amount] &amp;gt; 5000, "Medium", "Low")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Multi-condition logic.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;COALESCE()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;COALESCE(Sales[Discount], 0)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Replaces blanks with default value.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Relationship Functions
&lt;/h2&gt;

&lt;p&gt;Work across related tables.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;RELATED()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;RELATED(Customer[Name])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fetches related customer name.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;LOOKUPVALUE()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;LOOKUPVALUE(Customer[Email], Customer[ID], Sales[CustomerID])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Finds email based on ID.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;USERELATIONSHIP()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CALCULATE(SUM(Sales[Amount]), USERELATIONSHIP(Sales[Date], Calendar[Date]))&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Activates inactive relationship.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Ranking Functions
&lt;/h2&gt;

&lt;p&gt;Rank or sort data dynamically.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;RANKX()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;RANKX(ALL(Customer), SUM(Sales[Amount]), , DESC)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Ranks customers by total sales.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;TOPN()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;TOPN(5, Sales, Sales[Amount], DESC)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns top 5 sales records.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Mathematical Functions
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DIVIDE()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DIVIDE(SUM(Sales[Profit]), SUM(Sales[Revenue]), 0)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Safe division avoiding errors.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ROUND()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ROUND(Sales[Amount], 2)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Rounds to two decimals.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Date &amp;amp; Time Functions
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;TODAY()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;TODAY()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns current date.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;NOW()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;NOW()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns current date and time.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DATEDIFF()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DATEDIFF(Orders[OrderDate], Orders[ShipDate], DAY)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Calculates days between two dates.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Time Intelligence
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DATEADD()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DATEADD(Calendar[Date], -1, YEAR)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Shifts date context by one year.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SAMEPERIODLASTYEAR()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SAMEPERIODLASTYEAR(Calendar[Date])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Compares same period last year.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;TOTALYTD()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;TOTALYTD(SUM(Sales[Amount]), Calendar[Date])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Year-to-date total.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DATESBETWEEN()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DATESBETWEEN(Calendar[Date], DATE(2026,1,1), DATE(2026,6,30))&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Filters dates between range.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DATESINPERIOD()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DATESINPERIOD(Calendar[Date], MAX(Calendar[Date]), -30, DAY)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Last 30 days.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Table Functions
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ADDCOLUMNS()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ADDCOLUMNS(Sales, "Profit", Sales[Revenue] - Sales[Cost])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Adds calculated column.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SUMMARIZE()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SUMMARIZE(Sales, Region[Name], "TotalSales", SUM(Sales[Amount]))&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Groups and summarizes data.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SUMMARIZECOLUMNS()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SUMMARIZECOLUMNS(Region[Name], "TotalSales", SUM(Sales[Amount]))&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Similar to SUMMARIZE but optimized.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;UNION()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;UNION(TableA, TableB)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Combines two tables.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;INTERSECT()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;INTERSECT(TableA, TableB)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns common rows.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;EXCEPT()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;EXCEPT(TableA, TableB)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns rows in A not in B.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Text Functions
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;LEFT()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;LEFT(Customer[Name], 3)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;First three letters.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;RIGHT()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;RIGHT(Customer[Name], 3)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Last three letters.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SEARCH()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SEARCH("Ltd", Company[Name], 1, -1)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Finds position of substring.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CONCATENATEX()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CONCATENATEX(Customer, Customer[Name], ", ")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Joins names with commas.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Information Functions
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ISBLANK()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;IF(ISBLANK(Sales[Amount]), 0, Sales[Amount])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checks for blank values.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;HASONEVALUE()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;IF(HASONEVALUE(Product[Category]), VALUES(Product[Category]), "Multiple")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Detects single selection.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;These functions form the foundation of every Power BI model.&lt;br&gt;&lt;br&gt;
Mastering them means you can build dynamic dashboards, automate KPIs, and handle complex business logic with ease.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Tip: Start with &lt;code&gt;CALCULATE()&lt;/code&gt;, &lt;code&gt;FILTER()&lt;/code&gt;, and &lt;code&gt;SUMX()&lt;/code&gt; — they’re the most powerful trio in DAX.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  Source
&lt;/h3&gt;

&lt;p&gt;Microsoft DAX Documentation&lt;br&gt;&lt;br&gt;
Essential DAX functions for building powerful Power BI reports and models.&lt;/p&gt;




</description>
      <category>analytics</category>
      <category>datascience</category>
      <category>microsoft</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Parametric vs Non-Parametric Statistical Tests</title>
      <dc:creator>EricMWaimiri</dc:creator>
      <pubDate>Mon, 06 Jul 2026 05:28:28 +0000</pubDate>
      <link>https://dev.to/ericmwaimiri/parametric-vs-non-parametric-statistical-tests-4601</link>
      <guid>https://dev.to/ericmwaimiri/parametric-vs-non-parametric-statistical-tests-4601</guid>
      <description>&lt;h2&gt;
  
  
  What Are They?
&lt;/h2&gt;

&lt;p&gt;Statistical tests fall into two broad categories: &lt;strong&gt;parametric&lt;/strong&gt; and &lt;strong&gt;non-parametric&lt;/strong&gt;. The choice between them affects the validity of your conclusions — picking the wrong one can lead to misleading results.&lt;/p&gt;




&lt;h2&gt;
  
  
  Parametric Tests
&lt;/h2&gt;

&lt;p&gt;Parametric tests make assumptions about the underlying population distribution, most commonly that the data is &lt;strong&gt;normally distributed&lt;/strong&gt;. They work with the actual values in your data (means, variances) and tend to be more powerful when their assumptions are met.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common parametric tests:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;t-test (compare means between two groups)&lt;/li&gt;
&lt;li&gt;ANOVA (compare means across three or more groups)&lt;/li&gt;
&lt;li&gt;Pearson correlation (measure linear relationship between two variables)&lt;/li&gt;
&lt;li&gt;Linear regression&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;When to use them:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your data is continuous&lt;/li&gt;
&lt;li&gt;Sample size is large enough for the Central Limit Theorem to apply (typically n &amp;gt; 30)&lt;/li&gt;
&lt;li&gt;Data is approximately normally distributed&lt;/li&gt;
&lt;li&gt;Variances across groups are roughly equal (homoscedasticity)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Non-Parametric Tests
&lt;/h2&gt;

&lt;p&gt;Non-parametric tests make no assumptions about the population distribution. They work with &lt;strong&gt;ranks or categories&lt;/strong&gt; rather than raw values, making them more flexible — but generally less powerful than parametric tests when parametric assumptions hold.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common non-parametric tests:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mann-Whitney U test (equivalent of independent t-test)&lt;/li&gt;
&lt;li&gt;Wilcoxon signed-rank test (equivalent of paired t-test)&lt;/li&gt;
&lt;li&gt;Kruskal-Wallis test (equivalent of one-way ANOVA)&lt;/li&gt;
&lt;li&gt;Spearman correlation (rank-based correlation)&lt;/li&gt;
&lt;li&gt;Chi-square test (categorical data)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;When to use them:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data is ordinal (e.g. satisfaction scores, rankings)&lt;/li&gt;
&lt;li&gt;Data is heavily skewed or contains outliers&lt;/li&gt;
&lt;li&gt;Sample size is small (n &amp;lt; 30)&lt;/li&gt;
&lt;li&gt;Data violates normality assumptions&lt;/li&gt;
&lt;li&gt;You are working with categorical or nominal data&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Differences
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Parametric&lt;/th&gt;
&lt;th&gt;Non-Parametric&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Distribution assumption&lt;/td&gt;
&lt;td&gt;Yes (usually normal)&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data type&lt;/td&gt;
&lt;td&gt;Continuous&lt;/td&gt;
&lt;td&gt;Ordinal, categorical, or non-normal continuous&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Statistical power&lt;/td&gt;
&lt;td&gt;Higher (when assumptions met)&lt;/td&gt;
&lt;td&gt;Lower&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sensitivity to outliers&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sample size requirement&lt;/td&gt;
&lt;td&gt;Larger&lt;/td&gt;
&lt;td&gt;Smaller&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Role in Data Science
&lt;/h2&gt;

&lt;p&gt;In data science, both approaches appear regularly across the analytics workflow.&lt;/p&gt;

&lt;p&gt;Parametric tests are common in A/B testing (t-tests for comparing conversion rates at scale), regression modelling, and feature correlation analysis where datasets are large and roughly normal.&lt;/p&gt;

&lt;p&gt;Non-parametric tests are essential when working with customer satisfaction scores, survey data, small samples, or any dataset where normality cannot be assumed, which is more often the case in real-world business data than textbooks suggest.&lt;/p&gt;

&lt;p&gt;A practical rule: always check your data's distribution before choosing a test. Use a histogram, Q-Q plot, or the Shapiro-Wilk test to assess normality. If in doubt, non-parametric tests are the safer default, they sacrifice a little power in exchange for broader applicability.&lt;/p&gt;




&lt;p&gt;Parametric tests are more powerful but demand more from your data. Non-parametric tests are more flexible and robust. In data science, knowing when to apply each and being able to justify your choice is as important as running the test itself.&lt;/p&gt;

</description>
      <category>analytics</category>
      <category>data</category>
      <category>datascience</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How I Explored a US Health Dataset with Python — EDA + Hypothesis Testing</title>
      <dc:creator>EricMWaimiri</dc:creator>
      <pubDate>Sun, 28 Jun 2026 18:11:25 +0000</pubDate>
      <link>https://dev.to/ericmwaimiri/how-i-explored-a-us-health-dataset-with-python-eda-hypothesis-testing-2fb7</link>
      <guid>https://dev.to/ericmwaimiri/how-i-explored-a-us-health-dataset-with-python-eda-hypothesis-testing-2fb7</guid>
      <description>&lt;p&gt;I recently completed an exploratory data analysis project on the &lt;strong&gt;NHANES (National Health and Nutrition Examination Survey)&lt;/strong&gt; dataset from Kaggle. It's a real-world health survey collected by the CDC covering body measurements, lifestyle habits, and demographic data from thousands of US adults.&lt;/p&gt;

&lt;p&gt;In this article I'll walk you through exactly what I did — from loading and cleaning the data all the way to running statistical tests — and share what I found along the way.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Dataset
&lt;/h2&gt;

&lt;p&gt;The dataset has &lt;strong&gt;5,735 rows and 28 columns&lt;/strong&gt;, but for this project I focused on 8 columns that were relevant to the questions I wanted to answer:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Column&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;smoking&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Has the person smoked at least 100 cigarettes?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;gender&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Male or Female&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;age&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Age in years&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;education&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Highest level of education&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;weight&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Weight in kg&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;height&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Height in cm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;bmi&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Body Mass Index&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Step 1 — Loading and Selecting Columns
&lt;/h2&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;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;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="n"&gt;db&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;NHANES.csv&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loc&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;SEQN&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;SMQ020&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;RIAGENDR&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;RIDAGEYR&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;DMDEDUC2&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;BMXWT&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;BMXHT&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;BMXBMI&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rename&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;SEQN&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;id&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;SMQ020&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;smoking&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;RIAGENDR&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;gender&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;RIDAGEYR&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;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;DMDEDUC2&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;education&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;BMXWT&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;weight&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;BMXHT&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;height&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;BMXBMI&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;bmi&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;p&gt;One thing worth knowing about NHANES: all the columns come in as numeric codes. &lt;code&gt;1&lt;/code&gt; means Male, &lt;code&gt;2&lt;/code&gt; means Female. &lt;code&gt;1&lt;/code&gt; means the person smoked, &lt;code&gt;2&lt;/code&gt; means they didn't. You have to map these to readable labels before doing any analysis, otherwise your charts are meaningless.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 2 — Cleaning the Data
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Drop the ID column and remove nulls
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&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="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;axis&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;inplace&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;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dropna&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inplace&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This brought us from 5,735 rows down to 5,406 — about 6% lost, which is acceptable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remove outliers using the IQR method
&lt;/h3&gt;

&lt;p&gt;The IQR (Interquartile Range) method flags values that fall too far outside the middle 50% of the data:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lower bound&lt;/strong&gt; = Q1 − 1.5 × IQR&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Upper bound&lt;/strong&gt; = Q3 + 1.5 × IQR
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Height outlier removal
&lt;/span&gt;&lt;span class="n"&gt;hq25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hq50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hq75&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;height&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;quantile&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mf"&gt;0.25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.75&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="n"&gt;hiqr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hq75&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;hq25&lt;/span&gt;
&lt;span class="n"&gt;hlower&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hq25&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;1.5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;hiqr&lt;/span&gt;
&lt;span class="n"&gt;hupper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hq75&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;1.5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;hiqr&lt;/span&gt;
&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&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;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;height&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;hlower&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&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="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;height&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;hupper&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I applied this to &lt;code&gt;height&lt;/code&gt;, &lt;code&gt;weight&lt;/code&gt;, and &lt;code&gt;bmi&lt;/code&gt;. After removing outliers the final dataset had &lt;strong&gt;5,171 clean rows&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Map coded values to labels
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;smoking&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;smoking&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Yes&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;No&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&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;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nan&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="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;gender&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;gender&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Male&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Female&lt;/span&gt;&lt;span class="sh"&gt;'&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="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;education&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;education&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Less than 9th grade&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;9th to 12th grade&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;High school graduate&lt;/span&gt;&lt;span class="sh"&gt;'&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="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Some college&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;College graduate&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;      &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Others&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;p&gt;Note: codes &lt;code&gt;7&lt;/code&gt; and &lt;code&gt;9&lt;/code&gt; in the smoking column mean "Refused" and "Don't know" — I converted these to &lt;code&gt;NaN&lt;/code&gt; rather than treating them as valid answers.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 3 — Distribution Analysis
&lt;/h2&gt;

&lt;p&gt;Before looking at relationships between variables, I first looked at each variable individually using histograms and boxplots.&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;fig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;axes&lt;/span&gt; &lt;span class="o"&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;subplots&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;figsize&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;8&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;sns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;histplot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&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;x&lt;/span&gt;&lt;span class="o"&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="n"&gt;kde&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;bins&lt;/span&gt;&lt;span class="o"&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;ax&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;axes&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;skyblue&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;sns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;histplot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&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;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;weight&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kde&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;bins&lt;/span&gt;&lt;span class="o"&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;ax&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;axes&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;lime&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;sns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;histplot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&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;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;height&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kde&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;bins&lt;/span&gt;&lt;span class="o"&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;ax&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;axes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&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="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;red&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;sns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;histplot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&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;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;bmi&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;    &lt;span class="n"&gt;kde&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;bins&lt;/span&gt;&lt;span class="o"&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;ax&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;axes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&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;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;orange&lt;/span&gt;&lt;span class="sh"&gt;'&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;tight_layout&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;&lt;strong&gt;What I found:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;age&lt;/code&gt; is fairly uniform — the survey was designed to cover all adult age groups&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bmi&lt;/code&gt; and &lt;code&gt;weight&lt;/code&gt; are right-skewed — a few very high values pull the mean above the median&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;height&lt;/code&gt; is roughly normally distributed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The boxplots before and after outlier removal made it easy to confirm the cleaning worked — the extreme dots beyond the whiskers were gone after applying IQR.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 4 — Correlation Analysis
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;numerical&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;select_dtypes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;include&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;number&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;corr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numerical&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;corr&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;figure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;figsize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;sns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;heatmap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;corr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;annot&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;cmap&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;coolwarm&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;.2f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;linewidths&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.5&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;title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Correlation Matrix of Numerical Variables&lt;/span&gt;&lt;span class="sh"&gt;'&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;&lt;strong&gt;Key findings from the heatmap:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;weight&lt;/code&gt; and &lt;code&gt;bmi&lt;/code&gt; have a very strong positive correlation — expected, since BMI is calculated from weight&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;age&lt;/code&gt; and &lt;code&gt;bmi&lt;/code&gt; have a weak positive correlation — BMI tends to increase slightly with age&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;height&lt;/code&gt; and &lt;code&gt;weight&lt;/code&gt; show a moderate positive correlation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I also ran pairplots split by gender and by smoking status to see if patterns differed across groups.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 5 — Group Comparisons
&lt;/h2&gt;

&lt;p&gt;I binned the continuous &lt;code&gt;age&lt;/code&gt; column into decade bands for group analysis:&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;data&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="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;cut&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="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="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;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;70&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then looked at smoking proportions and BMI by age band and gender:&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;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;groupby&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;gender&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;&lt;span class="nf"&gt;agg&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;smoking&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;lambda&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;np&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="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Yes&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;p&gt;Some patterns that emerged:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Smoking rates are highest in the 30–40 age band&lt;/li&gt;
&lt;li&gt;Males smoke at a much higher rate than females across all age groups&lt;/li&gt;
&lt;li&gt;BMI peaks in the 50–60 age band for both genders&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step 6 — Hypothesis Testing
&lt;/h2&gt;

&lt;p&gt;This is where the analysis gets interesting. I defined three hypotheses and ran statistical tests on each one.&lt;/p&gt;




&lt;h3&gt;
  
  
  H01 — Are females aged 40–50 predominantly obese?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;statsmodels.stats.proportion&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;proportions_ztest&lt;/span&gt;

&lt;span class="n"&gt;females_40_50&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&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="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;gender&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Female&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&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="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="nf"&gt;astype&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;(40, 50]&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="n"&gt;obese&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;females_40_50&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;bmi&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;30&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="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;females_40_50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;stat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;proportions_ztest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obese&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;alternative&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;larger&lt;/span&gt;&lt;span class="sh"&gt;'&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="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Obese: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;obese&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; (&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;obese&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;%)&lt;/span&gt;&lt;span class="sh"&gt;'&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="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Z-stat: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;stat&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;, p-value: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&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;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; 224 out of 469 females aged 40–50 had BMI &amp;gt; 30 which is the cutoff according to WHO — that's &lt;strong&gt;47.8%&lt;/strong&gt;. The p-value was greater than 0.05, so we &lt;strong&gt;fail to reject H₀&lt;/strong&gt;. Just under half are obese — close, but not a statistically significant majority.&lt;/p&gt;




&lt;h3&gt;
  
  
  H02 — Do males and females smoke at different rates?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;scipy.stats&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;chi2_contingency&lt;/span&gt;

&lt;span class="n"&gt;smokers_only&lt;/span&gt; &lt;span class="o"&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;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;smoking&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;isin&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Yes&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;No&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])]&lt;/span&gt;
&lt;span class="n"&gt;ct&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;crosstab&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;smokers_only&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;gender&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;smokers_only&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;smoking&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="n"&gt;chi2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dof&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;chi2_contingency&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="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Chi-square: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;chi2&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;, p-value: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&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;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; Male smoking rate was &lt;strong&gt;53.3%&lt;/strong&gt;, female was &lt;strong&gt;31.2%&lt;/strong&gt;. The p-value was well below 0.05 — we &lt;strong&gt;reject H₀&lt;/strong&gt;. The difference in smoking rates between males and females is statistically significant.&lt;/p&gt;




&lt;h3&gt;
  
  
  H03 — Is BMI significantly different between males and females?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;scipy.stats&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ttest_ind&lt;/span&gt;

&lt;span class="n"&gt;male_bmi&lt;/span&gt;   &lt;span class="o"&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;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;gender&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Male&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;bmi&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;dropna&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;female_bmi&lt;/span&gt; &lt;span class="o"&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;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;gender&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Female&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;bmi&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;dropna&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;stat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ttest_ind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;male_bmi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;female_bmi&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="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Male BMI mean: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;male_bmi&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="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&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="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Female BMI mean: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;female_bmi&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="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&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="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;T-stat: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;stat&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;, p-value: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&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;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; Male mean BMI was &lt;strong&gt;28.21&lt;/strong&gt;, female was &lt;strong&gt;29.09&lt;/strong&gt;. The p-value was below 0.05 — we &lt;strong&gt;reject H₀&lt;/strong&gt;. The difference, while small, is statistically significant.&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary of findings
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Hypothesis&lt;/th&gt;
&lt;th&gt;Test used&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Females 40–50 are predominantly obese&lt;/td&gt;
&lt;td&gt;Proportion z-test&lt;/td&gt;
&lt;td&gt;Fail to reject H₀ (47.8%, not a majority)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Smoking rates differ by gender&lt;/td&gt;
&lt;td&gt;Chi-square&lt;/td&gt;
&lt;td&gt;Reject H₀ (53.3% male vs 31.2% female)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BMI differs by gender&lt;/td&gt;
&lt;td&gt;Independent t-test&lt;/td&gt;
&lt;td&gt;Reject H₀ (28.21 male vs 29.09 female)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  What I learned
&lt;/h2&gt;

&lt;p&gt;A few things that stood out doing this project:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Numeric codes will catch you off guard.&lt;/strong&gt; NHANES stores everything as numbers. If you forget to map them, your heatmap will show a correlation between "gender" and "BMI" that is actually just the correlation between the numbers 1 and 2 and BMI values — meaningless.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mean vs median gap is your quickest signal.&lt;/strong&gt; BMI mean was 29.1 but median was 27.8. That 1.3 gap immediately told me there were high-end outliers pulling the average up before I even plotted anything.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Statistical significance ≠ practical significance.&lt;/strong&gt; H03 rejected the null — male and female BMI are statistically different. But the actual difference is less than 1 BMI point. Significant in the mathematical sense, but probably not meaningful in a clinical one.&lt;/p&gt;




&lt;h2&gt;
  
  
  Tools used
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Python 3&lt;/li&gt;
&lt;li&gt;pandas, numpy&lt;/li&gt;
&lt;li&gt;matplotlib, seaborn&lt;/li&gt;
&lt;li&gt;scipy, statsmodels&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;📓 &lt;a href="https://github.com/EricMWaimiri/NHANES-Explolatory-Data-Analysis" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📊 &lt;a href="https://www.kaggle.com/code/lalina/exploratory-data-analysis-project" rel="noopener noreferrer"&gt;Dataset on Kaggle&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Thanks for reading! If you have questions about any of the steps or want to suggest improvements, drop them in the comments.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>data</category>
      <category>datascience</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Why Data People Are Moving Beyond Excel</title>
      <dc:creator>EricMWaimiri</dc:creator>
      <pubDate>Thu, 18 Jun 2026 18:05:00 +0000</pubDate>
      <link>https://dev.to/ericmwaimiri/why-data-people-are-moving-beyond-excel-49n6</link>
      <guid>https://dev.to/ericmwaimiri/why-data-people-are-moving-beyond-excel-49n6</guid>
      <description>&lt;p&gt;You've probably used Microsoft Excel at some point — maybe to track a budget, keep a list, or add up some numbers. It's familiar, it's visual, and it gets the job done. But behind the scenes in banks, hospitals, retail companies, and tech startups, a quiet shift is happening. Data analysts are increasingly reaching for something called pandas — not the animal, but a tool for working with data in Python, one of the world's most popular programming languages.&lt;br&gt;
So, what's the difference, and why does it matter?&lt;/p&gt;

&lt;p&gt;Think of Excel as a giant digital table — rows and columns you can see and click on. Want to add up a column? Click a cell, type a formula, done. It's intuitive because everything is right in front of you.&lt;br&gt;
Excel is brilliant for everyday tasks: personal budgets, small business records, simple reports. Millions of people use it every day, and for good reason.&lt;br&gt;
But Excel has limits. Try opening a file with a million rows and your computer might groan. Share it with three colleagues and you end up with three different versions. Repeat the same cleanup task every week and you're doing it by hand, every single time.&lt;/p&gt;

&lt;p&gt;Pandas (which stands for "Panel Data Analysis") is a tool that lets you work with data by writing instructions rather than clicking buttons. Instead of highlighting a column and pressing delete, you write a simple line like: "remove this column." It sounds intimidating, but the payoff is enormous.&lt;br&gt;
Here's what makes pandas stand out:&lt;br&gt;
It can handle massive amounts of data. Where Excel starts to struggle around a million rows, pandas can work with tens of millions without breaking a sweat. For a business analyzing years of transaction records or a hospital tracking patient data, this is a gamechanger.&lt;br&gt;
You can automate repetitive work. Imagine you clean up a sales report every Monday morning — removing blank rows, fixing date formats, calculating totals. In Excel, you do that manually each time. In pandas, you write those steps once, save them, and run them in seconds next Monday. And the Monday after that.&lt;br&gt;
It reduces human error. Every time a human clicks, drags, or types in Excel, there's a chance of a mistake. With pandas, the instructions are written down and run the same way every time. Auditors love this. Managers love this. Analysts sleep better at night.&lt;br&gt;
It plays well with other tools. Need to pull data from a database, clean it, analyze it, and send a summary to Power BI or a web dashboard? Pandas sits comfortably in the middle of that pipeline. Excel tends to be a destination; pandas is more of a workhorse in a larger system.&lt;/p&gt;

&lt;p&gt;A Simple Example. Say you run a small chain of shops and want to know which branch had the highest sales last quarter, after removing any days the store was closed.&lt;br&gt;
&lt;strong&gt;In Excel:&lt;/strong&gt; you'd filter the data manually, maybe use a SUMIF formula, perhaps copy-paste results into another sheet.&lt;br&gt;
&lt;strong&gt;In pandas:&lt;/strong&gt; you write something like "load the data, remove closed days, group by branch, sum the sales, show me the top result." It runs instantly, and you can reuse the same instructions next quarter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So Should Everyone Switch?&lt;/strong&gt;&lt;br&gt;
Not necessarily. Excel is still the right tool for many jobs — quick calculations, simple reports, sharing a file with someone who doesn't use Python. If you're doing something small and one-off, Excel wins on speed and familiarity.&lt;br&gt;
But if you're dealing with large datasets, repeating the same tasks regularly, or building something that other systems need to plug into — pandas starts to look very attractive.&lt;br&gt;
The good news is they're not enemies. Many professionals use both: Excel for quick checks and sharing with non-technical colleagues, pandas for the heavy lifting behind the scenes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Bottom Line&lt;/strong&gt;&lt;br&gt;
Excel is a window. Pandas is a factory. Both have their place — but if your data work is growing in size, complexity, or frequency, it might be time to look beyond the spreadsheet.&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>microsoft</category>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>Data Analytics with Python as a Beginner</title>
      <dc:creator>EricMWaimiri</dc:creator>
      <pubDate>Wed, 13 May 2026 18:55:39 +0000</pubDate>
      <link>https://dev.to/ericmwaimiri/data-analytics-with-python-as-a-beginner-1hp2</link>
      <guid>https://dev.to/ericmwaimiri/data-analytics-with-python-as-a-beginner-1hp2</guid>
      <description>&lt;p&gt;In today’s digital world, data is everywhere. Every time people shop online, scroll through social media, book a hotel, or use a banking app, they generate data. Companies collect this information to understand customer behavior, improve services, and make smarter business decisions. However, raw data alone is not useful unless it can be analyzed effectively. This is where &lt;strong&gt;Python&lt;/strong&gt; becomes important.&lt;/p&gt;

&lt;p&gt;Python is a high-level programming language created by Guido van Rossum in 1991. It is known for its simple syntax, readability, and flexibility. Unlike some programming languages that require complicated commands, Python reads almost like normal English. Because of this, beginners often find it easier to learn compared to languages such as Java or C++.&lt;/p&gt;

&lt;p&gt;Over the years, Python has become one of the most popular programming languages in the world. It is used in many fields, including web development, artificial intelligence, cybersecurity, automation, and especially &lt;strong&gt;data analytics&lt;/strong&gt;. Many organizations today depend on data analytics to make informed decisions, predict trends, and improve efficiency. Python provides the tools needed to collect, clean, analyze, and visualize data effectively.&lt;/p&gt;

&lt;p&gt;Python is often described as a “Swiss army knife” for data analytics because it can handle many different tasks in one environment. Analysts can use Python to organize messy datasets, calculate statistics, create visual charts, and even build machine learning models that predict future outcomes. Instead of switching between multiple tools, Python allows users to perform all these tasks in one programming language.&lt;/p&gt;

&lt;p&gt;Another reason for Python’s popularity is its large ecosystem of libraries. These libraries are collections of prewritten code that make complex tasks easier. For example, instead of writing hundreds of lines of code to analyze data, a user can simply import a library like Pandas or NumPy and perform advanced operations in just a few commands.&lt;/p&gt;

&lt;p&gt;Personally, one of the most interesting things about Python is how beginner-friendly it feels. When I first encountered Python code, it looked much simpler and cleaner than I expected programming to be. Even basic commands such as:&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="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;Hello, Data Analytics!&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;p&gt;show how readable the language is. This simplicity is one reason why Python has become a gateway into the world of data science and analytics for many beginners.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Python is Popular in Data Analytics
&lt;/h2&gt;

&lt;p&gt;Python has become the preferred language for data analytics because it combines simplicity, power, and flexibility. Both beginners and professionals use it because it makes working with data easier and faster.&lt;/p&gt;

&lt;p&gt;One major reason for Python’s popularity is its beginner-friendly syntax. Many programming languages use complex structures that can confuse new learners. Python, however, focuses on readability. Commands are written in a clean and straightforward way, making it easier to understand what the code is doing. This allows beginners to focus more on solving problems instead of struggling with syntax errors.&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 python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&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;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even someone with little programming knowledge can understand what the code is doing. This simplicity makes Python ideal for students and people transitioning into analytics from non-technical backgrounds.&lt;/p&gt;

&lt;p&gt;Another reason for Python’s success is its huge ecosystem of libraries. Libraries are prebuilt collections of code designed to perform specific tasks. In data analytics, Python libraries save analysts a lot of time because they provide ready-made tools for calculations, visualization, and machine learning. Instead of building everything from scratch, users can rely on tested and optimized libraries.&lt;/p&gt;

&lt;p&gt;Python also has strong community support. Millions of developers around the world contribute tutorials, online forums, videos, and open-source projects. If a beginner encounters a problem, there is a high chance someone else has already solved it online. Websites like Stack Overflow and Kaggle provide useful resources for learners.&lt;/p&gt;

&lt;p&gt;Another advantage is integration. Python works well with databases, cloud platforms, Excel files, APIs, and visualization tools. This flexibility allows analysts to connect Python with real-world business systems. For example, a company can use Python to extract sales data from a database, clean it, visualize trends, and generate reports automatically.&lt;/p&gt;

&lt;p&gt;Python is also widely used in industries such as finance, healthcare, retail, and hospitality. This broad adoption means that learning Python opens many career opportunities. Companies are constantly looking for employees who can analyze data and turn it into useful insights.&lt;/p&gt;

&lt;p&gt;When I first explored Python for data analytics, I noticed how quickly tasks could be automated. Something that would take hours in Excel could often be completed in minutes using Python scripts. That efficiency is one of the reasons why Python continues to dominate the analytics field.&lt;/p&gt;




&lt;h2&gt;
  
  
  Key Python Libraries for Data Analytics
&lt;/h2&gt;

&lt;p&gt;Python’s true power in data analytics comes from its libraries. These libraries provide specialized tools that simplify data-related tasks. Without them, analysts would have to write complex code from scratch. Some libraries focus on calculations, others on visualization, and others on machine learning.&lt;/p&gt;

&lt;p&gt;One of the most important libraries is &lt;strong&gt;NumPy&lt;/strong&gt;. NumPy stands for Numerical Python and is mainly used for numerical computing. It provides support for arrays and matrices, allowing calculations to be performed efficiently. Arrays in NumPy are faster and more memory-efficient than standard Python lists.&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;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="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&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="mi"&gt;5&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="n"&gt;numbers&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code calculates the average of the numbers in the array.&lt;/p&gt;

&lt;p&gt;Another essential library is &lt;strong&gt;Pandas&lt;/strong&gt;. Pandas is widely used for data cleaning and manipulation. It introduces the concept of DataFrames, which are tables similar to Excel spreadsheets. Analysts use Pandas to load datasets, remove duplicates, handle missing values, and organize information.&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;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;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;sales.csv&lt;/span&gt;&lt;span class="sh"&gt;"&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="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;head&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When I first used Pandas, I realized how much easier it was to clean messy Excel sheets. Tasks that normally required many manual steps could be completed with a few lines of code.&lt;/p&gt;

&lt;p&gt;For visualization, analysts often use &lt;strong&gt;Matplotlib&lt;/strong&gt; and &lt;strong&gt;Seaborn&lt;/strong&gt;. These libraries help create graphs and charts that make data easier to understand. Visualization is important because people often understand trends better through visuals than raw numbers.&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;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="n"&gt;sns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;barplot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Department&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Revenue&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;df&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 bar chart showing revenue by department.&lt;/p&gt;

&lt;p&gt;Another popular library is &lt;strong&gt;Scikit-learn&lt;/strong&gt;. This library is mainly used for machine learning and predictive analytics. It provides tools for regression, classification, clustering, and model evaluation. Beginners often use Scikit-learn to build simple predictive models.&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;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;LinearRegression&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, there is &lt;strong&gt;Statsmodels&lt;/strong&gt;, which focuses more on statistical analysis. It is useful for hypothesis testing, regression analysis, and advanced statistical modeling.&lt;/p&gt;

&lt;p&gt;Together, these libraries form a powerful toolkit for data analytics. They allow analysts to move from raw data to meaningful insights efficiently.&lt;/p&gt;




&lt;h2&gt;
  
  
  How Python is Used in Data Analytics
&lt;/h2&gt;

&lt;p&gt;Python is used throughout the entire data analytics process. From cleaning raw data to building predictive models, it provides tools that make each stage easier and more efficient.&lt;/p&gt;

&lt;p&gt;The first stage is &lt;strong&gt;data cleaning&lt;/strong&gt;. Real-world data is often incomplete, inconsistent, or messy. Datasets may contain missing values, duplicates, or incorrect formatting. Before analysis can begin, the data must be cleaned.&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;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;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;sales.csv&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Remove missing values
&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;dropna&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inplace&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="c1"&gt;# Standardize date format
&lt;/span&gt;&lt;span class="n"&gt;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;Date&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&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;to_datetime&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Date&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;p&gt;This code removes missing data and converts dates into a consistent format.&lt;/p&gt;

&lt;p&gt;The next stage is &lt;strong&gt;data analysis&lt;/strong&gt;. Analysts use Python to calculate statistics, identify patterns, and summarize datasets.&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="nf"&gt;print&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;describe&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="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;corr&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;describe()&lt;/code&gt; function generates summary statistics, while &lt;code&gt;corr()&lt;/code&gt; shows relationships between variables.&lt;/p&gt;

&lt;p&gt;Another important area is &lt;strong&gt;data visualization&lt;/strong&gt;. Visualization transforms raw data into graphs and charts that are easier to interpret. Businesses use dashboards and reports to communicate insights clearly.&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="n"&gt;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;Revenue&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;plot&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;Visualization helps decision-makers quickly identify trends and anomalies.&lt;/p&gt;

&lt;p&gt;Python is also heavily used in &lt;strong&gt;predictive analytics&lt;/strong&gt;. Predictive analytics involves using historical data to forecast future outcomes. Companies use predictive models to estimate sales, detect fraud, and predict customer behavior.&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;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;LinearRegression&lt;/span&gt;

&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LinearRegression&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="nf"&gt;fit&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Advertising&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Sales&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;p&gt;This creates a simple regression model that predicts sales based on advertising spending.&lt;/p&gt;

&lt;p&gt;One thing I appreciate about Python is how all these tasks can be done within one environment. Instead of switching between Excel, SQL, and visualization software, Python combines everything into one workflow.&lt;/p&gt;




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

&lt;p&gt;Python is widely used in many industries because data analytics has become essential for decision-making.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;- Finance&lt;/em&gt;&lt;br&gt;
Python is used for fraud detection and risk modeling. Banks analyze transaction data to identify suspicious activities. Machine learning models can detect unusual spending patterns that may indicate fraud.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;- Healthcare&lt;/em&gt;&lt;br&gt;
Python helps analyze patient data and predict diseases. Hospitals use analytics to improve treatment plans and forecast patient admissions. During disease outbreaks, data analytics can help track infection trends and allocate resources effectively.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;- Retail&lt;/em&gt;&lt;br&gt;
Retail companies use Python for customer segmentation and sales forecasting. Businesses analyze shopping patterns to understand customer preferences and improve marketing strategies. Online stores also use recommendation systems powered by Python to suggest products.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;- Hospitality&lt;/em&gt;&lt;br&gt;
Python is used for occupancy forecasting and guest sentiment analysis. Hotels analyze booking trends and customer reviews to improve services and optimize pricing strategies.&lt;/p&gt;

&lt;p&gt;These examples show that Python is not limited to one industry. Its flexibility makes it valuable in almost every field that relies on data.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Beginners Should Learn Python
&lt;/h2&gt;

&lt;p&gt;Python is one of the best programming languages for beginners. Its syntax is simple, readable, and less intimidating compared to many other languages.&lt;/p&gt;

&lt;p&gt;Another reason beginners should learn Python is career demand. Data analytics, data science, and artificial intelligence are among the fastest-growing fields globally. Companies are constantly searching for employees with Python skills.&lt;/p&gt;

&lt;p&gt;Python also teaches transferable skills. Someone who learns Python for analytics can later branch into web development, automation, cybersecurity, or AI. This flexibility makes Python a long-term investment.&lt;/p&gt;

&lt;p&gt;In addition, Python is free and open source. Anyone can download it and start learning without paying for expensive software licenses. The official Python website provides downloads, tutorials, and documentation for beginners.&lt;/p&gt;

&lt;p&gt;For beginners, practicing with small projects is important. Platforms like Kaggle provide free datasets and beginner-friendly projects that help learners apply their skills.&lt;/p&gt;

&lt;p&gt;Learning Python may feel challenging at first, but consistency makes a huge difference. Even small projects, such as analyzing sales data or creating charts, help build confidence over time.&lt;/p&gt;




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

&lt;p&gt;Python has transformed the field of data analytics by making it easier to collect, clean, analyze, and visualize data. Its simplicity, versatility, and powerful libraries have made it the preferred programming language for beginners and professionals alike.&lt;/p&gt;

&lt;p&gt;From finance and healthcare to retail and hospitality, Python is used across industries to uncover insights and support decision-making. Libraries such as Pandas, NumPy, Seaborn, and Scikit-learn provide tools that simplify complex tasks and improve efficiency.&lt;/p&gt;

&lt;p&gt;For beginners, Python offers an excellent starting point because it is easy to learn and supported by a massive global community. Beyond analytics, Python also opens pathways into artificial intelligence, automation, and software development.&lt;/p&gt;

&lt;p&gt;The best way to learn Python is to start small. Working with simple datasets, experimenting with visualizations, and completing beginner projects on platforms like Kaggle can gradually build confidence and skills. Over time, these small steps can lead to deeper knowledge in data science and analytics.&lt;/p&gt;

&lt;p&gt;In a world increasingly driven by data, Python is more than just a programming language — it is a gateway to understanding and solving real-world problems.&lt;/p&gt;

</description>
      <category>analytics</category>
      <category>beginners</category>
      <category>datascience</category>
      <category>python</category>
    </item>
    <item>
      <title>Subqueries vs. CTEs and When to Use Each</title>
      <dc:creator>EricMWaimiri</dc:creator>
      <pubDate>Mon, 20 Apr 2026 08:00:01 +0000</pubDate>
      <link>https://dev.to/ericmwaimiri/a-practical-guide-to-subqueries-and-ctes-in-sql-3574</link>
      <guid>https://dev.to/ericmwaimiri/a-practical-guide-to-subqueries-and-ctes-in-sql-3574</guid>
      <description>&lt;p&gt;SQL offers multiple ways to break down complex problems into manageable steps. Two of the most powerful tools for this are subqueries and Common Table Expressions (CTEs). While they often overlap in functionality, understanding their differences is key to writing efficient, maintainable queries.&lt;/p&gt;

&lt;p&gt;A &lt;em&gt;subquery&lt;/em&gt; is a query nested inside another query. It executes first, and its result feeds into the outer query. Subqueries can appear in &lt;code&gt;SELECT&lt;/code&gt;, &lt;code&gt;FROM&lt;/code&gt;, or &lt;code&gt;WHERE&lt;/code&gt; clauses.&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 sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;employee_id&lt;/span&gt; &lt;span class="k"&gt;IN&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;employee_id&lt;/span&gt;
  &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;salaries&lt;/span&gt;
  &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;50000&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the inner query finds employees with salaries above 50,000, and the outer query retrieves their names.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Subqueries
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scalar subquery&lt;/strong&gt; → returns a single value.
&lt;/li&gt;
&lt;/ul&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="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;SELECT&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;salary&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;salaries&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Row subquery&lt;/strong&gt; → returns one row with multiple columns.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Table subquery&lt;/strong&gt; → returns multiple rows/columns, used in &lt;code&gt;FROM&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Correlated subquery&lt;/strong&gt; → references columns from the outer query and runs repeatedly.
&lt;/li&gt;
&lt;/ul&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;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;first_name&lt;/span&gt;
  &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;
  &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&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;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;salary&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;salaries&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
    &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;department_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;department_id&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  When to Use Subqueries
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Filtering with complex conditions (&lt;code&gt;WHERE IN&lt;/code&gt;, &lt;code&gt;EXISTS&lt;/code&gt;).
&lt;/li&gt;
&lt;li&gt;Returning computed values inline.
&lt;/li&gt;
&lt;li&gt;Quick one‑off queries where readability isn’t critical.
&lt;/li&gt;
&lt;li&gt;Situations where you don’t want to define intermediate steps.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What Is a CTE?
&lt;/h2&gt;

&lt;p&gt;A CTE is a temporary named result set defined with &lt;code&gt;WITH&lt;/code&gt;. It improves readability by breaking queries into logical blocks.&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 sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;high_salary&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;employee_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt;
  &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;salaries&lt;/span&gt;
  &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;50000&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;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;
&lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;high_salary&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;employee_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;employee_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Types and Use Cases of CTEs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Non‑recursive CTEs&lt;/strong&gt; → simplify complex queries, improve readability.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recursive CTEs&lt;/strong&gt; → handle hierarchical data (e.g., org charts, tree structures).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multiple CTEs&lt;/strong&gt; → chain transformations step by step.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use cases:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reporting pipelines.
&lt;/li&gt;
&lt;li&gt;Breaking down multi‑stage logic.
&lt;/li&gt;
&lt;li&gt;Recursive problems like traversing parent‑child relationships.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Subqueries vs CTEs
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Aspect&lt;/th&gt;
&lt;th&gt;Subqueries&lt;/th&gt;
&lt;th&gt;CTEs&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Performance&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Often optimized well, but correlated subqueries can be slow.&lt;/td&gt;
&lt;td&gt;Similar performance; recursive CTEs can be powerful but heavy.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Readability&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Harder to read if deeply nested.&lt;/td&gt;
&lt;td&gt;Much clearer — logic broken into named blocks.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Use Cases&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Quick filters, inline calculations.&lt;/td&gt;
&lt;td&gt;Complex queries, multi‑step transformations, recursive problems.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Portability&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Supported everywhere.&lt;/td&gt;
&lt;td&gt;Supported in most modern RDBMS (PostgreSQL, SQL Server, Oracle, MySQL 8+).&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For better and more readable queries;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use subqueries for simple, inline logic.
&lt;/li&gt;
&lt;li&gt;Use CTEs when queries get complex, recursive, or need to be broken into readable steps.
&lt;/li&gt;
&lt;li&gt;Performance is usually similar, but CTEs win on readability and maintainability. &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>sql</category>
      <category>beginners</category>
    </item>
    <item>
      <title>First Week Reflections on SQL</title>
      <dc:creator>EricMWaimiri</dc:creator>
      <pubDate>Mon, 13 Apr 2026 14:06:35 +0000</pubDate>
      <link>https://dev.to/ericmwaimiri/first-week-reflections-on-sql-1kdn</link>
      <guid>https://dev.to/ericmwaimiri/first-week-reflections-on-sql-1kdn</guid>
      <description>&lt;p&gt;&lt;strong&gt;DDL vs DML&lt;/strong&gt;&lt;br&gt;
In SQL, two families of commands shape how we interact with data: &lt;em&gt;Data Definition Language (DDL)&lt;/em&gt; and &lt;em&gt;Data Manipulation Language (DML)&lt;/em&gt;.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DDL commands (&lt;code&gt;CREATE&lt;/code&gt;, &lt;code&gt;ALTER&lt;/code&gt;, &lt;code&gt;DROP&lt;/code&gt;) are like the architect’s blueprint, they define the structure of the database.
&lt;/li&gt;
&lt;li&gt;DML commands (&lt;code&gt;INSERT&lt;/code&gt;, &lt;code&gt;UPDATE&lt;/code&gt;, &lt;code&gt;DELETE&lt;/code&gt;, &lt;code&gt;SELECT&lt;/code&gt;) are the everyday tools. They let us add, change, or remove the actual records inside those structures. 
Here is how I tackled the first assignment:&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;&lt;code&gt;CREATE&lt;/code&gt;&lt;/em&gt; built the schema &lt;code&gt;nairobi_academy&lt;/code&gt; and three tables (&lt;code&gt;students&lt;/code&gt;, &lt;code&gt;subjects&lt;/code&gt;, &lt;code&gt;exam_results&lt;/code&gt;).
&lt;/li&gt;
&lt;/ul&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%2F5obuw5aky4iunwzhx987.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%2F5obuw5aky4iunwzhx987.png" alt=" " width="517" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;&lt;code&gt;INSERT&lt;/code&gt;&lt;/em&gt; populated each table with 10 rows of realistic data.&lt;/li&gt;
&lt;/ul&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%2Fhp5d66fuqso6z8aesv0f.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%2Fhp5d66fuqso6z8aesv0f.png" alt=" " width="800" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;&lt;code&gt;UPDATE&lt;/code&gt;&lt;/em&gt; corrected mistakes: Esther Akinyi’s city changed from Nakuru to Nairobi, and marks for result_id 5 were fixed from 49 to 59.
&lt;/li&gt;
&lt;/ul&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%2Fwfk5o64n483yqi1r5e1a.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%2Fwfk5o64n483yqi1r5e1a.png" alt=" " width="712" height="144"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;&lt;code&gt;DELETE&lt;/code&gt;&lt;/em&gt; removed the cancelled exam result with result_id 9.
&lt;/li&gt;
&lt;/ul&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%2Fst9jqqynh26mwoi231lb.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%2Fst9jqqynh26mwoi231lb.png" alt=" " width="586" height="76"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Filtering with WHERE&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;WHERE&lt;/code&gt; clause is the gatekeeper of SQL. Without it, every row would be affected — a dangerous mistake!&lt;br&gt;&lt;br&gt;
I used it to:&lt;br&gt;
_- Find students in Form 4 (&lt;code&gt;WHERE class = 'Form 4'&lt;/code&gt;).  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Retrieve exam results with marks &amp;gt;= 70.
&lt;/li&gt;
&lt;li&gt;Combine conditions (&lt;code&gt;WHERE class = 'Form 3' AND city = 'Nairobi'&lt;/code&gt;).
&lt;/li&gt;
&lt;li&gt;Explore operators like:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;BETWEEN&lt;/code&gt; for ranges (marks between 50 and 80).
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;IN&lt;/code&gt; for multiple matches (cities in Nairobi, Mombasa, Kisumu).
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;LIKE&lt;/code&gt; for patterns (names starting with A or E). _ &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;It’s the precision tool that makes queries powerful and safe.&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%2Fz9kkid8uf514q7bqfukj.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%2Fz9kkid8uf514q7bqfukj.png" alt=" " width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CASE WHEN: Transforming Data&lt;/strong&gt;&lt;br&gt;
Raw numbers are useful, but categories tell stories. With &lt;code&gt;CASE WHEN&lt;/code&gt;, I transformed exam marks into performance labels: Distinction, Merit, Pass, or Fail.  &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%2Fdqamvh38x0fr0kjabqob.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%2Fdqamvh38x0fr0kjabqob.png" alt=" " width="703" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also classified students as Senior (Form 3 or 4) or Junior (Form 1 or 2).  &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%2Fhgdrrigeibkjrdu7i4ir.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%2Fhgdrrigeibkjrdu7i4ir.png" alt=" " width="800" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The most challenging part was remembering to always pair &lt;code&gt;UPDATE&lt;/code&gt; and &lt;code&gt;DELETE&lt;/code&gt; with &lt;code&gt;WHERE&lt;/code&gt;. Forgetting it could wipe out entire tables in seconds. The most interesting part was experimenting with &lt;code&gt;CASE WHEN&lt;/code&gt;. It was like giving the database a voice: instead of just numbers, it could tell me who excelled, who struggled, and who was senior or junior.  This week, I realized that the beauty of SQL lies in precision and creativity.&lt;/p&gt;

</description>
      <category>sql</category>
      <category>postgres</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Publish a Power BI Report and Embed It into a Website.</title>
      <dc:creator>EricMWaimiri</dc:creator>
      <pubDate>Tue, 07 Apr 2026 09:20:49 +0000</pubDate>
      <link>https://dev.to/ericmwaimiri/publish-a-power-bi-report-and-embed-it-into-a-website-20pm</link>
      <guid>https://dev.to/ericmwaimiri/publish-a-power-bi-report-and-embed-it-into-a-website-20pm</guid>
      <description>&lt;p&gt;Power BI transforms raw numbers into interactive dashboards that are full of insights. The real magic, however, happens when you share those dashboards with the world. Publishing and embedding a Power BI report lets your audience explore the data directly on your website, turning a static page into a dynamic story.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Create a Workspace&lt;/strong&gt;&lt;br&gt;
Workspaces organize your reports and control who can access them.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Go to Power BI Service; Workspaces; Create Workspace&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Log in to the Power BI Service&lt;/em&gt; &lt;a href="https://app.powerbi.com/user/user-settings/general?experience=power-bi" rel="noopener noreferrer"&gt;app.powerbi.com&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click Workspaces in the left navigation&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Select Create a Workspace and give it a name&lt;/em&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%2Fw1gz9qodhi6qemcia2lb.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%2Fw1gz9qodhi6qemcia2lb.png" alt=" " width="594" height="907"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Upload and Publish Your Report&lt;/strong&gt;&lt;br&gt;
Publishing moves your report from Power BI Desktop to the cloud.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In Power BI Desktop; Home; Publish&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Open your report in Power BI Desktop&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Click Publish on the ribbon&lt;/em&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%2F2v6279izkjgiztjkezb6.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%2F2v6279izkjgiztjkezb6.png" alt=" " width="406" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Choose the workspace you created&lt;/em&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%2Fp2qxibj8j4pqnahxa678.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%2Fp2qxibj8j4pqnahxa678.png" alt=" " width="800" height="635"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Confirm upload&lt;/em&gt;; the report will appear in the Power BI Service&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%2Fydskx0v7k8cvwfly69hh.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%2Fydskx0v7k8cvwfly69hh.png" alt=" " width="800" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Generate the Embed Code&lt;/strong&gt;&lt;br&gt;
The embed code allows you to integrate the report into a website.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Go to Power BI Service; Report (In Workspace); File; Embed Report&lt;/em&gt;&lt;br&gt;
Open your report in the Power BI Service Click File → Embed Report → Website or Portal&lt;br&gt;
&lt;em&gt;Copy the iframe embed code provided&lt;/em&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%2F7sw7qxdp8dl34h7j13j4.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%2F7sw7qxdp8dl34h7j13j4.png" alt=" " width="800" height="483"&gt;&lt;/a&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%2Fljdjai76m999tm6fi6dp.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%2Fljdjai76m999tm6fi6dp.png" alt=" " width="800" height="126"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Embed the Report on Your Website&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Open a text editor&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Write or generate a code&lt;/em&gt; to embed a power BI report on your website&lt;br&gt;
&lt;em&gt;Paste the iframe embed code&lt;/em&gt; where you want the report to appear&lt;br&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%2Fdiyeqgjv3seh1k7mp4tj.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%2Fdiyeqgjv3seh1k7mp4tj.png" alt=" " width="800" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Save and publish your website&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Open the embedded report on your browser&lt;/em&gt; to ensure it loads and is interactive&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%2Fj056672mwlamut4dduoq.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%2Fj056672mwlamut4dduoq.png" alt=" " width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To understand all the technicality, think of it like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Workspaces are the foundation for organizing and securing reports.&lt;/li&gt;
&lt;li&gt;Publishing moves reports from desktop to the cloud.&lt;/li&gt;
&lt;li&gt;Embed codes are the bridge between Power BI and your website.&lt;/li&gt;
&lt;li&gt;Embedded reports remain fully interactive, giving your audience a dynamic data experience.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>powerbi</category>
      <category>analytics</category>
    </item>
  </channel>
</rss>
