<?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: Zaima Sohail</title>
    <description>The latest articles on DEV Community by Zaima Sohail (@zaima_sohail_6c55d2513505).</description>
    <link>https://dev.to/zaima_sohail_6c55d2513505</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%2F4268032%2F6c78bdf5-bfc0-4648-a71b-e8ba3c83b00c.jpg</url>
      <title>DEV Community: Zaima Sohail</title>
      <link>https://dev.to/zaima_sohail_6c55d2513505</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zaima_sohail_6c55d2513505"/>
    <language>en</language>
    <item>
      <title>10 Free Datasets for Beginner ML Projects (with Project Ideas)</title>
      <dc:creator>Zaima Sohail</dc:creator>
      <pubDate>Sun, 22 Nov 2026 11:36:01 +0000</pubDate>
      <link>https://dev.to/zaima_sohail_6c55d2513505/10-free-datasets-for-beginner-ml-projects-with-project-ideas-16na</link>
      <guid>https://dev.to/zaima_sohail_6c55d2513505/10-free-datasets-for-beginner-ml-projects-with-project-ideas-16na</guid>
      <description>&lt;p&gt;&lt;em&gt;The dataset you pick decides whether you’ll finish the project, or quit on day two.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When I started learning ML, I made the classic mistake. I picked a huge, messy dataset because it looked impressive. Then I spent a week just trying to load it, and never got anywhere near the actual machine learning part.&lt;/p&gt;

&lt;p&gt;Here’s what I wish someone had told me earlier: as a beginner, the dataset matters more than the model. A clean, well-documented dataset lets you focus on learning. A messy one turns your project into a data-cleaning job you didn’t sign up for.&lt;/p&gt;

&lt;p&gt;So here are 10 free datasets I’d recommend to anyone starting out. They’re all small enough to run on a normal laptop or free Google Colab. For each one I’ve added a project idea, so you’re not just staring at a CSV wondering what to do next.&lt;/p&gt;

&lt;h3&gt;
  
  
  Quick tip before we start
&lt;/h3&gt;

&lt;p&gt;Most of these are on &lt;a href="https://www.kaggle.com/datasets" rel="noopener noreferrer"&gt;Kaggle&lt;/a&gt; or the &lt;a href="https://archive.ics.uci.edu/" rel="noopener noreferrer"&gt;UCI Machine Learning Repository&lt;/a&gt;. A few even come built into scikit-learn or Keras, so you can load them with one line of code. No downloading, no unzipping, no excuses.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Titanic: the “Hello World” of machine learning
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; Passenger data from the Titanic: age, sex, ticket class, fare, and whether each person survived. The training set has 891 rows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where to get it:&lt;/strong&gt; Kaggle’s “Titanic: Machine Learning from Disaster” competition.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project idea:&lt;/strong&gt; Predict who survived. It sounds basic, but it teaches you almost everything: handling missing values (lots of missing ages), encoding categories, feature engineering (pulling titles like “Mr” or “Mrs” out of names), and comparing models like logistic regression and random forest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why I like it:&lt;/strong&gt; Thousands of people have solved it, so when you get stuck, the answer is one search away. Use that, but try on your own first.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Palmer Penguins: the friendlier Iris
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; Measurements of 344 penguins from three species: bill length, bill depth, flipper length, body mass, island and sex.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where to get it:&lt;/strong&gt; Kaggle, or sns.load_dataset("penguins") in seaborn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project idea:&lt;/strong&gt; Classify penguin species from body measurements, then build some nice visualizations to show &lt;em&gt;why&lt;/em&gt; the species are separable. Great first project for practicing EDA.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why I like it:&lt;/strong&gt; Iris is so overused that it doesn’t teach much anymore. Penguins has a few missing values and mixed data types, which makes it feel more like real data while still staying small.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. California Housing: your first regression problem
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; Census data for 20,640 districts in California, with features like median income, house age and location, plus the median house value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where to get it:&lt;/strong&gt; Built into scikit-learn with fetch_california_housing().&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project idea:&lt;/strong&gt; Predict house prices. Start with linear regression, then try gradient boosting and compare. Bonus: plot the predictions on a map using latitude and longitude. Seeing your errors cluster around the coast tells you a lot.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why I like it:&lt;/strong&gt; It teaches you that not every problem is classification, and that metrics like MAE and RMSE actually mean something in real-world units.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Mall Customer Segmentation: try unsupervised learning
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; 200 mall customers with gender, age, annual income and a “spending score.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where to get it:&lt;/strong&gt; Kaggle (search “Mall Customer Segmentation Data”).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project idea:&lt;/strong&gt; Use K-Means clustering to group customers into segments, then give each segment a name like “high income, low spending” and suggest a marketing strategy for each.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why I like it:&lt;/strong&gt; Most beginners only do supervised learning. This one forces you to think about problems with no labels, and to explain your results in plain business language, which is a skill interviewers love.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Heart Disease (UCI): a meaningful classification problem
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; Patient data like age, cholesterol, blood pressure and chest pain type, with a label for whether heart disease is present. The commonly used Cleveland subset has 303 patients.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where to get it:&lt;/strong&gt; UCI Machine Learning Repository or Kaggle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project idea:&lt;/strong&gt; Build a classifier that predicts heart disease risk, then use SHAP to explain &lt;em&gt;which&lt;/em&gt; features drive each prediction. Explainability turns a basic project into a much stronger portfolio piece.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why I like it:&lt;/strong&gt; Healthcare data makes you think about things accuracy alone doesn’t cover. Is a false negative worse than a false positive here? (Yes, much worse.) That question is where recall and precision finally start to make sense.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Fashion-MNIST: your first image classifier
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; 70,000 small grayscale images (28×28 pixels) of clothing items across 10 classes: T-shirts, trousers, sneakers, bags and so on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where to get it:&lt;/strong&gt; Built into Keras with tf.keras.datasets.fashion_mnist, and also in torchvision.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project idea:&lt;/strong&gt; Train a simple neural network first, then a small CNN, and compare. Then look at the confusion matrix. You’ll notice the model mixes up shirts, T-shirts and pullovers, which is honestly fair, because I would too.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why I like it:&lt;/strong&gt; It’s a drop-in replacement for classic MNIST digits, but harder, so you actually see a difference between a basic model and a CNN. It trains in minutes, even on a CPU.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. CIFAR-10: when you’re ready for color images
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; 60,000 color images (32×32 pixels) in 10 classes, like airplanes, cats, dogs, ships and trucks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where to get it:&lt;/strong&gt; Built into Keras and torchvision.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project idea:&lt;/strong&gt; Build a CNN, then improve it step by step with data augmentation, dropout and batch normalization. Track how each change moves your accuracy. For an extra step, fine-tune a small pretrained model, or try a tiny Vision Transformer and see how it compares.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why I like it:&lt;/strong&gt; It’s the point where you first feel overfitting happen. Your training accuracy goes up while validation accuracy stalls, and suddenly regularization isn’t just a word from a lecture anymore. Use Colab’s free GPU for this one.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. IMDB Movie Reviews: sentiment analysis
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; 50,000 movie reviews, each labeled positive or negative, split evenly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where to get it:&lt;/strong&gt; Kaggle (“IMDB Dataset of 50K Movie Reviews”), Keras, or the Hugging Face datasets library.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project idea:&lt;/strong&gt; Start with TF-IDF and logistic regression as a baseline. Then try an LSTM, and finally fine-tune a small transformer like DistilBERT. Seeing how far each approach gets you is a great lesson in why NLP moved to transformers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why I like it:&lt;/strong&gt; A simple baseline already does surprisingly well here. That teaches an important lesson: always build the simple model first before jumping to deep learning.&lt;/p&gt;

&lt;h3&gt;
  
  
  9. SMS Spam Collection: small, quick, and practical
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; 5,574 real SMS messages labeled as “spam” or “ham” (not spam).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where to get it:&lt;/strong&gt; UCI Machine Learning Repository or Kaggle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project idea:&lt;/strong&gt; Build a spam detector with Naive Bayes, then wrap it in a small Streamlit app where you paste a message and it tells you if it’s spam. Small project, but you end up with something people can actually use.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why I like it:&lt;/strong&gt; The data is imbalanced, with far more normal messages than spam. So accuracy can look great while your model misses half the spam. It’s the perfect dataset for learning why F1-score exists.&lt;/p&gt;

&lt;h3&gt;
  
  
  10. Airline Passengers: your first time series
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; Monthly totals of international airline passengers from 1949 to 1960. Only 144 rows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where to get it:&lt;/strong&gt; Kaggle (search “Air Passengers”), or many time-series tutorials host it directly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project idea:&lt;/strong&gt; Forecast the next 12 months. Try a seasonal naive baseline, then ARIMA/SARIMA, then Facebook Prophet or a small LSTM. Plot all of them against the actual values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why I like it:&lt;/strong&gt; It has a clear trend and clear yearly seasonality, so you can actually &lt;em&gt;see&lt;/em&gt; what each model is learning. Time series is a whole different way of thinking: no random train-test split, ever. This dataset teaches that before you move on to messy real-world data like stock prices.&lt;/p&gt;

&lt;h3&gt;
  
  
  So which one should you start with?
&lt;/h3&gt;

&lt;p&gt;If you’re completely new, here’s the order I’d follow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Titanic or Penguins&lt;/strong&gt; to learn the full workflow: load, clean, explore, train, evaluate&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;California Housing&lt;/strong&gt; to see how regression is different&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mall Customers&lt;/strong&gt; for a taste of unsupervised learning&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SMS Spam or Heart Disease&lt;/strong&gt; to understand imbalanced data and better metrics&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fashion-MNIST, then CIFAR-10&lt;/strong&gt; when you’re ready for deep learning&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IMDB&lt;/strong&gt; for NLP, and &lt;strong&gt;Airline Passengers&lt;/strong&gt; for time series&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You don’t need to do all ten. Pick two or three that match the kind of job you want, and go deep on them instead.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to make these stand out on your CV
&lt;/h3&gt;

&lt;p&gt;Here’s the honest truth: recruiters have seen a thousand Titanic notebooks. The dataset alone won’t impress anyone. What makes your project different is what you do &lt;em&gt;around&lt;/em&gt; it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Explain your decisions.&lt;/strong&gt; Why did you fill missing ages with the median instead of dropping them? Write it down.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compare at least two models&lt;/strong&gt; , and say why one won.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deploy it.&lt;/strong&gt; A live Streamlit or Gradio demo beats a notebook every time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write a clean README&lt;/strong&gt; with the problem, approach, results and a screenshot.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add something extra&lt;/strong&gt; , like explainability with SHAP, a small dashboard, or a comparison with a published result.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A simple dataset with a thoughtful write-up and a live demo will always beat a complex dataset with a messy notebook.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final thoughts
&lt;/h3&gt;

&lt;p&gt;I used to think I needed a “unique” dataset to build a good project. I didn’t. What I needed was to finish projects, and these datasets make finishing possible.&lt;/p&gt;

