<?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"><channel><title><![CDATA[fraud-detection-end2end]]></title><description><![CDATA[fraud-detection-end2end]]></description><link>https://fraud-detection-end2end.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 25 Nov 2026 08:25:42 GMT</lastBuildDate><atom:link href="https://fraud-detection-end2end.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA["Building a Production-Grade Insurance Fraud Detection System with Streamlit, XGBoost, and MLOps"
slug: insurance-fraud-detection-mlops]]></title><description><![CDATA[excerpt: "Learn how to build a complete fraud detection pipeline using Python, XGBoost, joblib, Streamlit, and MLOps principles. From data preprocessing to…]]></description><link>https://fraud-detection-end2end.hashnode.dev/building-a-production-grade-insurance-fraud-detection-system-with-streamlit-xgboost-and-mlops-slug-insurance-fraud-detection-mlops</link><guid isPermaLink="true">https://fraud-detection-end2end.hashnode.dev/building-a-production-grade-insurance-fraud-detection-system-with-streamlit-xgboost-and-mlops-slug-insurance-fraud-detection-mlops</guid><category><![CDATA[Data Science]]></category><category><![CDATA[Docker]]></category><category><![CDATA[Machine Learning]]></category><category><![CDATA[ML ENGINEERING]]></category><category><![CDATA[fraud detection]]></category><dc:creator><![CDATA[Sanjayram]]></dc:creator><pubDate>Sat, 14 Jun 2025 08:53:15 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/Y0Cy2PmRpnY/upload/5befefad8a47c5c5378048b4469b2742.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<hr />
<p>excerpt: "Learn how to build a complete fraud detection pipeline using Python, XGBoost, joblib, Streamlit, and MLOps principles. From data preprocessing to real-time dashboards—this guide walks you through it all."<br />tags:</p>
<ul>
<li><p>machine-learning</p>
</li>
<li><p>streamlit</p>
</li>
<li><p>data-science</p>
</li>
<li><p>xgboost</p>
</li>
<li><p>mlops</p>
</li>
</ul>
<hr />
<h2 id="heading-introduction">Introduction</h2>
<p>Fraudulent insurance claims cost the industry billions annually. In this blog, we'll dive deep into designing and deploying a <strong>production-grade insurance fraud detection pipeline</strong> using:</p>
<ul>
<li><p><strong>XGBoost</strong> for robust classification</p>
</li>
<li><p><strong>Streamlit</strong> for interactive dashboards</p>
</li>
<li><p><strong>MLOps practices</strong> (modular structure, testing, Docker, CI/CD)</p>
</li>
</ul>
<p>Whether you're an aspiring data scientist or a professional preparing for a FAANG role, this project showcases how to build real-world systems.</p>
<hr />
<h2 id="heading-project-structure">Project Structure</h2>
<pre><code class="lang-plaintext">insurance-fraud-detection/
├── data/                  # Raw and processed datasets
├── models/                # Saved model + scaler (joblib)
├── src/                   # Modular Python scripts (optional if not using direct imports)
├── dashboards/            # Streamlit UI
├── api/                   # FastAPI for REST serving
├── tests/                 # Pytest unit tests
├── requirements.txt       # Dependencies
├── config.yaml            # Config file
├── pyproject.toml         # Linting &amp; formatting
├── Makefile               # CLI workflow automation
├── .gitignore             # Ignore unnecessary files
└── README.md              # Full project overview
</code></pre>
<hr />
<h2 id="heading-dataset-overview">Dataset Overview</h2>
<p>We use a simplified insurance dataset with anonymized features:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td>Description</td></tr>
</thead>
<tbody>
<tr>
<td>age</td><td>Customer's age</td></tr>
<tr>
<td>policy_sales_channel</td><td>Agent or online channel ID</td></tr>
<tr>
<td>gender</td><td>0 = Female, 1 = Male</td></tr>
<tr>
<td>previously_insured</td><td>Has previous insurance? (0/1)</td></tr>
<tr>
<td>vehicle_age</td><td>0 = &lt;1yr, 1 = 1-2yr, 2 = &gt;2yr</td></tr>
<tr>
<td>vehicle_damage</td><td>0 = No, 1 = Yes</td></tr>
<tr>
<td>is_fraud</td><td>Target variable</td></tr>
</tbody>
</table>
</div><hr />
<h2 id="heading-model-building-xgboost-preprocessing">Model Building (XGBoost + Preprocessing)</h2>
<p>We use a <code>Pipeline</code> to ensure feature scaling + model inference are handled together:</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> sklearn.pipeline <span class="hljs-keyword">import</span> Pipeline
<span class="hljs-keyword">from</span> sklearn.preprocessing <span class="hljs-keyword">import</span> StandardScaler
<span class="hljs-keyword">from</span> xgboost <span class="hljs-keyword">import</span> XGBClassifier
<span class="hljs-keyword">import</span> joblib

features = [<span class="hljs-string">'age'</span>, <span class="hljs-string">'policy_sales_channel'</span>, <span class="hljs-string">'gender'</span>, <span class="hljs-string">'previously_insured'</span>,
            <span class="hljs-string">'vehicle_age'</span>, <span class="hljs-string">'vehicle_damage'</span>]

pipeline = Pipeline([
    (<span class="hljs-string">"scaler"</span>, StandardScaler()),
    (<span class="hljs-string">"model"</span>, XGBClassifier(n_estimators=<span class="hljs-number">100</span>, max_depth=<span class="hljs-number">4</span>, random_state=<span class="hljs-number">42</span>))
])

pipeline.fit(X_train[features], y_train)
joblib.dump(pipeline, <span class="hljs-string">"models/final_model.pkl"</span>)
</code></pre>
<p>One file, one artifact—makes deployment clean!</p>
<hr />
<h2 id="heading-streamlit-dashboard-for-real-time-use">Streamlit Dashboard for Real-Time Use</h2>
<p>We use Streamlit to:</p>
<ul>
<li><p>Upload a CSV file or input data manually</p>
</li>
<li><p>Show predictions</p>
</li>
<li><p>Visualize fraud distribution</p>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> streamlit <span class="hljs-keyword">as</span> st
<span class="hljs-keyword">import</span> joblib
<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd

model = joblib.load(<span class="hljs-string">"../models/final_model.pkl"</span>)

user_input = {...}  <span class="hljs-comment"># collected via st.selectbox, etc.</span>
df = pd.DataFrame([user_input])
pred = model.predict(df)
</code></pre>
<p>You get a downloadable fraud probability CSV and a pie chart.</p>
<hr />
<h2 id="heading-testing-with-pytest">Testing with PyTest</h2>
<p>A great project is incomplete without tests:</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_model_prediction</span>():</span>
    model = joblib.load(<span class="hljs-string">"models/final_model.pkl"</span>)
    X_sample = pd.DataFrame([{...}])
    pred = model.predict(X_sample)
    <span class="hljs-keyword">assert</span> pred[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>]
</code></pre>
<hr />
<h2 id="heading-automation-via-makefile">Automation via Makefile</h2>
<pre><code class="lang-makefile"><span class="hljs-section">install:</span>
    pip install -r requirements.txt

<span class="hljs-section">train:</span>
    python src/train_model.py

<span class="hljs-section">dashboard:</span>
    streamlit run dashboards/streamlit_dashboard.py
</code></pre>
<hr />
<h2 id="heading-dockerization-optional-but-pro-level">Dockerization (Optional but Pro-Level)</h2>
<p>Your Dockerfile:</p>
<pre><code class="lang-dockerfile"><span class="hljs-keyword">FROM</span> python:<span class="hljs-number">3.12</span>
<span class="hljs-keyword">WORKDIR</span><span class="bash"> /app</span>
<span class="hljs-keyword">COPY</span><span class="bash"> . .</span>
<span class="hljs-keyword">RUN</span><span class="bash"> pip install -r requirements.txt</span>
<span class="hljs-keyword">CMD</span><span class="bash"> [<span class="hljs-string">"streamlit"</span>, <span class="hljs-string">"run"</span>, <span class="hljs-string">"dashboards/streamlit_dashboard.py"</span>]</span>
</code></pre>
<p>Build and run:</p>
<pre><code class="lang-bash">docker build -t fraud-app .
docker run -p 8501:8501 fraud-app
</code></pre>
<hr />
<h2 id="heading-whats-next-advanced-enhancements">What's Next? Advanced Enhancements</h2>
<ul>
<li><p>✅ CI/CD with GitHub Actions</p>
</li>
<li><p>✅ FastAPI backend for ML inference</p>
</li>
<li><p>✅ Model versioning with MLflow</p>
</li>
<li><p>✅ Data pipeline orchestration with Prefect/Airflow</p>
</li>
<li><p>✅ Feature Store integration</p>
</li>
<li><p>✅ Monitor predictions in production</p>
</li>
</ul>
<hr />
<h2 id="heading-conclusion">Conclusion</h2>
<p>You’ve now built a <strong>complete, production-ready ML system</strong>:</p>
<ul>
<li><p>Clean code</p>
</li>
<li><p>Modular architecture</p>
</li>
<li><p>Tested and deployed with UI</p>
</li>
</ul>
<p>This is the kind of project that grabs attention on your resume, portfolio, or even FAANG interviews.</p>
<hr />
<h2 id="heading-source-code">Source Code</h2>
<p>Everything is available on GitHub:</p>
<p>👉 <a target="_blank" href="https://github.com/SANJAYRAM-DS/fraud-detection-end2end">https://github.com/SANJAYRAM-DS/fraud-detection-end2end</a></p>
<p>Linked-In</p>
<p>👉 <a target="_blank" href="http://www.linkedin.com/in/sanjayram-data">www.linkedin.com/in/sanjayram-data</a></p>
<p>If you liked this, follow me on <a target="_blank" href="https://hashnode.com/@yourprofile">Hashnode</a> and stay tuned for more industry-level ML projects!</p>
<hr />
]]></content:encoded></item></channel></rss>