<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Andile Pingo  on Medium]]></title>
        <description><![CDATA[Stories by Andile Pingo  on Medium]]></description>
        <link>https://medium.com/@andilepingo?source=rss-710be3592208------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*HDG6o3hcYV4CaDkC</url>
            <title>Stories by Andile Pingo  on Medium</title>
            <link>https://medium.com/@andilepingo?source=rss-710be3592208------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 01:23:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@andilepingo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Amazon’s Machine Learning System Design: End-to-End Overview]]></title>
            <link>https://medium.com/@andilepingo/amazons-machine-learning-system-design-end-to-end-overview-004481363a6d?source=rss-710be3592208------2</link>
            <guid isPermaLink="false">https://medium.com/p/004481363a6d</guid>
            <category><![CDATA[ml-system-design]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[amazon]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Andile Pingo ]]></dc:creator>
            <pubDate>Mon, 03 Mar 2025 11:37:37 GMT</pubDate>
            <atom:updated>2025-03-03T11:37:37.744Z</atom:updated>
            <content:encoded><![CDATA[<p>Amazon’s recommendation system is a world-class <strong>AI-driven</strong> platform that personalizes product suggestions for millions of users daily. In this blog, we’ll break down the <strong>end-to-end machine learning system design</strong> behind Amazon’s recommendation engine, including <strong>data collection, system architecture, model training, deployment, and continuous monitoring</strong>.</p><p>Let’s get started my lovely ML FAM!!!</p><h3>1️⃣ Data Collection &amp; Preprocessing 📊</h3><h3>🔹 Data Sources</h3><p>Amazon collects <strong>real-time and historical data</strong> from multiple sources, including: ✅ <strong>User behavior logs</strong> (search history, clicks, purchases, cart additions, wishlists). ✅ <strong>Product metadata</strong> (category, price, discount, reviews, ratings). ✅ <strong>User reviews</strong> (text sentiment analysis, review rating distributions). ✅ <strong>Browsing patterns</strong> (session data, dwell time, bounce rates). ✅ <strong>External data</strong> (trending products, competitor pricing, social media influence).</p><h3>🔹 Data Processing Tools</h3><p>To handle massive data, Amazon uses: ✔ <strong>AWS Kinesis / Kafka</strong> — Streams real-time user interactions. ✔ <strong>Amazon S3</strong> — Stores raw, structured, and unstructured data. ✔ <strong>AWS Glue / Apache Spark</strong> — Cleans and transforms data at scale. ✔ <strong>DynamoDB / Redis</strong> — Fast lookup storage for frequently used data.</p><p><strong>Example:</strong> When a user browses a laptop on Amazon, their interaction is logged, analyzed, and used for future recommendations.</p><h3>2️⃣ System Architecture &amp; Infrastructure 🏗️</h3><h3>🔹 Core Components</h3><p>Amazon’s ML infrastructure is built for <strong>scalability and low latency</strong>. The key components include: ✔ <strong>Data Pipelines</strong> — AWS Glue/Spark processes data in batches and streams. ✔ <strong>Feature Store</strong> — AWS SageMaker Feature Store stores engineered features for fast retrieval. ✔ <strong>Recommendation Engine</strong> — Uses deep learning, collaborative filtering, and NLP. ✔ <strong>Inference &amp; Ranking Service</strong> — Predicts recommendations in real time. ✔ <strong>API Gateway</strong> — Serves model predictions to Amazon’s website/app. ✔ <strong>Database (DynamoDB/Redis)</strong> — Stores user embeddings and caching popular results.</p><p><strong>Example:</strong> If a user frequently buys gaming accessories, the system <strong>precomputes embeddings</strong> to suggest new gaming products instantly.</p><h3>3️⃣ Model Training &amp; Optimization 🎯</h3><p>Amazon uses <strong>a mix of deep learning, collaborative filtering, and NLP models</strong> to generate recommendations.</p><h3>🔹 Model Approaches &amp; Techniques</h3><p>✔ <strong>Collaborative Filtering (Matrix Factorization, Neural CF)</strong> — Learns user-product relationships. ✔ <strong>Content-Based Filtering (TF-IDF, BERT embeddings)</strong> — Understands product descriptions. ✔ <strong>Deep Learning (Transformers, CNNs, LSTMs)</strong> — Extracts advanced patterns in user behavior. ✔ <strong>Reinforcement Learning (Multi-Armed Bandits, RLHF)</strong> — Adapts recommendations in real time. ✔ <strong>Graph Neural Networks (GNNs)</strong> — Detects relationships between users and products.</p><h3>🔹 Model Training Tools</h3><p>✔ <strong>AWS SageMaker</strong> — Trains and deploys scalable ML models. ✔ <strong>TensorFlow/PyTorch</strong> — Deep learning frameworks. ✔ <strong>Spark MLlib</strong> — Distributed ML processing for large datasets. ✔ <strong>Ray Tune / Optuna</strong> — Hyperparameter tuning for best model performance.</p><p><strong>Example:</strong> Amazon fine-tunes its model to <strong>prioritize trending products</strong>, balancing <strong>new arrivals</strong> with <strong>personalized history</strong>.</p><h3>4️⃣ Model Deployment &amp; Real-Time Inference 🚀</h3><h3>🔹 Deployment Strategy</h3><p>Amazon ensures <strong>low latency and scalability</strong> using: ✔ <strong>AWS SageMaker Endpoints</strong> — For large-scale ML inference. ✔ <strong>Docker + Kubernetes (AWS EKS)</strong> — For deploying models in a containerized environment. ✔ <strong>AWS Lambda + API Gateway</strong> — For lightweight, serverless inference.</p><h3>🔹 Real-Time Inference Pipeline</h3><p>1️⃣ User visits Amazon &amp; interacts with products. 2️⃣ User data is streamed via <strong>AWS Kinesis / Kafka</strong>. 3️⃣ Feature store fetches user embeddings (<strong>AWS SageMaker Feature Store</strong>). 4️⃣ Model inference request is sent to <strong>SageMaker Endpoint</strong>. 5️⃣ Ranking system applies personalization &amp; business rules. 6️⃣ Recommendations are served instantly with <strong>Redis caching</strong>.</p><p><strong>Example:</strong> A user searching for headphones will see <strong>real-time, personalized</strong> suggestions based on their search history, trending products, and popular choices.</p><h3>5️⃣ Monitoring &amp; Continuous Learning 🔄</h3><h3>🔹 Why Monitor the Model?</h3><p>To ensure Amazon’s recommendations <strong>stay relevant</strong>, the system monitors: ✔ <strong>Prediction Accuracy (CTR, Conversion Rate, A/B Test Results)</strong>. ✔ <strong>Latency &amp; Performance</strong> — Should always stay under <strong>100ms</strong>. ✔ <strong>Drift Detection</strong> — Identifies model degradation over time. ✔ <strong>Bias &amp; Fairness Metrics</strong> — Ensures diversity in recommendations.</p><h3>🔹 Tools Used for Monitoring</h3><p>✔ <strong>AWS CloudWatch</strong> — Tracks model inference requests &amp; errors. ✔ <strong>Evidently AI / SageMaker Model Monitor</strong> — Monitors data &amp; concept drift. ✔ <strong>Prometheus + Grafana</strong> — Real-time dashboards for tracking ML performance.</p><h3>🔹 Continuous Learning &amp; Auto-Retraining</h3><p>✔ <strong>AWS SageMaker Pipelines</strong> — Automates retraining when model drift is detected. ✔ <strong>Reinforcement Learning (RLHF)</strong> — Improves recommendations based on <strong>user interactions</strong>. ✔ <strong>A/B Testing &amp; Canary Deployments</strong> — Compares new vs. old models before full rollout.</p><p><strong>Example:</strong> If Amazon detects that a model’s <strong>CTR has dropped</strong>, it automatically triggers <strong>retraining</strong> to refresh recommendations.</p><h3>🚀 Conclusion</h3><p>Amazon’s <strong>ML recommendation system</strong> is one of the most advanced AI systems in the world, powered by <strong>deep learning, NLP, reinforcement learning, and large-scale distributed computing</strong>.</p><p>And that’s a wrap! I hope you enjoyed this post and found it insightful. If you did, don’t forget to like, comment, and share it with your friends. I’d also love to hear your thoughts — any feedback or suggestions for improvement are always welcome in the comments. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=004481363a6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ML Algorithms Overview]]></title>
            <link>https://medium.com/@andilepingo/ml-algorithms-overview-070b36519b39?source=rss-710be3592208------2</link>
            <guid isPermaLink="false">https://medium.com/p/070b36519b39</guid>
            <category><![CDATA[ml-algorithm]]></category>
            <category><![CDATA[machine-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Andile Pingo ]]></dc:creator>
            <pubDate>Wed, 26 Feb 2025 15:46:23 GMT</pubDate>
            <atom:updated>2025-02-26T15:46:23.991Z</atom:updated>
            <content:encoded><![CDATA[<p>Mastering Machine Learning Algorithms: A Beginner-Friendly Guide</p><p>Greetings, todays post is about machine learnings algorithms, a friendly beginner guide. Machine learning (ML) is at the heart of modern AI, powering everything from recommendation systems and fraud detection to self-driving cars and predictive analytics. But behind all the hype lies a fundamental question:</p><p>👉 <strong>Which machine learning algorithm should you use, and when?</strong></p><p>This guide will walk you through the different types of machine learning algorithms, how they work, and real-world examples. By the end, you’ll have a clear understanding of:<br>✅ The main types of ML algorithms (Supervised, Unsupervised)<br>✅ How to choose the right algorithm based on your problem<br>✅ Example implementations in Python</p><p>Let’s dive into the world of ML algorithms! 🔥</p><h3><strong>A️) Supervised Learning: Teaching Machines with Labeled Data</strong></h3><p>Supervised learning is a type of machine learning where the model is trained using <strong>labeled data</strong>. This means the dataset contains both <strong>input features (X)</strong> and <strong>correct output labels (Y)</strong>, allowing the model to learn from past examples and make future predictions.</p><p>Supervised learning is broadly classified into:<br>✅ <strong>Regression</strong> (Predicting continuous values)<br>✅ <strong>Classification</strong> (Predicting discrete labels)</p><p>Let’s break them down with real-world examples and Python implementations. 🚀:</p><h3>1️⃣ Regression: Predicting Continuous Values</h3><p>Regression is used when the output variable is a <strong>continuous numerical value</strong> (e.g., predicting house prices, stock prices, or temperature).</p><h3>📌 Example: Predicting House Prices</h3><p><strong>Scenario:</strong> Suppose you’re a real estate agent, and you want to predict house prices based on features like area, number of bedrooms, and location.</p><p>🔢 Linear Regression Model (Python Example)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q2JcXPwp6gIJEbNDhizQgQ.png" /><figcaption>Creating a linear regression model</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HLd1Qlx2Y74ghqWET-YDuQ.png" /><figcaption>Creating a linear regression model</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ULpMqCtXyH2q0xRwXLY70g.png" /></figure><h3>Interpretation of Linear Regression (Mean Absolute Error: 4.0)</h3><p>📌 <strong>What does Mean Absolute Error (MAE) = 4.0 mean?</strong></p><ul><li>MAE tells us how far, on average, the predicted house prices are from the actual prices.</li><li>An MAE of <strong>4.0</strong> means that, on average, our model’s predictions are off by <strong>$4,000</strong> (since house prices were in thousands).</li></ul><p>✅ <strong>Is this good or bad?</strong></p><ul><li>It depends! If house prices range from <strong>$100,000 to $300,000</strong>, a $4,000 error might be acceptable.</li><li>If you’re working with high-precision pricing, you’d want a lower MAE.</li><li>The goal is to reduce the error by improving the model (e.g., adding more features like location, number of rooms, etc.).</li></ul><h3>📌 When to Use Regression?</h3><p>✅ When predicting a continuous variable (e.g., temperature, sales, stock prices).<br>✅ When understanding trends and relationships between variables.</p><h3>2️⃣ Classification: Predicting Categories</h3><p>Classification is used when the output variable belongs to <strong>distinct categories</strong> (e.g., spam detection, medical diagnosis, or customer segmentation).</p><h3>📌 Example: Email Spam Detection</h3><p><strong>Scenario:</strong> Imagine you’re building a model to classify emails as <strong>spam or not spam</strong> based on features like subject length, the presence of certain words, and sender reputation.</p><h3>🔢 Logistic Regression Model (Python Example)</h3><p>We’ll use <strong>Logistic Regression</strong>, a powerful algorithm for binary classification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8-QWVfHoi4LLSqF8uSJeRw.png" /><figcaption>Building a classification model</figcaption></figure><h3>Interpretation of Classification (Model Accuracy: 50%)</h3><p>📌 <strong>What does 50% accuracy mean?</strong></p><ul><li>The model correctly classifies only <strong>50%</strong> of the test samples.</li><li>This is as good as randomly guessing between two classes (like flipping a coin).</li></ul><p>✅ <strong>Why is accuracy so low?</strong></p><ol><li><strong>Data might not be well-separated</strong> — The features used may not provide enough distinction between classes.</li><li><strong>Class imbalance</strong> — If one class appears more frequently than the other, the model might not learn properly.</li><li><strong>Overfitting or underfitting</strong> — The model might need tuning, more training data, or better preprocessing.</li></ol><p>🚀 <strong>How to Improve It?</strong></p><ul><li>Use more advanced models like <strong>Random Forest, SVM, or Neural Networks</strong>.</li><li>Improve feature engineering (e.g., extracting better data patterns).</li><li>Balance the dataset if there’s an imbalance.</li></ul><p>Here is a summary of supervised algorithms, when to use them, and their examples</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*yKAxDK1YCk7jV4OJZZjSFQ.png" /><figcaption>Supervised algorithms</figcaption></figure><h3>B) Unsupervised Learning: Finding Hidden Patterns Without Labels</h3><p>Unsupervised learning is a type of machine learning where the model is trained on <strong>unlabeled data</strong> — meaning it <strong>doesn’t have predefined output labels</strong> like in supervised learning. Instead, it <strong>finds patterns, structures, or relationships</strong> within the data on its own.</p><h3>🔹 Types of Unsupervised Learning</h3><p>There are two main categories:</p><p>1️⃣ <strong>Clustering</strong> — Grouping similar data points together<br>2️⃣ <strong>Dimensionality Reduction</strong> — Reducing the number of features while keeping important information.</p><p>Let’s dive into each with real-world examples! 🚀</p><p>Clustering is useful when we want to group data points based on similarities. It’s widely used in:<br>✅ <strong>Customer segmentation</strong> (e.g., grouping customers based on buying behavior)<br>✅ <strong>Anomaly detection</strong> (e.g., identifying fraudulent transactions)<br>✅ <strong>Image segmentation</strong> (e.g., separating objects in an image)</p><h3>📌 Example: Customer Segmentation Using K-Means Clustering</h3><p><strong>Scenario:</strong><br>A marketing team wants to segment customers based on their annual income and spending score, so they can target different groups with personalized offers.</p><p>🔢 K-Means Clustering (Python Example)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SRuhJF_gCrZhOjbCQvhwpQ.png" /><figcaption>Customer Segmentation Using K-Means</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dJeMJ3ixniEOc-CnGUEo3Q.png" /></figure><p>✅ <strong>When to Use Clustering?</strong></p><ul><li>When you need to <strong>group similar items together</strong> without predefined categories.</li><li>When analyzing <strong>customer behavior, social networks, or biological data</strong>.</li></ul><h3>2️⃣ Dimensionality Reduction: Simplifying Data Without Losing Information</h3><p>When datasets have <strong>many features (high-dimensional data)</strong>, training machine learning models can become inefficient and slow. <strong>Dimensionality reduction</strong> techniques help by removing unnecessary features while keeping essential patterns.</p><h3>📌 Example: Visualizing High-Dimensional Data with PCA</h3><p><strong>Scenario:</strong><br>Imagine we have customer data with 50+ features. Instead of analyzing all 50 features, we can <strong>reduce</strong> them to <strong>2 or 3 principal components</strong> and visualize the relationships between customers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WHlgnwGVIz8VLj7VK22R5g.png" /><figcaption>PCA</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l2quBGnyweHaPX4Z8QLxWw.png" /><figcaption>PCA Graph</figcaption></figure><p>✅ <strong>When to Use Dimensionality Reduction?</strong></p><ul><li>When dealing with datasets that have <strong>many features</strong> (e.g., gene expression data, image pixels).</li><li>When you want to <strong>visualize</strong> high-dimensional data.</li></ul><p>Here is a summary of unsupervised algorithms, when to use them, and their examples</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ii4dTm9rEyTohABqNHgweg.png" /></figure><h3>🔍 Conclusion: Mastering ML Algorithms</h3><p>We’ve explored the <strong>fundamentals of machine learning algorithms</strong>, covering both <strong>Supervised and Unsupervised Learning</strong> with practical examples. Let’s quickly recap what we’ve learned:</p><h3>📌 Supervised Learning</h3><ul><li>Works with <strong>labeled data</strong>, where the model learns from input-output pairs.</li><li>Used for <strong>classification</strong> (predicting categories) and <strong>regression</strong> (predicting continuous values).</li><li>Examples:</li><li><strong>Classification:</strong> Email spam detection (Spam vs. Not Spam).</li><li><strong>Regression:</strong> Predicting house prices based on historical sales data.</li></ul><h3>📌 Unsupervised Learning</h3><ul><li>Works with <strong>unlabeled data</strong>, where the model finds patterns on its own.</li><li>Used for <strong>clustering</strong> (grouping similar data) and <strong>dimensionality reduction</strong> (simplifying datasets).</li><li>Examples:</li><li><strong>Clustering:</strong> Segmenting customers based on their shopping behavior.</li><li><strong>Dimensionality Reduction:</strong> Reducing a high-dimensional dataset for visualization (PCA).</li></ul><h3>🚀 Key Takeaways</h3><p>✅ <strong>Supervised learning</strong> is great when you have clear labels and need to make predictions.<br>✅ <strong>Unsupervised learning</strong> is useful when you need to explore hidden patterns in raw data.<br>✅ <strong>Choosing the right algorithm</strong> depends on the problem — classification, regression, clustering, or dimensionality reduction.<br>✅ <strong>Improving ML models</strong> involves tuning hyperparameters, feature engineering, and selecting the right evaluation metrics.</p><p>Machine learning is a powerful tool, and understanding its algorithms is just the beginning. The next step? <strong>Experimenting with real datasets, optimizing models, and deploying solutions!</strong> 🚀</p><p>Thank you for taking your precious time to read my lovely post… LOve.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=070b36519b39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Sales Prediction Model with Machine Learning]]></title>
            <link>https://medium.com/@andilepingo/building-a-sales-prediction-model-with-machine-learning-6b64b3d79355?source=rss-710be3592208------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b64b3d79355</guid>
            <category><![CDATA[xgboost]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[model-training]]></category>
            <category><![CDATA[regression-analysis]]></category>
            <dc:creator><![CDATA[Andile Pingo ]]></dc:creator>
            <pubDate>Wed, 19 Feb 2025 12:47:36 GMT</pubDate>
            <atom:updated>2025-02-19T12:47:36.644Z</atom:updated>
            <content:encoded><![CDATA[<p>Greetings to all, I am Andile Pingo. I am an inspiring Machine learning Engineer. I decided to give this blog writing thing a chance, so this is my first blog, please do go through it and advise where I can improve, Kindly appreciated.</p><p>In this blog, we will walk through building a machine learning model that predicts <strong>sales</strong> based on various features, such as <strong>quantity ordered</strong>, <strong>price per item</strong>, and <strong>state</strong>. We will use popular tools like <strong>XGBoost</strong> and <strong>SHAP</strong> to explain the model and interpret its predictions. By the end of this blog, you’ll understand not just how to build and evaluate a model, but also how to explain and trust its predictions.</p><h3>Step 1: Importing Libraries</h3><p>Let’s begin by importing the necessary Python libraries. These libraries will help us with data manipulation, model building, and explainability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ds2DLUuvQ5pQENZkatg_Cg.png" /><figcaption>Loading dataset and visualizing data</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rMhHqwKKaI5PMb48JYmX2A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pAQWIMTiQqhG8C9JYbRuCQ.png" /><figcaption>No missing values</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nwYg8xwo4KhXhZS2ZZgYVg.png" /><figcaption>Data Describe</figcaption></figure><p>In the code above, we start by loading the dataset, followed by a quick overview, including data information and summary statistics. Next, we identify any missing values and duplicate rows before moving on to data visualization.</p><p><strong>Step 2) Feature Engineering</strong></p><p>Feature engineering involves creating new features or transforming existing ones to help the model make better predictions. For example, we can extract the month and day of the week from a date column to give the model more useful information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jdrw25ypUaU3SZu2R3r0Iw.png" /><figcaption>Converting date columns</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2q_s_r6iyEdJpcxEsbJFSw.png" /><figcaption>Creating useful features</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3h4zGEpfjzDLHL4i-Bq_oA.png" /><figcaption>Extracting data</figcaption></figure><p><strong>Feature scaling</strong></p><p>Machine learning models often perform better when features are scaled, especially for distance-based models. For this project, we’ll use <strong>StandardScaler</strong> to scale the features. <strong>Standardization</strong>: Scaling ensures that all features are on the same scale, which helps improve the performance and stability of many models, especially for distance-based algorithms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M5QkeOO5sijmAtPguclw_Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FI4ZEKjetNDurMDkJX_KAA.png" /><figcaption>Feature scaling results.</figcaption></figure><p>As part of our feature engineering process, we started by converting date columns and extracting relevant time-based features. Additionally, we extracted the state information from the purchase address, which could be useful for further exploratory data analysis, such as identifying the states with the highest sales. Finally, we applied feature scaling to ensure all features are on the same scale.</p><h3>Step 3) Model Selection for Sales Prediction</h3><p>We use <strong>XGBoost</strong>, a powerful gradient boosting algorithm, to train the model. This is a robust model that works well for both classification and regression tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-AEctxhMBEXlgJ25h6uEfA.png" /><figcaption>Model Section</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*77haEk3_rFtIHU0NgyXktw.png" /><figcaption>Model Selection 2</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*34VmwYxqHVCB2JCdaurHjA.png" /><figcaption>Model Selection Results</figcaption></figure><h3>Something’s Off — Possible Data Leakage!</h3><p>If all models are scoring 1.0000 R² with 0 error, that’s a 🚨 red flag. This usually means:</p><p>1️⃣ Data Leakage:</p><p>The model is accidentally using information from the target (Total Sales) in the training data. Example: If Total Sales was derived from Quantity Ordered * Price Each, then the model is just memorizing it.</p><p>2️⃣ Overfitting:</p><p>If the dataset is too small, the model might memorize the training data instead of generalizing.</p><p>We can solve this by checking if any feature was directly derived from the target variable (Total Sales) then we move on to Model Explainability</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EwktdhYsAr3pnpG_6EjELQ.png" /><figcaption>Solving Data Leakage</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*szzjsTgrYQ0igOwSG1HaHg.png" /><figcaption>rertaining model</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*34VmwYxqHVCB2JCdaurHjA.png" /><figcaption>results after trained model</figcaption></figure><p>As you can see, we have not solved the problem yet, we still have a perfect model metric, which is too good to be true. Its time to dig deeper into our data and identify more data leakages, worry not we will get to the bottom of this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fB-ZVluGm0f_2u2qdyH7_A.png" /><figcaption>dropping potential leak columns</figcaption></figure><h3>Step 5) Model Explainability</h3><p>Model explainability helps us understand why the model makes certain predictions instead of just trusting it blindly. This is especially important for interpreting patterns, debugging issues, and making trustworthy AI systems.</p><h4>Right now, our model is too perfect (R² = 1.0000), which means it might be overfitting or leaking data. If we use explainability tools, we can:</h4><p>✅ See which features are influencing predictions (like “Is City too dominant?”) ✅ Detect bias or errors (like “Is the model just memorizing instead of learning?”) ✅ Improve transparency when presenting to others (like “Why did the model predict $500 in sales for this order?”)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E9ovbmcok5lDp1LCHYfkAQ.png" /><figcaption>Model explainability using XGBRegressor</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iWcb82G5aFxSMmHmupa3Qw.png" /><figcaption>xgb feature importance</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V7Xr2Z8SRzU-3j0HiEOG6w.png" /></figure><h3>Mean Absolute Error (MAE) Interpretation:</h3><p>That value <strong>(3.08648e-05)</strong> represents the average absolute difference between our predicted and actual values. Since it’s a very small number, it means our model’s predictions are <strong>super close</strong> to the actual sales values. In simpler terms, our model is performing <strong>really well</strong> with minimal error!</p><p>Graph Intepretation</p><ul><li>The model relies heavily on <strong>Price Each</strong> to predict sales.</li><li>In other words, the price of an item has the biggest influence on the total sales.</li><li>This makes sense because <strong>Sales = Price Each × Quantity Ordered</strong> — so the price directly impacts the revenue!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XsfvzVobrGu2naXgvgW3Yw.png" /><figcaption>MSE and R2 score metrics</figcaption></figure><h3>1️⃣ Mean Squared Error (MSE) → 5.49294e-06</h3><p>MSE measures how far the predictions are from the actual values, but it squares the errors, so larger mistakes get <strong>penalized more heavily</strong>. Since our MSE is a <strong>very small number</strong>, it means our model’s predictions are <strong>extremely close</strong> to the real values. Lower MSE = <strong>better model performance</strong>! 🚀</p><h3>2️⃣ R² Score (Coefficient of Determination) → 0.99999453</h3><ul><li>R² measures <strong>how well our model explains the variability in the target variable (sales).</strong></li><li>An R² of <strong>0.99999</strong> means <strong>99.999% of the variation in sales is explained by our model.</strong></li><li>This is <strong>almost a perfect fit</strong> — meaning our model has learned the data patterns extremely well! 🎯</li></ul><p><strong>Final Takeaway:</strong><br>Our model is performing <strong>exceptionally well</strong>, with minimal error and very high predictive accuracy. However, we should <strong>always double-check for overfitting</strong>, especially if the test set also gives a similar R² score.</p><p>Lets also import SHAP tool to help us graph our feature importance and see if it will produce similar results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ud-o9ajR32BsqLBr6C6W0Q.png" /><figcaption>importing shap tool</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*249kWOCxXMrn-p_5zsAR9Q.png" /><figcaption>Shap graph</figcaption></figure><p>Our SHAP graph provides the same insights as the XGBoost feature importance graph, confirming that <strong>Price Each</strong> remains the most influential feature in our model.</p><h3>Conclusion</h3><p>In this blog, we walked through the entire process of building a machine learning model for sales prediction, from loading the data to interpreting the results with SHAP. We saw that <strong>Price Each</strong> was the most important feature in predicting sales, which aligns with what we would expect in a sales forecasting model.</p><ul><li><strong>Model Performance</strong>: With an R² score close to 1, the model performs excellently, meaning it can predict sales accurately.</li><li><strong>Feature Importance</strong>: SHAP helps us trust the model by explaining why certain predictions are made, giving us transparency in machine learning.</li></ul><h3>Next Steps</h3><ul><li><strong>Improving the Model</strong>: You could experiment with different models like Random Forest or XGBoost hyperparameter tuning.</li><li><strong>Dealing with Overfitting</strong>: It might be useful to perform cross-validation and hyperparameter tuning to improve generalization.</li></ul><p>Thank you for spending your valuable time reading my post, highly appreciated. Stay tuned for part 2 of this project, which is pipeline development and MLflow integration</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b64b3d79355" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>