&lt;p&gt;So pick one tonight, open Colab, and write your first df.head(). Everything else starts from there.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Which dataset did you start with? Or is there a beginner-friendly one I missed? Let me know in the comments.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mlproject</category>
      <category>pythonprojectideas</category>
      <category>dataset</category>
      <category>freedataset</category>
    </item>
    <item>
      <title>7 Free Tools I Use to Deploy ML Apps (with No Budget)</title>
      <dc:creator>Zaima Sohail</dc:creator>
      <pubDate>Fri, 20 Nov 2026 11:21:01 +0000</pubDate>
      <link>https://dev.to/zaima_sohail_6c55d2513505/7-free-tools-i-use-to-deploy-ml-apps-with-no-budget-1j77</link>
      <guid>https://dev.to/zaima_sohail_6c55d2513505/7-free-tools-i-use-to-deploy-ml-apps-with-no-budget-1j77</guid>
      <description>&lt;p&gt;&lt;em&gt;Training the model was the easy part. Getting it online without a credit card was the real problem.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let me be honest about something. For a long time my ML projects lived in Jupyter notebooks. They had good accuracy and nice confusion matrices, and nobody could use them. When a recruiter asked “Can I see it running?”, all I could send was a GitHub link and an apology.&lt;/p&gt;

&lt;p&gt;I’m a grad student. I don’t have an AWS budget, and I don’t want a surprise bill because I left a GPU instance running over the weekend. So over the past year I’ve put together a stack of free tools that gets my projects out of notebooks and onto real URLs.&lt;/p&gt;

&lt;p&gt;None of this is sponsored. It’s just what works for me, along with the catches I found the hard way.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Google Colab: where the training happens
&lt;/h3&gt;

&lt;p&gt;My laptop is not a training machine. Colab gives me a free GPU in the browser, and for the small-to-medium models I build for portfolio projects, that’s usually enough.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How I use it:&lt;/strong&gt; I train in Colab, save the model weights to Google Drive, and export them so they’re ready for deployment. I never deploy from Colab. It’s a workshop, not a storefront.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The catch:&lt;/strong&gt; Sessions disconnect, and the free GPU isn’t guaranteed. Save checkpoints often. I learned this after losing two hours of training to a browser tab that went idle.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. GitHub (and GitHub Actions): the backbone
&lt;/h3&gt;

&lt;p&gt;Everything starts here. Almost every free deployment platform connects to GitHub, so a clean repo is the most useful thing you can have.&lt;/p&gt;

&lt;p&gt;On top of that, GitHub Actions is free for public repositories. I use it for simple things: running my tests on every push and checking that requirements.txt actually installs. These sound boring until a broken dependency takes down your live demo the night before an interview.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My tip:&lt;/strong&gt; Pin your package versions. “It works on my machine” becomes “it doesn’t work anywhere” the moment a library releases a new major version.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Streamlit Community Cloud: my default for demos
&lt;/h3&gt;

&lt;p&gt;If you can write Python, you can build a Streamlit app. Then you connect your GitHub repo, click deploy, and you have a public URL. It’s the fastest path I know from model to shareable demo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The catch:&lt;/strong&gt; It comes with hard limits: roughly 1 GB of memory, apps that sleep after 12 hours without traffic, unlimited public apps but only one private app, and no custom domains. That 1 GB memory limit is the one that will bite you. Loading a large transformer model is a quick way to see the “Oh no” error screen.&lt;/p&gt;

&lt;p&gt;Also, Streamlit only offers free resource increases to nonprofits and educational organizations, case by case, so don’t plan around getting one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best for:&lt;/strong&gt; Dashboards, forecasting apps, tabular ML, and anything where the model is small.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Gradio: the fastest UI for a model
&lt;/h3&gt;

&lt;p&gt;Gradio is a Python library, not a hosting platform, but it belongs on this list because it saves so much time. A few lines of code give you an input box, an output panel, and a working interface for an image classifier or a text model.&lt;/p&gt;

&lt;p&gt;I use Gradio when the demo is “give it an input, see the prediction,” and Streamlit when I need a full dashboard with charts and filters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A note on hosting Gradio apps:&lt;/strong&gt; Hugging Face Spaces used to be the obvious free home for Gradio apps, but that changed this year. More on that in the next section.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Hugging Face Hub: where my models live
&lt;/h3&gt;

&lt;p&gt;I keep my trained model files on the Hugging Face Hub instead of committing them to GitHub, which hates large files. My app then downloads the model at startup. This keeps the repo light, and the model gets a proper page with a model card.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The 2026 catch with Spaces:&lt;/strong&gt; Hugging Face’s own docs now say that while CPU Basic hardware has no hourly cost, creating a Space that runs on compute (Gradio or Docker) requires a paid plan. Only Static Spaces are free for everyone. Many developers on the forums were surprised by this, since the restriction arrived around mid-2026 without much announcement.&lt;/p&gt;

&lt;p&gt;So for me, the Hub is now mainly for &lt;strong&gt;storing and versioning models&lt;/strong&gt; (still great and free), not running apps. If you have an older tutorial telling you to “just deploy on Spaces for free,” check the current rules first.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Render: when I need a real API
&lt;/h3&gt;

&lt;p&gt;Sometimes a demo page isn’t enough and I need an actual REST endpoint, usually a FastAPI app that accepts JSON and returns predictions. That’s what I use Render for.&lt;/p&gt;

&lt;p&gt;You connect your GitHub repo, set the start command (uvicorn main:app --host 0.0.0.0 --port $PORT), and you get a live API with HTTPS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The catch:&lt;/strong&gt; Free web services spin down after 15 minutes without traffic and take about a minute to wake up on the next request. Each workspace gets 750 free instance hours a month. Free instances are small too (512 MB RAM, 0.1 CPU), and if you add their free Postgres database, it expires 30 days after creation.&lt;/p&gt;

&lt;p&gt;In practice, the first person to open my API after a quiet period waits about a minute. For a portfolio project, I’m fine with that. I just add a line in my README saying “first load may take ~60 seconds,” so recruiters don’t think it’s broken.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. ONNX Runtime: the tool that makes everything else fit
&lt;/h3&gt;

&lt;p&gt;This one surprised me. It’s not a hosting platform, but it’s probably the reason most of my apps survive on free tiers at all.&lt;/p&gt;

&lt;p&gt;Free platforms give you very little memory, and a full PyTorch install is large. Exporting my model to ONNX format and running it with onnxruntime instead of the full framework makes my deployments much lighter and starts the apps faster. Add dynamic quantization, and models that crashed on Streamlit's memory limit suddenly run fine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My rule now:&lt;/strong&gt; Before deploying anything, I ask whether I can make the model smaller. Usually the answer is yes.&lt;/p&gt;

&lt;h3&gt;
  
  
  My actual workflow, start to finish
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Train&lt;/strong&gt; in Colab, save checkpoints to Drive&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shrink&lt;/strong&gt; the model with ONNX export and quantization&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Upload&lt;/strong&gt; the model to the Hugging Face Hub&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Push&lt;/strong&gt; the app code to GitHub, with Actions running basic checks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deploy&lt;/strong&gt; the UI on Streamlit Community Cloud, or the API on Render&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Put the live link&lt;/strong&gt; at the top of the README and on my CV&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Total cost: zero.&lt;/p&gt;

&lt;h3&gt;
  
  
  A few honest lessons
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Free tiers change, sometimes without warning.&lt;/strong&gt; The Hugging Face change this year is proof. Don’t build your whole portfolio on one platform. Keep your code portable, ideally with a Dockerfile in the repo, so you can move if you need to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cold starts are fine for a portfolio.&lt;/strong&gt; Just tell people about them. A one-minute wait with a warning is better than a dead link.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A live demo beats a perfect notebook.&lt;/strong&gt; A slightly rough app that someone can actually click on says more about you than a 98%-accuracy notebook nobody can run.&lt;/p&gt;

&lt;p&gt;If you’re a student or early-career developer sitting on a folder of notebooks, pick your best project and deploy it this weekend. Free tools are enough to get it online.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you have a free tool I missed, leave it in the comments. I’m always looking to add to my stack.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>aitools</category>
      <category>machinelearningai</category>
      <category>free</category>
      <category>generativeaitools</category>
    </item>
    <item>
      <title>From Electrical Engineering to AI Engineer: My Roadmap</title>
      <dc:creator>Zaima Sohail</dc:creator>
      <pubDate>Wed, 18 Nov 2026 09:56:28 +0000</pubDate>
      <link>https://dev.to/zaima_sohail_6c55d2513505/from-electrical-engineering-to-ai-engineer-my-roadmap-1fbm</link>
      <guid>https://dev.to/zaima_sohail_6c55d2513505/from-electrical-engineering-to-ai-engineer-my-roadmap-1fbm</guid>
      <description>&lt;p&gt;&lt;em&gt;How I went from circuits and microprocessors to machine learning, LLMs and RAG, and the path I’d follow if I started again.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A few years ago, if someone had told me I’d be building RAG pipelines and working with large language models, I wouldn’t have believed them. I was an Electrical Engineering student. My days were circuit diagrams, signals, control systems and far too many MATLAB assignments, and AI wasn’t really on my radar as a career.&lt;/p&gt;

&lt;p&gt;Today I write Python for a living, I’m doing my MS in Data Science, and most of my free time goes into building AI projects. I don’t have a CS degree. What I had was curiosity and a lot of trial and error.&lt;/p&gt;

&lt;p&gt;This post is about how that happened: the projects that pushed me, the mistakes I made, and the roadmap I’d follow if I were starting from scratch today. If you’re coming from EE or any other non-CS field and wondering whether you can make the switch, I hope it helps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Starting with Electrical Engineering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I did my bachelor’s in Electrical Engineering at UET Lahore from 2021 to 2025. Most of it was what you’d expect: electric circuits, electronics, digital systems, signals and systems, microprocessors, control systems, power and computer architecture. But looking back, there was more computing in there than I gave it credit for. My very first semester had a course called Introduction to Computing and Data Science. Later came Programming Fundamentals, Data Structures and Algorithms, Discrete Mathematics, Digital Signal Processing and Computer Networks, and in my last two years I took Introduction to Machine Learning and Deep Learning as part of the degree.&lt;/p&gt;

&lt;p&gt;At the time I didn’t see any of this as an AI path. They were just courses to get through. But they gave me two things I use every day. The first is the maths: linear algebra, multivariable calculus, probability, and the convolution from signals and DSP were already familiar when I met them again in machine learning. The second is a habit of breaking a messy problem into smaller parts and continuing to experiment when things don’t work. That habit is very useful when a model refuses to train properly at 2 a.m.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The project that changed my direction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For my final-year project I built a Vision Transformer accelerator using RISC-V. The idea was to design hardware that speeds up the attention computations inside a Vision Transformer, written in Verilog with fixed-point arithmetic and connected to a RISC-V processor.&lt;/p&gt;

&lt;p&gt;To build hardware for attention, I had to understand attention properly: every matrix multiplication, every intermediate value, where each number comes from and where it goes. You can’t hide behind a library call when you’re the one designing the circuit that does the work.&lt;/p&gt;

&lt;p&gt;Somewhere in that project I realised I was more interested in the model than the hardware. Hardware and AI turned out to be much closer than I’d assumed, and I started wondering what it would be like to work on the software side of AI full time. That’s really where my transition started.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting serious about Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;My degree gave me a start with programming. Programming Fundamentals went well enough that I later worked as a TA for it, and Data Structures and Algorithms showed me how much I still had to learn. But Python was where things really opened up. I went through the basics again properly: functions, data structures, OOP, file and exception handling, and working with libraries and APIs. Then NumPy, Pandas and Matplotlib.&lt;/p&gt;

&lt;p&gt;It was slow at first. I’d lose an hour to a bug that turned out to be one wrong index. But at some point I stopped writing code just to finish assignments and started using it to analyse data and automate boring tasks, and that’s when it became fun.&lt;/p&gt;

&lt;p&gt;You don’t need to know every corner of Python before moving into AI. You do need to be able to write code on your own, read error messages, and understand roughly what your libraries are doing. Copying code is easy. Knowing why it works is the part that actually matters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learning machine learning the slow way&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;My first proper introduction to machine learning was a course in the third year of my degree, and honestly it was overwhelming. Supervised, unsupervised, overfitting, feature engineering, hyperparameters, all at once, and one semester isn’t much time to take it all in. Every tutorial I found afterwards made it look easier than it was.&lt;/p&gt;

&lt;p&gt;So I went slowly. I revisited linear algebra, probability and statistics (my EE background helped a lot here), then learned the classical algorithms in scikit-learn: linear and logistic regression, decision trees, random forests, SVMs and KNN. The biggest jump came when I started using real datasets, with missing values, noise, and models that looked great in training and fell apart on test data.&lt;/p&gt;

&lt;p&gt;My early projects were things like MNIST digit recognition, time-series forecasting, forecasting on PSX stock data, and a water quality assessment project with explainable ML. None of them were perfect, but each one taught me something no tutorial had. Mainly, that machine learning is not about calling .fit(). Most of the work is understanding the data, evaluating properly and figuring out why the model is doing what it’s doing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deep learning and PyTorch&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I took Deep Learning in my final semester, alongside my final-year project, and kept going on my own after that: CNNs, RNNs, LSTMs and transformers, mostly in PyTorch. Tensor shapes confused me for a long time. One wrong dimension and the whole thing breaks, usually with an error message longer than the code. It got better with practice, and my final-year project helped because I already knew how attention worked underneath.&lt;/p&gt;

&lt;p&gt;One project from this stage that I’m happy with is my AI Health Assistant. You enter your symptoms and it predicts a likely disease, along with the type of doctor to see and a risk level, using a hybrid CNN and Vision Transformer model. The code is on &lt;a href="https://github.com/zaima-20/ai-health-assistant" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discovering LLMs and RAG&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Natural language processing pulled me in next, and that led to large language models. What surprised me was how different building with LLMs is from training a classifier. I had to learn prompting, embeddings, vector databases, retrieval with FAISS and BM25, LangChain, and later agentic and multi-agent setups.&lt;/p&gt;

&lt;p&gt;Retrieval-Augmented Generation caught my attention most. Instead of relying only on what the model learned in training, you retrieve relevant documents first and let the model answer from them. Think of a chatbot that answers from your university’s course material instead of guessing from general knowledge.&lt;/p&gt;

&lt;p&gt;It sounds simple, but it raises hard questions very quickly. How do you make sure you retrieve the right chunks? What happens when retrieval returns something irrelevant? How do you reduce hallucinations, and how do you even measure whether the system is good? That’s when I understood that an AI application is a lot more than an API call.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What my Odoo job taught me&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Alongside all this, I work as a Python and Odoo developer at ESSL Lab, KICS, UET Lahore. It might look unrelated to AI, but it has made me a much more practical developer.&lt;/p&gt;

&lt;p&gt;I work with Python, PostgreSQL, business logic, access controls and reports on a system that real people use every day. When something breaks, someone notices. A small change in one place can cause a problem somewhere else, and “it works on my machine” doesn’t count as done.&lt;/p&gt;

&lt;p&gt;That’s the part of AI engineering a lot of courses skip. A good model is only one piece. You also have to integrate it into an application, handle errors, deal with messy data and keep the code maintainable. My AI Resume Analyzer is where I tried to put this into practice. It parses a CV, scores it against a job description using an LLM, and points out missing keywords and problems. It has user login and it’s live on Streamlit Community Cloud (&lt;a href="https://github.com/zaima-20/ai-resume-analyzer" rel="noopener noreferrer"&gt;code on GitHub&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why I did an MS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Self-learning helped me figure out what I liked, but I wanted a stronger theoretical base and a proper introduction to research, so I started an MS in Data Science at UET Lahore.&lt;/p&gt;

&lt;p&gt;The biggest change in how I think has been around evaluation. It’s easy to say a model performs well and much harder to show it. Is the comparison fair? Are these the right metrics? Does the new approach actually beat the baseline, or does it just sound more impressive? With LLMs this matters even more, because an answer can sound completely convincing and still be wrong.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The roadmap I’d follow if I started again&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you’re coming from EE, mechanical, physics, maths or any other non-CS background, this is roughly the path I’d suggest. The timelines are rough and depend on how much time you have.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 1: Python (4–6 weeks)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Fundamentals, OOP and file handling, then NumPy, Pandas and plotting. Build a small data analysis or Excel automation project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 2: Machine learning (6–8 weeks)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Supervised and unsupervised learning, feature engineering, evaluation metrics and scikit-learn. Build a classification or regression project on a real, messy dataset.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 3: Deep learning (6–8 weeks)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Neural networks, backpropagation, CNNs, transformers and PyTorch. Build an image or text classifier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 4: LLM applications (6–8 weeks)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Embeddings, prompting, vector databases, RAG, model APIs and LangChain. Build a chatbot that answers questions from your own documents and shows its sources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 5: Complete applications (ongoing)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;FastAPI, SQL, Git, testing, Docker, deployment and basic cloud. Build something end to end that another person can actually use.&lt;/p&gt;

&lt;p&gt;Whatever phase you’re in, spend less time watching tutorials and more time building. You learn the most when your own project breaks and you have to fix it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mistakes I made&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trying to learn everything at once.&lt;/strong&gt; At one point I wanted ML, deep learning, NLP, computer vision and LLMs all together. I ended up knowing a little about everything and not enough to build anything complete. Picking one area and going deep worked much better.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Too many tutorials.&lt;/strong&gt; Watching someone build a project feels like learning. Then you open a blank editor and realise you can’t do it yourself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comparing myself with CS graduates.&lt;/strong&gt; They often have stronger foundations in algorithms, databases and software engineering, and for a while that bothered me. But my background gave me strengths too, in maths, hardware and thinking about whole systems. Different paths give you different advantages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thinking a working notebook means a finished project.&lt;/strong&gt; A notebook is a starting point. A real application also needs data validation, an API, error handling, security, a usable interface and evaluation. I’m still learning this one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What’s next&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I don’t think of my transition as finished. Right now I’m focusing on production-ready LLM and RAG applications, agentic AI, evaluation and benchmarking, deployment, and backend engineering for AI systems. I’d rather build things that solve a real problem than chase whatever is trending this month.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you’re thinking about switching&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;My path wasn’t planned. There were confusing concepts, failed experiments and plenty of days when I wondered if I was learning fast enough. There were also good moments: the first model that gave sensible predictions, the first project I built without a tutorial, the first research paper I actually understood.&lt;/p&gt;

&lt;p&gt;If you’re moving into AI from another field, start with what you already know, fill in the gaps one at a time, and build projects that are slightly too hard for you. You don’t need to feel ready first. I didn’t, and I still don’t, but I’m building anyway.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading. I write about what I’m learning in AI, LLMs, RAG and Python while building real projects. If you’ve moved into AI from another field, I’d love to hear what the hardest part was for you.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Connect with me on&lt;/em&gt; &lt;a href="https://www.linkedin.com/in/zaima-sohail-354268255/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; &lt;em&gt;and&lt;/em&gt; &lt;a href="https://github.com/zaima-20" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>electricalengineerin</category>
      <category>aiengineer</category>
      <category>aideveloper</category>
    </item>
    <item>
      <title>Is RAG Dead? Long Context vs Retrieval in Real Projects</title>
      <dc:creator>Zaima Sohail</dc:creator>
      <pubDate>Fri, 13 Nov 2026 06:54:41 +0000</pubDate>
      <link>https://dev.to/zaima_sohail_6c55d2513505/is-rag-dead-long-context-vs-retrieval-in-real-projects-2d7p</link>
      <guid>https://dev.to/zaima_sohail_6c55d2513505/is-rag-dead-long-context-vs-retrieval-in-real-projects-2d7p</guid>
      <description>&lt;p&gt;Short answer: no. But the RAG most of us learned back in 2023, where you chunk everything, embed it, grab the top five chunks and hope, isn’t the automatic choice it used to be.&lt;/p&gt;

&lt;p&gt;Every few months a model ships with a bigger context window and my feed fills up with “RAG is dead” posts. It happened when Gemini 1.5 Pro hit a million tokens. It happens again every time someone announces two million. And honestly, I get the appeal. No vector database, no chunking strategy to argue about, no reranker. Just paste the whole knowledge base into the prompt and let the model deal with it.&lt;/p&gt;

&lt;p&gt;I’ve been building retrieval pipelines for my own projects, so I wanted to know if I was wasting my time. I went through the recent research (mostly 2025 and 2026), and this post is what I found: where each approach falls apart, what it actually costs, and how I now decide between them.&lt;/p&gt;

&lt;h3&gt;
  
  
  They’re not solving the same problem
&lt;/h3&gt;

&lt;p&gt;I think a lot of the confusion comes from treating long context and RAG as two answers to one question. They aren’t.&lt;/p&gt;

&lt;p&gt;A long context window is about how much the model can hold in its head at once. Basically working memory. RAG is about finding the right material before the model reads anything. That’s search.&lt;/p&gt;

&lt;p&gt;Giving a model a bigger window doesn’t make it better at searching. You’ve just handed it a bigger haystack. Can it still find the needle? And can you afford to hand over that haystack on every single query? Those are the two questions that ended up shaping every design decision I made.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where long context falls apart
&lt;/h3&gt;

&lt;p&gt;The window size on the model card and the amount of context a model can actually use well are two different numbers. Three bits of research keep coming up.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lost in the middle
&lt;/h3&gt;

&lt;p&gt;This one is from 2023, by a Stanford team (&lt;a href="https://arxiv.org/abs/2307.03172" rel="noopener noreferrer"&gt;Liu et al.&lt;/a&gt;, later published in TACL). They found models pay attention to the start and end of a long prompt and tend to skip what’s in the middle. Plot accuracy against position and you get a U shape. The part that surprised me: in some multi-document tests, GPT-3.5-Turbo did worse with the documents than with no documents at all. Models built specifically for long context had the same problem.&lt;/p&gt;

&lt;h3&gt;
  
  
  Context rot
&lt;/h3&gt;

&lt;p&gt;In 2025, Chroma ran a &lt;a href="https://www.trychroma.com/research/context-rot" rel="noopener noreferrer"&gt;study&lt;/a&gt; on 18 frontier models, including GPT-4.1, Claude 4, Gemini 2.5 and Qwen3. All 18 got worse as the input got longer, even on simple tasks. Text that looked relevant but wasn’t made things worse still. So you can see a model with a 200K window start slipping at 50K. You don’t have to fill the window for it to happen.&lt;/p&gt;

&lt;h3&gt;
  
  
  Needle tests make models look better than they are
&lt;/h3&gt;

&lt;p&gt;The classic needle-in-a-haystack test hides one fact in a long document and asks the model to find it. Models score close to 100%, and that’s the number you see in launch posts. NVIDIA’s &lt;a href="https://arxiv.org/abs/2404.06654" rel="noopener noreferrer"&gt;RULER&lt;/a&gt; benchmark made the test harder, with multiple needles, tracing and aggregation, and only about half the models held up at 32K tokens, even though they claimed much more. Real questions look a lot more like RULER than like one planted fact.&lt;/p&gt;

&lt;p&gt;So a bigger window is a limit, not a target. If you fill it up, you’re swapping a retrieval problem you can measure for an attention problem you mostly can’t.&lt;/p&gt;

&lt;h3&gt;
  
  
  The money and the waiting
&lt;/h3&gt;

&lt;p&gt;I’ll be fair to long context here. If you can afford it, it often wins on accuracy. A controlled comparison from June 2026 (&lt;a href="https://arxiv.org/abs/2606.20898" rel="noopener noreferrer"&gt;Hamilton et al.&lt;/a&gt;) had long-context prompting at 73.1% correct, against 65.4% for semantic RAG. The catch is that it cost 26 times more per query.&lt;/p&gt;

&lt;p&gt;That 26x is what stops “just stuff it all in” from working in production. Here are some of the reported numbers in one place:&lt;/p&gt;

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

&lt;p&gt;That last row comes from a vendor’s own benchmark, so take it with some salt. Still, the failure it describes is the one that worries me most. When the model read the PDFs directly, it often made up an answer if the information wasn’t there. The RAG setup just said “not found”. I’d much rather get that.&lt;/p&gt;

&lt;p&gt;Prompt caching does close some of the gap if your documents don’t change much. You pay full price once and reuse the cached part cheaply after that. But any change to the knowledge base breaks the cache, so if your data updates every hour, caching won’t save you much.&lt;/p&gt;

&lt;h3&gt;
  
  
  When long context is the right call
&lt;/h3&gt;

&lt;p&gt;RAG has a real weak spot: questions that need the whole document at once. Chunking chops the reasoning into pieces, and top-k retrieval only brings back the pieces that happen to look like the question. In these cases I’d reach for long context:&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;One document, or a handful.&lt;/strong&gt; Summarising a paper, reviewing a single contract, explaining one module of a codebase. If it fits easily, a retrieval layer just gives you more things that can go wrong.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;The answer is spread across the text.&lt;/strong&gt; Something like “how does the argument shift between chapter 2 and chapter 7?”, or following a contract clause through every amendment. Chunk retrieval can’t see that kind of structure.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Most of the corpus matters for most questions.&lt;/strong&gt; One practitioner &lt;a href="https://tianpan.co/blog/2026-04-09-long-context-vs-rag-production-decision-framework" rel="noopener noreferrer"&gt;puts the tipping point&lt;/a&gt; at roughly 20%. If a typical query needs less than that share of your data, RAG usually wins. Above it, sending everything starts to make sense.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;You’re still prototyping.&lt;/strong&gt; Pasting the documents in is the quickest way to find out what people actually ask, before you spend time building an index.&lt;/p&gt;

&lt;p&gt;To be fair to the other side, a January 2025 paper (&lt;a href="https://arxiv.org/abs/2501.01880" rel="noopener noreferrer"&gt;Li et al.&lt;/a&gt;) found long context generally beat chunk-based RAG on question answering. RAG still did better on dialogue-style and general questions, though, and retrieving summaries instead of raw chunks came out roughly even with long context.&lt;/p&gt;

&lt;h3&gt;
  
  
  How I decide now
&lt;/h3&gt;

&lt;p&gt;These days I skip the big philosophical debate. I just go through a few questions about the data and the queries, and see which way each one points.&lt;/p&gt;

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

&lt;p&gt;If the answers point in different directions, that usually means you want a mix of both. In my experience that’s most projects.&lt;/p&gt;

&lt;p&gt;One more thing I’d pass on: test before you try anything clever. A 2026 study compared ten retrieval strategies on 23,088 financial queries. Plain BM25 keyword search beat state-of-the-art dense retrieval on that data, and tricks like HyDE query expansion barely helped with precise numerical questions (&lt;a href="https://hackernoon.com/long-context-beats-rag-on-accuracyso-why-keep-retrieval" rel="noopener noreferrer"&gt;HackerNoon summary&lt;/a&gt;). An evaluation set built from your own queries will tell you more than any leaderboard.&lt;/p&gt;

&lt;h3&gt;
  
  
  What I actually build: retrieve first, then reason
&lt;/h3&gt;

&lt;p&gt;Most of the setups I’d actually ship use retrieval to pick what goes into the context, and a long-context model to think about it. That way you keep RAG’s precision and low cost, and the model still gets to read whole sections instead of scraps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkl8za1cp3ka891n3sugs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkl8za1cp3ka891n3sugs.png" width="799" height="428"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;hybrid RAG + long-context architecture&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here’s what each piece is for:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Router.&lt;/strong&gt; A cheap classifier, or one small LLM call, works out what kind of question came in. Precise lookups go to search. Questions that need a whole document go straight to the full text.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hybrid search.&lt;/strong&gt; Use BM25 keyword search and dense embeddings together. Keywords catch exact names, codes and numbers, and embeddings catch paraphrases. Each one finds things the other misses.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rerank and order.&lt;/strong&gt; A cross-encoder reranker picks the best few chunks. Then, because of the lost-in-the-middle problem, I put the strongest ones at the start and end of the prompt rather than in the middle.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cached core.&lt;/strong&gt; The small, stable part of the knowledge base (policies, a syllabus, an API spec) can sit in a cached prompt prefix. You pay full price once, and after that it’s cheap.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bigger units.&lt;/strong&gt; When a chunk matches, think about sending its whole section or parent document. Long context makes that affordable, and it fixes the annoying case where the answer was split across two chunks.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  An example
&lt;/h3&gt;

&lt;p&gt;Say you’re building a Q&amp;amp;A assistant for students over a course’s lecture notes, slides and assignment briefs. Plenty of us end up building something like this for a thesis or a portfolio.&lt;/p&gt;

&lt;p&gt;• &lt;em&gt;“When is assignment 3 due?”&lt;/em&gt; is a straight lookup. Hybrid search finds the brief almost instantly. If you sent the whole course instead, it would be slow and expensive, and the model would be more likely to mix up dates between assignments.&lt;/p&gt;

&lt;p&gt;• &lt;em&gt;“How does lecture 6’s explanation of attention build on lecture 2?”&lt;/em&gt; needs two full documents. Pull both lectures in completely and let the long-context model compare them.&lt;/p&gt;

&lt;p&gt;• The syllabus and grading policy are short, rarely change and come up all the time. Keep them cached as a fixed prefix on every query.&lt;/p&gt;

&lt;p&gt;None of these routes handles all three questions well by itself. Put together, they do, and the model only ever sees what that question needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  So, is RAG dead?
&lt;/h3&gt;

&lt;p&gt;No. The naive version might be, but the idea behind it is doing fine. What took its place is probably better called context engineering: for each query, deciding what the model should see and in what order.&lt;/p&gt;

&lt;p&gt;If I had to boil it down: the context window is a limit, not something to fill. Long context can beat RAG on accuracy, but at around 26 times the token cost and with much slower responses, so do that math before you ship. RAG is search and long context is memory, and the systems I trust most use both. Most of the time the real bottleneck is retrieval quality, and a decent hybrid search with a reranker will usually do more for you than a bigger window.&lt;/p&gt;

&lt;p&gt;And please build an evaluation set from your own users’ questions and test both approaches on it. The benchmarks I’ve cited here are only a starting point.&lt;/p&gt;

&lt;p&gt;So the question I ask at the start of a project isn’t “RAG or long context?” anymore. It’s “what’s the smallest, cleanest context that can answer this?” Sometimes that’s the whole document. Usually it isn’t.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;p&gt;• Liu et al., &lt;a href="https://arxiv.org/abs/2307.03172" rel="noopener noreferrer"&gt;Lost in the Middle: How Language Models Use Long Contexts&lt;/a&gt;, TACL 2024&lt;/p&gt;

&lt;p&gt;• Chroma Research, &lt;a href="https://www.trychroma.com/research/context-rot" rel="noopener noreferrer"&gt;Context Rot: How Increasing Input Tokens Impacts LLM Performance&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;• Hsieh et al. (NVIDIA), &lt;a href="https://arxiv.org/abs/2404.06654" rel="noopener noreferrer"&gt;RULER: What’s the Real Context Size of Your Long-Context Language Models?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;• Hamilton et al., &lt;a href="https://arxiv.org/abs/2606.20898" rel="noopener noreferrer"&gt;The Token Tax of Epistemic Accuracy&lt;/a&gt;, June 2026&lt;/p&gt;

&lt;p&gt;• Li et al., &lt;a href="https://arxiv.org/abs/2501.01880" rel="noopener noreferrer"&gt;Long Context vs. RAG for LLMs: An Evaluation and Revisits&lt;/a&gt;, January 2025&lt;/p&gt;

&lt;p&gt;• IntuitionLabs, &lt;a href="https://intuitionlabs.ai/articles/long-context-ai-vs-retrieval-rag" rel="noopener noreferrer"&gt;Long-Context AI vs. RAG for Document Analysis Compared&lt;/a&gt;, September 2026&lt;/p&gt;

&lt;p&gt;• Towards AI, &lt;a href="https://pub.towardsai.net/rag-vs-long-context-in-2026-when-retrieval-still-wins-e6ebad9a4096" rel="noopener noreferrer"&gt;RAG vs. Long Context in 2026: When Retrieval Still Wins&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;• Tian Pan, &lt;a href="https://tianpan.co/blog/2026-04-09-long-context-vs-rag-production-decision-framework" rel="noopener noreferrer"&gt;Long-Context Models vs. RAG: When the 1M-Token Window Is the Wrong Tool&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;• HackerNoon, &lt;a href="https://hackernoon.com/long-context-beats-rag-on-accuracyso-why-keep-retrieval" rel="noopener noreferrer"&gt;Long Context Beats RAG on Accuracy — So Why Keep Retrieval?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;• Algeria Tech News, &lt;a href="https://algeriatech.news/no-stack-stack-long-context-ai-architecture-2026/" rel="noopener noreferrer"&gt;The No-Stack Stack: Long-Context AI Architecture in 2026&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;• Poll the People, &lt;a href="https://pollthepeople.app/is-rag-better-than-a-large-context-window/" rel="noopener noreferrer"&gt;Is RAG Better Than a Large Context Window?&lt;/a&gt; (CustomGPT.ai benchmark)&lt;/p&gt;

</description>
      <category>genai</category>
      <category>machinelearning</category>
      <category>artificialintelligen</category>
      <category>largelanguagemodels</category>
    </item>
    <item>
      <title>Building an AI Resume Analyzer That Matches You to Real Jobs</title>
      <dc:creator>Zaima Sohail</dc:creator>
      <pubDate>Tue, 10 Nov 2026 04:15:53 +0000</pubDate>
      <link>https://dev.to/zaima_sohail_6c55d2513505/building-an-ai-resume-analyzer-that-matches-you-to-real-jobs-432h</link>
      <guid>https://dev.to/zaima_sohail_6c55d2513505/building-an-ai-resume-analyzer-that-matches-you-to-real-jobs-432h</guid>
      <description>&lt;p&gt;&lt;em&gt;What I learned building a full-stack AI app with Gemini, live job APIs and Supabase, and why the AI was the easy part.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When I started applying for machine learning roles, I kept asking the same two questions. Is my resume actually good? And which of the hundreds of job postings out there do I really fit?&lt;/p&gt;

&lt;p&gt;So I built a tool to answer both. You upload your resume, and the app reviews it, points out concrete problems, and searches live job listings from sites like LinkedIn and Glassdoor. Then it ranks every job by how well it matches you.&lt;/p&gt;

&lt;p&gt;The full code is on &lt;a href="https://github.com/zaima-20/ai-resume-analyzer" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. This post isn’t a line-by-line tutorial. It’s the five lessons that surprised me most, because most of them had nothing to do with the AI.&lt;/p&gt;

&lt;h3&gt;
  
  
  How it works
&lt;/h3&gt;

&lt;p&gt;The app is built in Python with Streamlit, and it has four tabs that follow the user’s journey:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Your Profile.&lt;/strong&gt; You enter your target job title, experience level, years of experience, top skills (each rated 1 to 5), location and preferred work type.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Upload Resume.&lt;/strong&gt; The app reads a PDF or Word file, splits it into sections like Experience, Skills and Projects, and extracts your email, phone, LinkedIn and GitHub links.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Analysis.&lt;/strong&gt; Fixed rules check for common problems, then Google Gemini gives a scored AI review with suggested rewrites.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Jobs.&lt;/strong&gt; The app searches several job sources, scores every job against your resume and profile, and shows the best matches first.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Users log in with their own account, so their profile, past analyses and saved jobs are there next time.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Lesson 1: Let rules and the LLM do different jobs
&lt;/h3&gt;

&lt;p&gt;My first instinct was to send the whole resume to an LLM and ask “what’s wrong with it?” I ended up splitting the work in two.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rule checks handle anything that can be checked exactly.&lt;/strong&gt; Missing sections, missing contact details, resume length, bullet points with no numbers, and weak phrases like “responsible for” or “worked on”. These rules are instant, free, and give the same answer every time. On my own CV, they flagged 20 bullet points with no measurable results, and that my resume had no LinkedIn link. Both were fair.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The LLM handles judgment.&lt;/strong&gt; Gemini gives an overall score, an ATS score, strengths, problems with fixes, rewritten bullet points, and keywords missing for the target role. I ask for JSON only, validate it into Python dataclasses, and retry once if the reply is malformed.&lt;/p&gt;

&lt;p&gt;Two things went wrong along the way, and both taught me something.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The model didn’t know today’s date.&lt;/strong&gt; On my first real run, Gemini flagged my current job, which started in August 2025, as “employment starting in the future”. Language models have no clock; their sense of “now” comes from their training data. The fix was one line: put today’s date in every prompt and tell the model to judge dates against it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The model must never invent achievements.&lt;/strong&gt; A resume tool that writes “improved performance by 40%” when you never measured anything is worse than useless. So the prompt says to keep every fact from the original bullet and use placeholders like [X%] for numbers the resume doesn't contain. I also pass the same weak-phrase list the rule checks use, so the AI's rewrites don't use phrases the app itself would flag.&lt;/p&gt;

&lt;p&gt;The model still isn’t perfect. Once it called “Designed custom ERP modules” weak, even though “Designed” is a strong verb. That’s why the rule checks sit alongside the AI rather than being replaced by it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lesson 2: You can’t just scrape LinkedIn
&lt;/h3&gt;

&lt;p&gt;I wanted jobs from LinkedIn, Indeed and Glassdoor. It turns out none of them offers a public API for reading job postings, and scraping them breaks their terms of service and gets blocked quickly.&lt;/p&gt;

&lt;p&gt;The legal route was to combine several sources:&lt;/p&gt;

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

&lt;p&gt;Every source returns the same Job dataclass, so the rest of the app doesn't care where a job came from. If one source fails, the app shows a warning and carries on with the others.&lt;/p&gt;

&lt;p&gt;Two real-world surprises:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;APIs change without warning.&lt;/strong&gt; My first JSearch request returned “Endpoint ‘/search’ does not exist”. The provider had retired it in favour of /search-v2, which also changed the response format.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Coverage is uneven.&lt;/strong&gt; Adzuna doesn’t cover Pakistan, so for a search in Lahore the app skips it with a friendly note rather than an error. JSearch, on the other hand, returned 10 Lahore-based ML jobs on the first try.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because free quotas are tiny, every search is cached for 6 hours. That also keeps the app within Remotive’s request of only a few fetches per day.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lesson 3: A match score is only good if you tune it on real data
&lt;/h3&gt;

&lt;p&gt;Each job gets a score from 0 to 100, made of four parts:&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;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;45&lt;/span&gt; × &lt;span class="n"&gt;skills&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; × &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; × &lt;span class="n"&gt;experience&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt; × &lt;span class="n"&gt;location&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each part is between 0 and 1. Skills are weighted by how the user rated them, and the score is based on their top 5 skills, so listing many skills never lowers a match.&lt;/p&gt;

&lt;p&gt;The first version passed all its tests. Then I ran it on my own CV and real Lahore jobs, and the problems were obvious:&lt;/p&gt;

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

&lt;p&gt;After tuning, the top results were the right ones: a “Junior Machine Learning Engineer” role asking for 1+ years ranked first with a score of 82 for a junior with 1 year of experience, and senior roles were labelled “above your level”.&lt;/p&gt;

&lt;p&gt;The lesson: tests prove the code does what you designed. Only real data shows whether the design was right.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lesson 4: Security belongs in the database, not just the code
&lt;/h3&gt;

&lt;p&gt;Before putting the app online, I added user accounts with Supabase. This raised three problems I hadn’t thought about.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One app, many visitors.&lt;/strong&gt; Streamlit runs a single Python process for everyone. If the logged-in user were stored in a normal module-level variable, the last person to log in would be logged in for everybody. Each visitor gets their own Supabase client and session, stored in Streamlit’s per-browser session_state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What stops user A reading user B’s data?&lt;/strong&gt; Every query in the code filters by user ID, but that’s not the real protection. Supabase’s &lt;strong&gt;Row Level Security&lt;/strong&gt; checks every request inside the database, using the signed login token: a user can only read and change rows where auth.uid() = user_id. Even if my Python code had a bug that forgot the filter, the database would still return only the caller's own rows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stopping one user from draining the API quotas.&lt;/strong&gt; Each user gets 5 job searches and 3 AI reviews per day. Users can read their usage counts but can’t change them directly, or they could reset their own limits. The only way to increase a count is a database function that checks the limit and adds one in a single step.&lt;/p&gt;

&lt;p&gt;I also made privacy choices on purpose. The app never stores the resume file or its full text, only the analysis results. It tells users that their resume text is sent to Gemini, and they can delete their data or their whole account with one button.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lesson 5: Measure before you optimize
&lt;/h3&gt;

&lt;p&gt;Once the app was live, it felt slow. I was ready to blame the free server or the distance to the database. Instead, I added timing logs around every major step first.&lt;/p&gt;

&lt;p&gt;The measurements pointed somewhere I didn’t expect. Ranking jobs took about &lt;strong&gt;1,050 ms&lt;/strong&gt; , because the missing-skills check ran about &lt;strong&gt;19,000 regex searches&lt;/strong&gt; per search. Two-thirds of them asked the same question for every job: is this skill already in the resume?&lt;/p&gt;

&lt;p&gt;The fixes were simple once I could see the problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Work out the user’s skills &lt;strong&gt;once per search&lt;/strong&gt; instead of once per job.&lt;/li&gt;
&lt;li&gt;Skip a regex entirely when a skill’s letters don’t appear in the text.&lt;/li&gt;
&lt;li&gt;Reuse compiled patterns.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ranking dropped to about &lt;strong&gt;170 ms&lt;/strong&gt; , roughly 6× faster, and I checked that every score and skill list stayed identical.&lt;/p&gt;

&lt;p&gt;Two more changes helped. Streamlit reruns the whole script on every click, including the code of hidden tabs, so I moved the job results into a &lt;strong&gt;fragment&lt;/strong&gt; that reruns on its own, and showed &lt;strong&gt;20 jobs at a time&lt;/strong&gt; with a “Show more” button. I also stopped reloading data from the database after every change, updating the lists on screen directly instead.&lt;/p&gt;

&lt;p&gt;If I’d guessed, I would have spent hours moving the database to another region. The real problem was one loop.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The AI review was the part I expected to be hard, and it turned out to be one of the quicker parts to build. The parts that took real work were everything around it: finding legal job sources, tuning a score on real data, keeping users’ data separate, protecting free API quotas, and finding out why the app was slow.&lt;/p&gt;

&lt;p&gt;If you’re building an AI project for your portfolio, that’s my main advice: the model call is only the start. Validation, testing on real inputs, security and measurement are what turn a demo into something people can actually use.&lt;/p&gt;

&lt;p&gt;The project has 478 automated tests and is built on the free tiers of Streamlit, Supabase, Gemini and the job APIs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Code:&lt;/strong&gt; &lt;a href="https://github.com/zaima-20/ai-resume-analyzer" rel="noopener noreferrer"&gt;github.com/zaima-20/ai-resume-analyzer&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What would you add next? I’m thinking about making the AI quote the exact resume line behind each problem. Let me know in the comments.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Job data includes listings from&lt;/em&gt; &lt;a href="https://remotive.com" rel="noopener noreferrer"&gt;&lt;em&gt;Remotive&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>aianalyzer</category>
      <category>machinelearning</category>
      <category>artificialintelligen</category>
    </item>
    <item>
      <title>Explain Your Machine Learning Model with SHAP: A Beginner’s Guide in Python</title>
      <dc:creator>Zaima Sohail</dc:creator>
      <pubDate>Tue, 03 Nov 2026 10:01:12 +0000</pubDate>
      <link>https://dev.to/zaima_sohail_6c55d2513505/explain-your-machine-learning-model-with-shap-a-beginners-guide-in-python-5em5</link>
      <guid>https://dev.to/zaima_sohail_6c55d2513505/explain-your-machine-learning-model-with-shap-a-beginners-guide-in-python-5em5</guid>
      <description>&lt;p&gt;&lt;em&gt;Your model is 95% accurate. Now someone asks why it made a particular decision. Here’s how to answer.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Most machine learning tutorials end with an accuracy score. In real projects, that’s where the hard questions start. A doctor won’t trust a model that flags a tumour as malignant without a reason. A bank can’t reject a loan application and say “the algorithm decided”.&lt;/p&gt;

&lt;p&gt;I ran into this while working on research into explainable machine learning for water quality assessment. A good score wasn’t enough. We needed to show which measurements drove each prediction, so people could check the model’s reasoning against what they already knew.&lt;/p&gt;

&lt;p&gt;The tool that made this possible was &lt;strong&gt;SHAP&lt;/strong&gt;. In this tutorial, we’ll train a model on a real medical dataset and use SHAP to explain it two ways: which features matter most overall, and why the model made one specific prediction. The full code is on &lt;a href="https://github.com/zaima-20/shap-explainability" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What SHAP actually does
&lt;/h3&gt;

&lt;p&gt;SHAP stands for SHapley Additive exPlanations. The idea comes from game theory: if a team wins a prize, how do you split it fairly based on how much each player contributed?&lt;/p&gt;

&lt;p&gt;SHAP treats each feature as a player and the prediction as the prize. For every single prediction, it calculates how much each feature pushed the result up or down compared to the model’s average prediction.&lt;/p&gt;

&lt;p&gt;The key property is that these contributions add up exactly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tex"&gt;&lt;code&gt;\text{prediction} = \text{average prediction} + \sum_i \text{SHAP value}_i
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So if the model’s average prediction is 0.62 and it predicts 0.10 for one patient, the SHAP values for that patient add up to -0.52. Each one tells you how much that feature was responsible for.&lt;/p&gt;

&lt;p&gt;This makes SHAP more useful than the built-in feature importance in tree models. That gives you one number per feature for the whole dataset. SHAP tells you the direction of the effect, and works for each individual prediction too.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setup
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install scikit-learn shap matplotlib pandas
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We’ll use the &lt;strong&gt;breast cancer dataset&lt;/strong&gt; that comes with scikit-learn, so there’s nothing to download. It has 569 tumour samples, each described by 30 measurements taken from a scan, such as radius, area, and the number of concave points on the tumour’s edge. Each sample is labelled malignant (212 cases) or benign (357 cases).&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;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;matplotlib&lt;/span&gt;
&lt;span class="n"&gt;matplotlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Agg"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# save plots to files without opening windows&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;matplotlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;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="k"&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="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;shap&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;datasets&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;load_breast_cancer&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ensemble&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;RandomForestClassifier&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;accuracy_score&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;classification_report&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;model_selection&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;train_test_split&lt;/span&gt;

&lt;span class="no"&gt;OUT_DIR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"plots"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="no"&gt;OUT_DIR&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mkdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exist_ok&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 1: Load the data
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;load_data&lt;/span&gt;&lt;span class="p"&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;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;load_breast_cancer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;as_frame&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="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="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="c1"&gt;# target: 0 = malignant, 1 = benign&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;train_test_split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;test_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;random_state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stratify&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as_frame=True gives us a pandas DataFrame with proper column names. That matters later: SHAP plots use these names, so they're readable without extra work.&lt;/p&gt;

&lt;p&gt;stratify=y keeps the same ratio of malignant to benign cases in both the training and test sets. With an imbalanced dataset like this one, a random split could leave the test set with too few malignant cases to judge the model properly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Train the model
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;train_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_test&lt;/span&gt;&lt;span class="p"&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="nc"&gt;RandomForestClassifier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n_estimators&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_depth&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;6&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;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="nc"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;preds&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="nc"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Test accuracy: {accuracy_score(y_test, preds):.3f}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;classification_report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;preds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target_names&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"malignant"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"benign"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A Random Forest is a good choice here. It works well on tabular data without much tuning, and SHAP has a fast, exact method for tree models.&lt;/p&gt;

&lt;p&gt;On the 114 test samples, the model reaches 94.7% accuracy:&lt;/p&gt;

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

&lt;p&gt;That’s a solid model. But these numbers can’t tell us &lt;em&gt;what&lt;/em&gt; it learned. That’s where SHAP comes in.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Compute SHAP values
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;compute_shap&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="nc"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;explainer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;shap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TreeExplainer&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="n"&gt;shap_values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;explainer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# For a binary classifier, SHAP returns one set of values per class.&lt;/span&gt;
    &lt;span class="c1"&gt;# We keep class 1 ("benign"): positive values push towards benign.&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;shap_values&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&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;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;TreeExplainer is SHAP's method for tree-based models like Random Forest and XGBoost. It's fast and gives exact values instead of approximations.&lt;/p&gt;

&lt;p&gt;The last line trips up a lot of beginners. For a classifier, SHAP returns values for &lt;em&gt;every&lt;/em&gt; class, so the result has three dimensions: samples, features, and classes. We pick class 1 (benign). From here on, a &lt;strong&gt;positive&lt;/strong&gt; SHAP value pushes a prediction towards benign, and a &lt;strong&gt;negative&lt;/strong&gt; one pushes it towards malignant.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: See what the model learned overall
&lt;/h3&gt;

&lt;p&gt;The first question to ask is: which features does the model rely on most?&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;shap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;plots&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sv&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_display&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&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="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;savefig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;OUT_DIR&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="s2"&gt;"shap_bar.png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dpi&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;150&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;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;The bar plot ranks features by their average impact. The top five are worst perimeter, worst area, worst concave points, worst radius and mean concave points. (“Worst” in this dataset means the largest value measured across the tumour’s cells.) In other words, the model mostly looks at &lt;strong&gt;tumour size and the shape of its edges&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The bar plot tells you &lt;em&gt;how much&lt;/em&gt; each feature matters, but not &lt;em&gt;in which direction&lt;/em&gt;. For that, we use the beeswarm plot:&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;shap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;plots&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;beeswarm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sv&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_display&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&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="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;savefig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;OUT_DIR&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="s2"&gt;"shap_beeswarm.png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dpi&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;150&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;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;This is the most information-dense plot in SHAP, so it’s worth learning to read:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Each dot is one patient&lt;/strong&gt; in the test set.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Its position left or right&lt;/strong&gt; is the SHAP value: left pushes towards malignant, right towards benign.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Its colour&lt;/strong&gt; is the feature’s actual value: red is high, blue is low.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Look at worst perimeter: the red dots (large tumours) sit on the left, and the blue dots (small ones) on the right. So the model has learned that &lt;strong&gt;larger, more irregular tumours are more likely to be malignant&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That matches medical knowledge, and this is the real value of SHAP. If the plot had shown the opposite, or if the top feature had been something meaningless like a sample ID, we’d know the model had learned something wrong, even with a 95% accuracy score.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Explain one prediction
&lt;/h3&gt;

&lt;p&gt;Global plots describe the model as a whole. But a doctor looking at one patient wants to know why the model flagged &lt;em&gt;this&lt;/em&gt; case. Let’s explain the first malignant tumour in the test set.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;explain_one&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="n"&gt;sv&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;proba&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_proba&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iloc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&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;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;actual&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"benign"&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;y_test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iloc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="s2"&gt;"malignant"&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Sample {idx}: predicted P(benign) = {proba:.3f}, actual = {actual}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Base value (average prediction): {sv.base_values[idx]:.3f}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;shap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;plots&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;waterfall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_display&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&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="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;savefig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;OUT_DIR&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"shap_waterfall_sample{idx}.png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dpi&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;150&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;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sample 0: predicted P(benign) = 0.000, actual = malignant
Base value (average prediction): 0.625
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model is certain this tumour is malignant, and it’s right. Here’s why:&lt;/p&gt;

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

&lt;p&gt;Read the waterfall plot from the bottom up:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It starts at the &lt;strong&gt;base value, 0.625&lt;/strong&gt;. This is the model’s average prediction: before looking at this patient, it leans towards benign, because benign cases are more common.&lt;/li&gt;
&lt;li&gt;Each bar is one feature’s contribution. Every bar here points left, towards malignant.&lt;/li&gt;
&lt;li&gt;The biggest pushes come from worst concave points (0.194), worst perimeter (178.6) and worst area (1,926), each lowering the prediction by about 0.07 to 0.08.&lt;/li&gt;
&lt;li&gt;Together, all the contributions bring the prediction down from 0.625 to  &lt;strong&gt;0&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is the kind of explanation a person can actually check. A doctor could look at this and say: “Yes, a tumour this large with this many irregular points is worrying.” The model’s decision is no longer a black box.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Treating SHAP as cause and effect.&lt;/strong&gt; SHAP explains what the &lt;em&gt;model&lt;/em&gt; relies on, not what causes cancer in the real world. If two features are strongly related, like radius and area here, the model may split credit between them in ways that don’t reflect biology.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Forgetting which class you’re explaining.&lt;/strong&gt; If you pick class 0 instead of class 1, every sign flips and your interpretation is backwards. Always write down which class positive values point towards.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explaining only the global picture.&lt;/strong&gt; The bar plot alone can hide a lot. Look at individual predictions too, especially the ones the model got wrong. Those usually teach you the most.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Using the slow explainer by accident.&lt;/strong&gt; shap.KernelExplainer works with any model but can be very slow. For tree models, always use TreeExplainer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In just over 100 lines of Python, we trained a model with 94.7% test accuracy and then answered the questions accuracy can’t: which features drive its decisions, in which direction, and why it made one specific prediction.&lt;/p&gt;

&lt;p&gt;The main lesson is simple. Before you trust a model, check that it learned something sensible. Here, SHAP confirmed the model relies on tumour size and edge shape, which matches medical knowledge. In other projects, it might reveal that your model learned a shortcut you never intended.&lt;/p&gt;

&lt;p&gt;The complete code is on &lt;a href="https://github.com/zaima-20/shap-explainability" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. Try it on your own dataset, and let me know in the comments what SHAP reveals about your model.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you found this useful, follow me for more practical machine learning tutorials.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>datavisualization</category>
      <category>machinelearning</category>
      <category>python</category>
      <category>shap</category>
    </item>
    <item>
      <title>Most RAG Tutorials Skip the Hardest Part: Evaluation</title>
      <dc:creator>Zaima Sohail</dc:creator>
      <pubDate>Tue, 03 Nov 2026 09:46:36 +0000</pubDate>
      <link>https://dev.to/zaima_sohail_6c55d2513505/most-rag-tutorials-skip-the-hardest-part-evaluation-5chg</link>
      <guid>https://dev.to/zaima_sohail_6c55d2513505/most-rag-tutorials-skip-the-hardest-part-evaluation-5chg</guid>
      <description>&lt;p&gt;&lt;em&gt;Building a RAG demo takes an afternoon. Knowing whether it works takes much longer, and that’s the part almost nobody writes about.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Search for “RAG tutorial” and you’ll find hundreds of them. They all follow the same script: load some PDFs, split them into chunks, embed them, store them in a vector database, connect an LLM, and ask it a question. The answer comes back fluent and confident. The tutorial ends there.&lt;/p&gt;

&lt;p&gt;But that last step hides the real question. Was the answer correct? Did it come from the documents, or did the model make it up? Would it still work on the next hundred questions?&lt;/p&gt;

&lt;p&gt;I think evaluation is the hardest and most important part of building a RAG system, and the part most tutorials skip entirely.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why evaluation gets skipped
&lt;/h3&gt;

&lt;p&gt;The honest reason is that evaluation is boring to demo. A chatbot answering a question looks impressive in a screenshot. A spreadsheet of 50 test questions with scores next to them does not.&lt;/p&gt;

&lt;p&gt;There’s also a deeper problem: LLMs are very good at sounding right. A wrong answer written in clear, confident English is hard to spot when you’re testing by hand. You ask five questions, the answers look reasonable, and you move on. That’s not testing. That’s hoping.&lt;/p&gt;

&lt;h3&gt;
  
  
  A RAG system can fail in two different places
&lt;/h3&gt;

&lt;p&gt;This is the idea I wish someone had explained to me earlier. A RAG pipeline has two stages, and each one can fail on its own:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Retrieval&lt;/strong&gt; can bring back the wrong chunks. If the right information never reaches the model, even the best LLM can’t answer correctly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generation&lt;/strong&gt; can misuse the right chunks. The model might ignore the context, mix it with its own knowledge, or add details that aren’t in any document.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When you only look at the final answer, you can’t tell which stage failed. So you end up changing the wrong thing: swapping the LLM when the real problem was chunk size, or tuning the retriever when the model was ignoring good context.&lt;/p&gt;

&lt;p&gt;That’s why “it answered my question” tells you almost nothing. You need to measure each stage separately.&lt;/p&gt;

&lt;h3&gt;
  
  
  What building a multi-agent pipeline taught me
&lt;/h3&gt;

&lt;p&gt;For my MS thesis, I built EmoRAG: a pipeline of five agents in LangGraph that answers student questions and adapts its response to the student’s emotional state. One agent detects emotion with a fine-tuned BERT-style classifier, others handle retrieval and routing, and an LLM generates the final answer.&lt;/p&gt;

&lt;p&gt;A few lessons stood out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Every agent is another place to fail.&lt;/strong&gt; In a single-step RAG system, there are two stages to check. With five agents, there are five, plus the hand-offs between them. If the emotion agent misreads a frustrated student as calm, the answer can be accurate and still land badly. The final output looks fine, but the system didn’t do what it was designed to do.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So each component needs its own test.&lt;/strong&gt; Instead of judging only the final answer, I evaluate the emotion classifier on its own. I’m comparing five options (BERT-base, RoBERTa-base, DistilRoBERTa, DeBERTa-v3-small, and a simple TF-IDF with logistic regression baseline) on the same labelled data before choosing one. Including the simple baseline matters: if a basic model comes close, the extra complexity has to earn its place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Speed is part of quality.&lt;/strong&gt; I started with a local LLaMA 3.1 8B model through Ollama. The answers were fine, but generation was too slow for an interactive student tool, so I switched to a Gemini model. No accuracy metric would have caught that. A system that gives a good answer after a long wait still fails the user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A result that surprised us.&lt;/strong&gt; We expected the hosted LLM to be the stronger emotion detector, and on our own 35 emotion variants it was: gemini-3.5-flash-lite labelled all 35 correctly, while DistilRoBERTa got only 18 of them right (0.514). On 300 real Reddit comments from the GoEmotions test split, the result reversed. DistilRoBERTa was correct on 217 (0.723) and Gemini on only 149 (0.497). Gemini’s errors were not random: it labelled 54 of these comments as Confident, although only one of them was. Our variants were written so that the emotion is easy to see, the way an exam question is written, but real comments rarely say how the writer feels so clearly. Each detector did best on text that resembled what it was trained or prompted on. A perfect score on clean, hand-written examples therefore told us very little about how the system would handle real student messages.&lt;/p&gt;

&lt;h3&gt;
  
  
  A minimal evaluation checklist
&lt;/h3&gt;

&lt;p&gt;You don’t need a huge framework to start. If I were adding evaluation to a RAG project from scratch, I’d start with this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Write a small test set first.&lt;/strong&gt; Collect 30 to 50 real questions, each with the correct answer and the document it should come from. Writing these by hand is slow, and it’s the most valuable hour you’ll spend on the project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure retrieval on its own.&lt;/strong&gt; For each question, check whether the correct chunk appears in the top results. If it doesn’t, stop there and fix retrieval before touching the prompt or the model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check whether answers stay faithful to the context.&lt;/strong&gt; Does every claim in the answer appear in the retrieved chunks? Tools like RAGAS can score this automatically, but reading 20 answers yourself teaches you even more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test what happens when the answer isn’t there.&lt;/strong&gt; Ask questions your documents can’t answer. A good system says it doesn’t know. A bad one invents something.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Track latency and cost.&lt;/strong&gt; Record how long each answer takes and what it costs. These matter to real users as much as accuracy does.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Re-run everything after every change.&lt;/strong&gt; New chunk size, new prompt, new model: run the same test set and compare. Without this, you’re guessing whether each change helped.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;RAG tutorials make it look like the hard part is connecting the pieces. In my experience, connecting the pieces is the easy part. The hard part is proving the system works, finding out where it breaks, and knowing that the next change made it better rather than just different.&lt;/p&gt;

&lt;p&gt;If you’re building a RAG project for your portfolio, add an evaluation section to it. A chatbot that answers questions is common. A chatbot with a test set, retrieval scores, and an honest list of failure cases shows that you think like an engineer.&lt;/p&gt;

&lt;p&gt;How do you evaluate your RAG systems? I’d genuinely like to hear what’s worked for you in the comments.&lt;/p&gt;

</description>
      <category>gemini</category>
      <category>rags</category>
      <category>llm</category>
      <category>llama3</category>
    </item>
    <item>
      <title>How I Automate Excel Reports with Python in One Script</title>
      <dc:creator>Zaima Sohail</dc:creator>
      <pubDate>Tue, 03 Nov 2026 09:34:16 +0000</pubDate>
      <link>https://dev.to/zaima_sohail_6c55d2513505/how-i-automate-excel-reports-with-python-in-one-script-31h9</link>
      <guid>https://dev.to/zaima_sohail_6c55d2513505/how-i-automate-excel-reports-with-python-in-one-script-31h9</guid>
      <description>&lt;p&gt;&lt;em&gt;Turn a messy spreadsheet into a clean, formatted report with one Python script.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Every week, someone in your office opens the same messy spreadsheet. They delete duplicate rows, hunt for blank cells, fix “north “ so it matches “North”, and rebuild the same pivot tables they built last week. It takes an hour, it’s boring, and one small slip breaks the totals.&lt;/p&gt;

&lt;p&gt;I work as a Python developer on business systems, and I see this pattern constantly. The good news is that this kind of work is perfect for automation. In this tutorial, we’ll write one Python script that reads a raw Excel file, cleans it, summarises it, and saves a formatted report with a chart, all in a few seconds.&lt;/p&gt;

&lt;p&gt;You only need basic Python. The full code is on &lt;a href="https://github.com/zaima-20/excel-report-automation" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What we’ll build
&lt;/h3&gt;

&lt;p&gt;We start with a raw sales file of 215 rows. It has duplicate orders, blank cells, and inconsistent region names. The script turns it into one Excel report with five sheets:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0kvf7vcg470rzuznvr1l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0kvf7vcg470rzuznvr1l.png" width="671" height="198"&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F08ky0tzwraojs89542sl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F08ky0tzwraojs89542sl.png" width="799" height="295"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Setup&lt;/p&gt;

&lt;p&gt;We need two libraries: &lt;strong&gt;pandas&lt;/strong&gt; for working with the data and &lt;strong&gt;openpyxl&lt;/strong&gt; for reading, writing and formatting Excel files.&lt;/p&gt;

&lt;p&gt;pip install pandas openpyxl&lt;/p&gt;

&lt;p&gt;You probably don’t have a messy sales file lying around, so the script creates one for you. On the first run, a small function generates 200 orders and deliberately breaks them: it blanks out some cells, turns a few region names into lowercase with trailing spaces, and copies 15 rows to create duplicates. That way anyone can follow along and get the same results.&lt;/p&gt;

&lt;p&gt;Here are the imports and file names we’ll use throughout:&lt;/p&gt;

&lt;p&gt;from pathlib import Path  &lt;/p&gt;

&lt;p&gt;import numpy as np&lt;br&gt;&lt;br&gt;
 import pandas as pd&lt;br&gt;&lt;br&gt;
 from openpyxl import load_workbook&lt;br&gt;&lt;br&gt;
 from openpyxl.chart import BarChart, Reference&lt;br&gt;&lt;br&gt;
 from openpyxl.styles import Font, PatternFill, Alignment  &lt;/p&gt;

&lt;p&gt;RAW_FILE = Path(“raw_sales.xlsx”)&lt;br&gt;&lt;br&gt;
 REPORT_FILE = Path(“sales_report.xlsx”)&lt;/p&gt;

&lt;p&gt;If you want to use your own data instead, just replace raw_sales.xlsx with your file and adjust the column names later on.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Step 1: Read the Excel file
&lt;/h3&gt;

&lt;p&gt;Reading an Excel file with pandas takes one line. pd.read_excel() opens the first sheet and returns a DataFrame, which is basically a spreadsheet you can control with code.&lt;/p&gt;

&lt;p&gt;def load_data(path: Path) -&amp;gt; pd.DataFrame:&lt;br&gt;&lt;br&gt;
 df = pd.read_excel(path)&lt;br&gt;&lt;br&gt;
 print(f”Loaded {len(df)} rows, {df.shape[1]} columns”)&lt;br&gt;&lt;br&gt;
 return df&lt;/p&gt;

&lt;p&gt;The print line is a small habit worth keeping. When the script runs every week on new files, a quick row count tells you straight away if something looks wrong, like a file that’s half empty. For our sample file it prints Loaded 215 rows, 6 columns.&lt;/p&gt;

&lt;p&gt;If your data lives on a different sheet, pass its name: pd.read_excel(path, sheet_name=”January”).&lt;/p&gt;

&lt;p&gt;(The function that generates the sample data is in the &lt;a href="https://github.com/zaima-20/excel-report-automation" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt; if you want to see how the mess was made.)&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Clean the data
&lt;/h3&gt;

&lt;p&gt;This is the part people usually do by hand, and the part where automation saves the most time. Our raw file has three problems: duplicate rows, inconsistent text, and missing values. We’ll fix them one at a time, and keep a few numbers along the way for the report.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remove duplicates
&lt;/h3&gt;

&lt;p&gt;stats = {“rows_before”: len(df)}&lt;br&gt;&lt;br&gt;
 stats[“duplicates_removed”] = int(df.duplicated().sum())&lt;br&gt;&lt;br&gt;
 df = df.drop_duplicates().copy()&lt;/p&gt;

&lt;p&gt;df.duplicated() marks every row that is an exact copy of an earlier one. Counting them before dropping lets us report how many we removed, which here is 15. That number matters: if your boss asks why the total changed, you have the answer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fix inconsistent text
&lt;/h3&gt;

&lt;p&gt;In the raw file, the same region appears as “North”, “north “ and so on. To you, these are the same. To pandas, they’re different values, so a summary would show “North” and “north “ as two separate regions with split totals.&lt;/p&gt;

&lt;p&gt;df[“Region”] = df[“Region”].str.strip().str.title()&lt;/p&gt;

&lt;p&gt;.str.strip() removes spaces at the start and end, and .str.title() capitalises the first letter. In our sample, this one line fixes 16 inconsistent entries.&lt;/p&gt;

&lt;p&gt;We also convert the Date column into real dates, so we can group by month later:&lt;/p&gt;

&lt;p&gt;df[“Date”] = pd.to_datetime(df[“Date”], errors=”coerce”)&lt;/p&gt;

&lt;p&gt;errors=”coerce” turns anything that isn’t a valid date into a blank instead of crashing the script.&lt;/p&gt;

&lt;h3&gt;
  
  
  Handle missing values
&lt;/h3&gt;

&lt;p&gt;After removing duplicates, the data still has 12 missing quantities, 8 missing regions and 5 missing prices. The easy option is to fill every blank with 0. Don’t. If a laptop order has no price and you fill it with 0, that order now looks free, and your revenue total is quietly wrong.&lt;/p&gt;

&lt;p&gt;Instead, each column gets a fill that makes sense for it:&lt;/p&gt;

&lt;p&gt;df[“Region”] = df[“Region”].fillna(“Unknown”)&lt;br&gt;&lt;br&gt;
 df[“Quantity”] = df[“Quantity”].fillna(df[“Quantity”].median())&lt;br&gt;&lt;br&gt;
 df[“Unit Price”] = df.groupby(“Product”)[“Unit Price”].transform(&lt;br&gt;&lt;br&gt;
 lambda s: s.fillna(s.median())&lt;br&gt;&lt;br&gt;
 )&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Region:&lt;/strong&gt; we can’t guess where an order came from, so we label it “Unknown”. The orders stay in the totals, and the report shows openly how many are unassigned.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Quantity:&lt;/strong&gt; we use the median. It’s a typical order size, and unlike the average, one huge order can’t pull it up.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Unit Price:&lt;/strong&gt; a missing laptop price should be filled with a laptop price, not the average of laptops and mice. groupby(“Product”) with transform fills each blank with the median price of that same product.&lt;/p&gt;

&lt;p&gt;That last line is the one I’d point to if someone asked what separates a careful cleaning script from a quick one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add calculated columns
&lt;/h3&gt;

&lt;p&gt;Finally, we add Revenue and Month, which the summaries need:&lt;/p&gt;

&lt;p&gt;df[“Revenue”] = df[“Quantity”] * df[“Unit Price”]&lt;br&gt;&lt;br&gt;
 df[“Month”] = df[“Date”].dt.to_period(“M”).astype(str)&lt;br&gt;&lt;br&gt;
 stats[“rows_after”] = len(df)&lt;/p&gt;

&lt;p&gt;We’re now down from 215 messy rows to 200 clean ones, with no blank cells left.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Build summary tables
&lt;/h3&gt;

&lt;p&gt;Now the data is clean, summaries are easy. These replace the pivot tables someone would otherwise rebuild by hand every week.&lt;/p&gt;

&lt;p&gt;def build_summaries(df: pd.DataFrame) -&amp;gt; dict[str, pd.DataFrame]:&lt;br&gt;&lt;br&gt;
 by_region = (df.groupby(“Region”, as_index=False)&lt;br&gt;&lt;br&gt;
 .agg(Orders=(“Order ID”, “count”),&lt;br&gt;&lt;br&gt;
 Units=(“Quantity”, “sum”),&lt;br&gt;&lt;br&gt;
 Revenue=(“Revenue”, “sum”))&lt;br&gt;&lt;br&gt;
 .sort_values(“Revenue”, ascending=False))  &lt;/p&gt;

&lt;p&gt;by_product = (df.groupby(“Product”, as_index=False)&lt;br&gt;&lt;br&gt;
 .agg(Units=(“Quantity”, “sum”), Revenue=(“Revenue”, “sum”))&lt;br&gt;&lt;br&gt;
 .sort_values(“Revenue”, ascending=False))  &lt;/p&gt;

&lt;p&gt;monthly = df.pivot_table(index=”Month”, columns=”Region”,&lt;br&gt;&lt;br&gt;
 values=”Revenue”, aggfunc=”sum”, fill_value=0)&lt;br&gt;&lt;br&gt;
 monthly = monthly.reset_index()  &lt;/p&gt;

&lt;p&gt;return {“By Region”: by_region, “By Product”: by_product, “Monthly”: monthly}&lt;/p&gt;

&lt;p&gt;groupby() with .agg() works like a pivot table with named results. Each line inside .agg() reads as “new column = (source column, calculation)”, so Orders=(“Order ID”, “count”) counts orders per region. Sorting by revenue puts the best performers at the top.&lt;/p&gt;

&lt;p&gt;pivot_table() builds a grid: months down the side, regions across the top, revenue in each cell. fill_value=0 matters here, because a region with no sales in a month should show 0, not a blank.&lt;/p&gt;

&lt;p&gt;Here’s the region summary for our sample data:&lt;/p&gt;

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

&lt;p&gt;Notice the “Unknown” row. Eight orders and 3,495 in revenue would have quietly disappeared if we had simply deleted rows with missing regions.&lt;/p&gt;

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

&lt;p&gt;Step 4: Save multiple sheets&lt;/p&gt;

&lt;p&gt;A report is much easier to use when everything lives in one file instead of five. pd.ExcelWriter lets us write several DataFrames into separate sheets of the same workbook.&lt;/p&gt;

&lt;p&gt;def save_report(df, summaries, stats, path):&lt;br&gt;&lt;br&gt;
 with pd.ExcelWriter(path, engine=”openpyxl”) as writer:&lt;br&gt;&lt;br&gt;
 overview = pd.DataFrame({&lt;br&gt;&lt;br&gt;
 “Metric”: [“Rows before cleaning”, “Duplicates removed”,&lt;br&gt;&lt;br&gt;
 “Rows after cleaning”, “Total revenue”],&lt;br&gt;&lt;br&gt;
 “Value”: [stats[“rows_before”], stats[“duplicates_removed”],&lt;br&gt;&lt;br&gt;
 stats[“rows_after”], round(df[“Revenue”].sum(), 2)],&lt;br&gt;&lt;br&gt;
 })&lt;br&gt;&lt;br&gt;
 overview.to_excel(writer, sheet_name=”Overview”, index=False)&lt;br&gt;&lt;br&gt;
 for name, table in summaries.items():&lt;br&gt;&lt;br&gt;
 table.to_excel(writer, sheet_name=name, index=False)&lt;br&gt;&lt;br&gt;
 df.to_excel(writer, sheet_name=”Clean Data”, index=False)&lt;/p&gt;

&lt;p&gt;The with block opens the file, writes each sheet, and saves and closes it automatically at the end.&lt;/p&gt;

&lt;p&gt;I put the Overview sheet first on purpose. It’s the first thing anyone sees when they open the file: 215 rows came in, 15 duplicates were removed, 200 rows remain, and total revenue is 116,175. Those four numbers also make the report easy to trust, because anyone can see exactly what the cleaning changed.&lt;/p&gt;

&lt;p&gt;index=False stops pandas from adding an extra column of row numbers, which nobody wants in a business report.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Step 5: Add formatting and a chart
&lt;/h3&gt;

&lt;p&gt;A plain pandas export works, but it looks unfinished: narrow columns, plain headers, no visuals. A few lines of openpyxl turn it into something you’d happily send to a manager.&lt;/p&gt;

&lt;p&gt;def format_report(path):&lt;br&gt;&lt;br&gt;
 wb = load_workbook(path)&lt;br&gt;&lt;br&gt;
 header_fill = PatternFill(“solid”, fgColor=”1F4E78")&lt;br&gt;&lt;br&gt;
 header_font = Font(bold=True, color=”FFFFFF”)  &lt;/p&gt;

&lt;p&gt;for ws in wb.worksheets:&lt;br&gt;&lt;br&gt;
 for cell in ws[1]:&lt;br&gt;&lt;br&gt;
 cell.fill = header_fill&lt;br&gt;&lt;br&gt;
 cell.font = header_font&lt;br&gt;&lt;br&gt;
 cell.alignment = Alignment(horizontal=”center”)&lt;br&gt;&lt;br&gt;
 for col in ws.columns:&lt;br&gt;&lt;br&gt;
 width = max(len(str(c.value)) if c.value is not None else 0 for c in col)&lt;br&gt;&lt;br&gt;
 ws.column_dimensions[col[0].column_letter].width = min(width + 3, 30)&lt;br&gt;&lt;br&gt;
 ws.freeze_panes = “A2”&lt;/p&gt;

&lt;p&gt;For every sheet, this does three things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Styles the header row&lt;/strong&gt; with a dark blue background and bold white text. ws[1] means “row 1”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Auto-sizes each column&lt;/strong&gt; to fit its longest value, capped at 30 characters so one long entry can’t make a column huge.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Freezes the header row&lt;/strong&gt; with freeze_panes = “A2”, so the headers stay visible when you scroll down 200 rows.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Then we add a bar chart to the By Region sheet:&lt;/p&gt;

&lt;p&gt;ws = wb[“By Region”]&lt;br&gt;&lt;br&gt;
 chart = BarChart()&lt;br&gt;&lt;br&gt;
 chart.title = “Revenue by Region”&lt;br&gt;&lt;br&gt;
 chart.y_axis.title = “Revenue”&lt;br&gt;&lt;br&gt;
 data = Reference(ws, min_col=4, min_row=1, max_row=ws.max_row)&lt;br&gt;&lt;br&gt;
 cats = Reference(ws, min_col=1, min_row=2, max_row=ws.max_row)&lt;br&gt;&lt;br&gt;
 chart.add_data(data, titles_from_data=True)&lt;br&gt;&lt;br&gt;
 chart.set_categories(cats)&lt;br&gt;&lt;br&gt;
 ws.add_chart(chart, “F2”)  &lt;/p&gt;

&lt;p&gt;wb.save(path)&lt;/p&gt;

&lt;p&gt;Reference points the chart at cells in the sheet. Column 4 holds Revenue (including its header, so the chart picks up the series name), and column 1 holds the region names for the x-axis. add_chart(chart, “F2”) places the chart next to the table.&lt;/p&gt;

&lt;p&gt;Because this is a real Excel chart, not an image, anyone can click it, restyle it, or change its type in Excel.&lt;/p&gt;

&lt;h3&gt;
  
  
  Putting it all together
&lt;/h3&gt;

&lt;p&gt;The main() function runs every step in order:&lt;/p&gt;

&lt;p&gt;def main():&lt;br&gt;&lt;br&gt;
 if not RAW_FILE.exists():&lt;br&gt;&lt;br&gt;
 create_sample_data(RAW_FILE)&lt;br&gt;&lt;br&gt;
 df = load_data(RAW_FILE)&lt;br&gt;&lt;br&gt;
 clean, stats = clean_data(df)&lt;br&gt;&lt;br&gt;
 summaries = build_summaries(clean)&lt;br&gt;&lt;br&gt;
 save_report(clean, summaries, stats, REPORT_FILE)&lt;br&gt;&lt;br&gt;
 format_report(REPORT_FILE)&lt;br&gt;&lt;br&gt;
 print(f”Duplicates removed: {stats[‘duplicates_removed’]}”)&lt;br&gt;&lt;br&gt;
 print(f”Report saved: {REPORT_FILE}”)  &lt;/p&gt;

&lt;p&gt;if __name__ == “__main__”:&lt;br&gt;&lt;br&gt;
 main()&lt;/p&gt;

&lt;p&gt;Run it with python excel_report_automation.py. The whole thing finishes in a few seconds, and the output looks like this:&lt;/p&gt;

&lt;p&gt;Sample data created: raw_sales.xlsx (215 rows)&lt;br&gt;&lt;br&gt;
 Loaded 215 rows, 6 columns&lt;br&gt;&lt;br&gt;
 Duplicates removed: 15&lt;br&gt;&lt;br&gt;
 Report saved: sales_report.xlsx&lt;/p&gt;

&lt;h3&gt;
  
  
  Going further
&lt;/h3&gt;

&lt;p&gt;The script already saves time, but a few small additions make it fully hands-off:&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Run it on a schedule.&lt;/strong&gt; On Windows, use Task Scheduler to run the script every Monday at 9 a.m. On Mac or Linux, a cron job does the same thing. The report is ready before anyone opens their laptop.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Email the report automatically.&lt;/strong&gt; Python’s built-in smtplib and email modules can attach sales_report.xlsx and send it to your team as soon as it’s created.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Process a whole folder.&lt;/strong&gt; If you receive one file per branch or per month, loop over them with Path(“data”).glob(“*.xlsx”), combine them with pd.concat(), and build one combined report.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Make it reusable.&lt;/strong&gt; Move the column names and file paths into a small config file, so the same script works for different reports without editing the code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;We took a messy 215-row spreadsheet and, with one Python script, turned it into a clean, five-sheet report with a chart. Along the way, we removed 15 duplicates, fixed 16 inconsistent region names, and filled 25 missing values in ways that keep the totals honest.&lt;/p&gt;

&lt;p&gt;The biggest lesson isn’t any single pandas function. It’s that cleaning decisions, like how to fill a missing price, are business decisions. Writing them down in code makes them consistent every single week.&lt;/p&gt;

&lt;p&gt;The complete code is on &lt;a href="https://github.com/zaima-20/excel-report-automation" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. Try it on your own data, and if you get stuck or have ideas for improvements, leave a comment. I’d love to hear what you automate with it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you found this useful, follow me for more practical Python, data science and machine learning tutorials.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>datascience</category>
      <category>automation</category>
      <category>pandas</category>
    </item>
  </channel>
</rss>
