<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Guillaume Gilles</title>
<link>https://ggilles.dev/</link>
<atom:link href="https://ggilles.dev/index.xml" rel="self" type="application/rss+xml"/>
<description></description>
<generator>quarto-1.4.537</generator>
<lastBuildDate>Mon, 22 Jun 2026 22:00:00 GMT</lastBuildDate>
<item>
  <title>GitHub Codespaces + Quarto</title>
  <link>https://ggilles.dev/posts/github-codespaces-quarto/</link>
  <description><![CDATA[ 




<section id="the-problem-with-local-setup" class="level2">
<h2 class="anchored" data-anchor-id="the-problem-with-local-setup">The problem with local setup</h2>
<p>Every time you start a new project, you go through the same ritual: install the right version of Python, find the right extension for your editor, configure the environment, and debug why it doesn’t work on <em>your</em> local machine. With Quarto, this often means installing the CLI, setting up Jupyter, adding VS Code extensions, and getting the preview server running — before writing a single line.</p>
<p><a href="https://github.com/features/codespaces">GitHub Codespaces</a> solves this by moving the entire development environment into the cloud. You define the environment once as code, and anyone (including future you) can launch a fully configured workspace from a browser in seconds.</p>
<p>Each codespace runs in a <a href="https://www.docker.com/resources/what-container/">Docker container</a> on a GitHub-managed virtual machine. Every personal GitHub account includes <strong>120 core hours of free compute time</strong> and <strong>15 GB of storage per month</strong> — more than enough for writing and publishing. (With the 4-core machine this template requests, that works out to 30 hours of usage per month.)</p>
</section>
<section id="the-template" class="level2">
<h2 class="anchored" data-anchor-id="the-template">The template</h2>
<p>I built a ready-to-use template repository that bundles everything you need to write and publish Quarto documents without installing anything locally. Click the button below to launch it instantly:</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="https://codespaces.new/guillaumegilles/codespaces-quarto"><img src="https://github.com/codespaces/badge.svg" class="img-fluid figure-img" alt="Open in GitHub Codespaces"></a></p>
<figcaption>Open in GitHub Codespaces</figcaption>
</figure>
</div>
<p>When the codespace starts, you get:</p>
<ul>
<li>The <strong>Quarto CLI</strong> (latest), ready to render <code>.qmd</code> files</li>
<li><strong>Python</strong> with <code>jupyter</code>, <code>matplotlib</code>, and <code>plotly</code> pre-installed</li>
<li><strong>VS Code for the web</strong> with the Quarto, Python, and Jupyter extensions</li>
<li>A <strong>live preview</strong> of <code>hello.qmd</code> that opens automatically in the side panel</li>
</ul>
<p>All of this is driven by a single configuration file: <code>.devcontainer/devcontainer.json</code>.</p>
</section>
<section id="walking-through-devcontainer.json" class="level2">
<h2 class="anchored" data-anchor-id="walking-through-devcontainer.json">Walking through <code>devcontainer.json</code></h2>
<p>The <code>.devcontainer/devcontainer.json</code> file is the heart of any Codespaces setup. It tells GitHub exactly what container image to use, what tools to install, and how to configure the editor. Scroll through the story below to see how each piece of this file works.</p>
<div class="cr-section cr-column-screen sidebar-left">
<div class="narrative-col">
<div class="trigger new-trigger" data-focus-on="cr-config-1">
<div class="narrative">
<p>This is the complete <code>.devcontainer/devcontainer.json</code> for this template. Every key plays a specific role — let’s go through them one by one.</p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-config-1" data-highlight="2,4">
<div class="narrative">
<p><strong><code>name</code></strong> is just a human-readable label shown in the Codespaces dashboard. <strong><code>image</code></strong> sets the base container. The Microsoft Ubuntu image is a lean starting point with <code>git</code>, <code>curl</code>, and common shell tools — without the bloat of the universal image.</p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-config-1" data-highlight="6-13">
<div class="narrative">
<p><strong><code>features</code></strong> are the magic of dev containers. Each entry is a self-contained install script that layers on top of the base image. Here we pull in two: the official Python feature (which also sets up <code>pip</code>) and the Rocker project’s Quarto CLI feature (which installs the latest <code>quarto</code> binary). </p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-config-2" data-highlight="4-5">
<div class="narrative">
<p><strong><code>hostRequirements</code></strong> asks GitHub to provision a machine with at least 4 CPU cores. Quarto rendering — especially with Jupyter kernels — benefits from extra CPU headroom, so this prevents the codespace from running on the smallest tier. </p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-config-2" data-highlight="8">
<div class="narrative">
<p><strong><code>waitFor</code></strong> tells the lifecycle to wait until <code>onCreateCommand</code> has finished before running subsequent commands. This ensures the container is fully ready before installing Python packages or starting the preview server. </p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-config-2" data-highlight="9">
<div class="narrative">
<p><strong><code>updateContentCommand</code></strong> runs every time the codespace content is updated (including on creation). Here it installs all Python packages listed in <code>requirements.txt</code> — so adding a dependency to that file is all you need to do to make it available in your codespace. </p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-config-2" data-highlight="10-11">
<div class="narrative">
<p><strong><code>postAttachCommand</code></strong> runs once VS Code connects to the container. The <code>server</code> key starts a <code>quarto preview</code> process in the background, watching <code>hello.qmd</code> and serving a live preview on port 8000. </p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-config-2" data-highlight="13-16">
<div class="narrative">
<p><strong><code>portsAttributes</code></strong> tells Codespaces what to do when port 8000 is open. <code>"onAutoForward": "openPreview"</code> makes the preview appear directly in the VS Code side panel — no copying URLs, no browser tabs. </p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-config-3" data-highlight="1-12">
<div class="narrative">
<p><strong><code>customizations</code></strong> configures the editor itself. The <code>codespaces.openFiles</code> list causes <code>hello.qmd</code> to open automatically when the workspace loads. The <code>vscode.extensions</code> list pre-installs three extensions: <strong>Quarto</strong> for syntax highlighting and rendering commands, <strong>Python</strong> for IntelliSense, and <strong>Jupyter</strong> for running notebook cells inline. </p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-config-3" data-highlight="14">
<div class="narrative">
<p><strong><code>forwardPorts</code></strong> ensures port 8000 is always forwarded to your browser, even if <code>portsAttributes</code> automatic forwarding hasn’t triggered yet. This is the safety net that guarantees the preview is always reachable. </p>
</div>
</div>
</div>
<div class="sticky-col">
<div class="sticky-col-stack">
<div id="cr-config-1" class="sticky">
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode json code-with-copy"><code class="sourceCode json"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb1-2">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"name"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quarto Codespaces"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-3"></span>
<span id="cb1-4">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"image"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mcr.microsoft.com/devcontainers/base:ubuntu"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-5"></span>
<span id="cb1-6">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"features"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb1-7">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"ghcr.io/devcontainers/features/python:1"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb1-8">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"version"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"latest"</span></span>
<span id="cb1-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">},</span></span>
<span id="cb1-10">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"ghcr.io/rocker-org/devcontainer-features/quarto-cli:1"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb1-11">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"version"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"latest"</span></span>
<span id="cb1-12">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb1-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">},</span></span></code></pre></div>
</div>
<div id="cr-config-2" class="sticky">
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode json code-with-copy"><code class="sourceCode json"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb2-2">  <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">…SNIP…</span></span>
<span id="cb2-3"></span>
<span id="cb2-4">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"hostRequirements"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb2-5">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"cpus"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb2-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">},</span></span>
<span id="cb2-7"></span>
<span id="cb2-8">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"waitFor"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"onCreateCommand"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-9">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"updateContentCommand"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"python3 -m pip install -r requirements.txt"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-10">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"postAttachCommand"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb2-11">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"server"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"quarto preview hello.qmd --output-dir _page --no-browser --port 8000"</span></span>
<span id="cb2-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">},</span></span>
<span id="cb2-13">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"portsAttributes"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb2-14">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"8000"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb2-15">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"label"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quarto Preview"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-16">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"onAutoForward"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"openPreview"</span></span>
<span id="cb2-17">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb2-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">},</span></span>
<span id="cb2-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span></code></pre></div>
</div>
<div id="cr-config-3" class="sticky">
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode json code-with-copy"><code class="sourceCode json"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb3-2"></span>
<span id="cb3-3">  <span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">…SNIP…</span></span>
<span id="cb3-4"></span>
<span id="cb3-5">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"customizations"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb3-6">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"codespaces"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb3-7">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"openFiles"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">[</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hello.qmd"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">]</span></span>
<span id="cb3-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">},</span></span>
<span id="cb3-9">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"vscode"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb3-10">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"extensions"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">[</span></span>
<span id="cb3-11">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"quarto.quarto"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-12">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ms-python.python"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-13">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ms-toolsai.jupyter"</span></span>
<span id="cb3-14">      <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">]</span></span>
<span id="cb3-15">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb3-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">},</span></span>
<span id="cb3-17"></span>
<span id="cb3-18">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">"forwardPorts"</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">:</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">[</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8000</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">]</span></span>
<span id="cb3-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">}</span></span></code></pre></div>
</div>
</div>
</div>
</div>
</section>
<section id="using-the-template" class="level2">
<h2 class="anchored" data-anchor-id="using-the-template">Using the template</h2>
<p>The quickest way to get started is to click the badge above. Alternatively, you can use it to seed your own repository:</p>
<ol type="1">
<li>Go to <a href="https://github.com/guillaumegilles/codespaces-quarto">github.com/guillaumegilles/codespaces-quarto</a></li>
<li>Click <strong>“Use this template”</strong> → <strong>“Create a new repository”</strong></li>
<li>Open your new repo and click <strong>“Code”</strong> → <strong>“Codespaces”</strong> → <strong>“Create codespace on main”</strong></li>
</ol>
<p>Within about 90 seconds the container will be built, Python packages installed, and a live Quarto preview will open in your browser — ready to write.</p>
</section>
<section id="going-further" class="level2">
<h2 class="anchored" data-anchor-id="going-further">Going further</h2>
<p>Once you’re comfortable with the template, you can extend it by editing <code>.devcontainer/devcontainer.json</code>:</p>
<ul>
<li><strong>Add R support</strong> by including the <code>ghcr.io/rocker-org/devcontainer-features/r-rig:1</code> feature</li>
<li><strong>Add more Python packages</strong> by editing <code>requirements.txt</code></li>
<li><strong>Pre-install more VS Code extensions</strong> by adding their IDs to the <code>extensions</code> list</li>
<li><strong>Change the base image</strong> to the universal image if you need a wider set of pre-installed runtimes</li>
</ul>
<p>The configuration-as-code approach means any change you commit is instantly available to anyone who opens the repository in a codespace.</p>
</section>
<section id="what-to-expect" class="level2">
<h2 class="anchored" data-anchor-id="what-to-expect">What to expect</h2>
<p>Here is what the codespace looks like once it has finished loading: VS Code on the left with <code>hello.qmd</code> open, and the live Quarto preview rendering a polar plot on the right — no local setup required.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://ggilles.dev/posts/github-codespaces-quarto/preview.png" class="img-fluid figure-img"></p>
<figcaption>VS Code for the web with <code>hello.qmd</code> open and its Quarto preview side by side.</figcaption>
</figure>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
  const toc = document.querySelector('#TOC, .sidebar.toc-left, nav[role="doc-toc"]');
  const crSection = document.querySelector('.cr-section');
  if (!toc || !crSection) return;
  const observer = new IntersectionObserver(([entry]) => {
    toc.style.visibility = entry.isIntersecting ? 'hidden' : 'visible';
    toc.style.opacity    = entry.isIntersecting ? '0'       : '1';
    toc.style.transition = 'opacity 0.2s, visibility 0.2s';
  }, { threshold: 0 });
  observer.observe(crSection);
});
</script>


</section>

 ]]></description>
  <category>Quarto</category>
  <category>GitHub</category>
  <category>Dev Tools</category>
  <guid>https://ggilles.dev/posts/github-codespaces-quarto/</guid>
  <pubDate>Mon, 22 Jun 2026 22:00:00 GMT</pubDate>
  <media:content url="https://ggilles.dev/posts/github-codespaces-quarto/image.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>Évolution de l’inclusion financière des français</title>
  <link>https://ggilles.dev/posts/dataviz-bdf/</link>
  <description><![CDATA[ 




<section id="sec-contexte" class="level2">
<h2 class="anchored" data-anchor-id="sec-contexte">Contexte et problématique</h2>
<p>L’inclusion financière des ménages français est mise à l’épreuve par une série de chocs économiques — chômage, inflation, précarisation — dont l’intensité varie fortement selon les territoires. À l’échelle départementale, certains marchés du travail structurellement fragilisés concentrent aussi les populations les plus exposées au surendettement.</p>
<p><strong>Questions de recherche :</strong></p>
<ol type="1">
<li>Quelles variables économiques départementales (chômage, pauvreté, minimas sociaux, logement, démographie) sont le plus corrélées au taux de surendettement sur la période 2018–2023 ?</li>
<li>Les effets du chômage et de la pauvreté sur le surendettement sont-ils contemporains ou décalés d’une année ?</li>
<li>Peut-on construire un score synthétique de fragilité financière territoriale prédictif du surendettement ?</li>
</ol>
<p><strong>Périmètre :</strong> 96 départements métropolitains (hors DOM-TOM). <strong>Sources :</strong> Banque de France, INSEE FiLoSoFi, INSEE RP 2021, INSEE chômage localisé, DREES (voir Section 2).</p>
<div class="callout callout-style-simple callout-note">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-body-container">
<p><strong>À propos de ce rapport</strong> — L’ensemble des chiffres présentés sont générés programmatiquement à partir de données publiques. Le code source est accessible en cliquant sur « Voir le code » dans chaque section. Les données brutes peuvent être téléchargées en suivant les instructions du <a href="specs/001-surendettement-analysis/quickstart.md">guide de démarrage</a>.</p>
</div>
</div>
</div>
<section id="chiffres-clés" class="level3">
<h3 class="anchored" data-anchor-id="chiffres-clés">Chiffres clés</h3>
<div class="cell" data-execution_count="2">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> IPython.display <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> display</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> DATA_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(df) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>:</span>
<span id="cb1-4">    df_s <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df[df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"annee"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> YEAR_TARGET].copy()</span>
<span id="cb1-5">    kpi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb1-6"></span>
<span id="cb1-7">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> df_s.columns:</span>
<span id="cb1-8">        nb <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_s[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>).dropna()</span>
<span id="cb1-9">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(nb) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>:</span>
<span id="cb1-10">            kpi.append({</span>
<span id="cb1-11">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Indicateur"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total dossiers de surendettement déposés"</span>,</span>
<span id="cb1-12">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Médiane départementale"</span>: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>nb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>median()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.0f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb1-13">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Étendue (min – max)"</span>: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>(nb.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">min</span>())<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> – </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>(nb.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">max</span>())<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb1-14">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Source"</span>: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Banque de France </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb1-15">            })</span>
<span id="cb1-16"></span>
<span id="cb1-17">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> df_s.columns:</span>
<span id="cb1-18">        tx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_s[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span>], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>).dropna()</span>
<span id="cb1-19">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(tx) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> tx.median() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>:</span>
<span id="cb1-20">            kpi.append({</span>
<span id="cb1-21">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Indicateur"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taux de surendettement (‰ ménages)"</span>,</span>
<span id="cb1-22">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Médiane départementale"</span>: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>tx<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>median()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> ‰"</span>,</span>
<span id="cb1-23">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Étendue (min – max)"</span>: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>tx<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">min</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> – </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>tx<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">max</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> ‰"</span>,</span>
<span id="cb1-24">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Source"</span>: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Banque de France </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb1-25">            })</span>
<span id="cb1-26"></span>
<span id="cb1-27">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> df_s.columns:</span>
<span id="cb1-28">        ch <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_s[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux"</span>], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>).dropna()</span>
<span id="cb1-29">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(ch) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>:</span>
<span id="cb1-30">            kpi.append({</span>
<span id="cb1-31">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Indicateur"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taux de chômage BIT"</span>,</span>
<span id="cb1-32">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Médiane départementale"</span>: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>ch<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>median()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> %"</span>,</span>
<span id="cb1-33">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Étendue (min – max)"</span>: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>ch<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">min</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> – </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>ch<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">max</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> %"</span>,</span>
<span id="cb1-34">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Source"</span>: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"INSEE </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb1-35">            })</span>
<span id="cb1-36"></span>
<span id="cb1-37">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"taux_pauvrete"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> df_s.columns:</span>
<span id="cb1-38">        pv <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_s[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"taux_pauvrete"</span>], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>).dropna()</span>
<span id="cb1-39">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(pv) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>:</span>
<span id="cb1-40">            kpi.append({</span>
<span id="cb1-41">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Indicateur"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taux de pauvreté (seuil 60 %)"</span>,</span>
<span id="cb1-42">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Médiane départementale"</span>: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>pv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>median()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> %"</span>,</span>
<span id="cb1-43">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Étendue (min – max)"</span>: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>pv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">min</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> – </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>pv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">max</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> %"</span>,</span>
<span id="cb1-44">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Source"</span>: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"INSEE FiLoSoFi </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_FILOSOFI<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb1-45">            })</span>
<span id="cb1-46"></span>
<span id="cb1-47">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rsa_taux"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> df_s.columns:</span>
<span id="cb1-48">        rsa <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_s[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rsa_taux"</span>], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>).dropna()</span>
<span id="cb1-49">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(rsa) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>:</span>
<span id="cb1-50">            kpi.append({</span>
<span id="cb1-51">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Indicateur"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Part d'allocataires RSA"</span>,</span>
<span id="cb1-52">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Médiane départementale"</span>: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>rsa<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>median()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> %"</span>,</span>
<span id="cb1-53">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Étendue (min – max)"</span>: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>rsa<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">min</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> – </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>rsa<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">max</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> %"</span>,</span>
<span id="cb1-54">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Source"</span>: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"DREES </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb1-55">            })</span>
<span id="cb1-56"></span>
<span id="cb1-57">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> kpi:</span>
<span id="cb1-58">        kpi_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame(kpi)</span>
<span id="cb1-59">        display(kpi_df.style.hide(axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"index"</span>).set_properties(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-align"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>}))</span>
<span id="cb1-60">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb1-61">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Données insuffisantes — exécuter les scripts 01–04 d'abord."</span>)</span>
<span id="cb1-62"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb1-63">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Données non disponibles — exécuter les scripts 01–04 d'abord."</span>)</span></code></pre></div>
</details>
<div id="tbl-kpi" class="cell quarto-float anchored" data-execution_count="2">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-kpi-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1: Statistiques descriptives clés — France métropolitaine (année de référence)
</figcaption>
<div aria-describedby="tbl-kpi-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output cell-output-display">
<style type="text/css">
#T_fdf8a_row0_col0, #T_fdf8a_row0_col1, #T_fdf8a_row0_col2, #T_fdf8a_row0_col3, #T_fdf8a_row1_col0, #T_fdf8a_row1_col1, #T_fdf8a_row1_col2, #T_fdf8a_row1_col3, #T_fdf8a_row2_col0, #T_fdf8a_row2_col1, #T_fdf8a_row2_col2, #T_fdf8a_row2_col3, #T_fdf8a_row3_col0, #T_fdf8a_row3_col1, #T_fdf8a_row3_col2, #T_fdf8a_row3_col3, #T_fdf8a_row4_col0, #T_fdf8a_row4_col1, #T_fdf8a_row4_col2, #T_fdf8a_row4_col3 {
  text-align: left;
}
</style>

<table id="T_fdf8a" class="do-not-create-environment cell table table-sm table-striped small" data-quarto-postprocess="true">
<thead>
<tr class="header">
<th id="T_fdf8a_level0_col0" class="col_heading level0 col0" data-quarto-table-cell-role="th">Indicateur</th>
<th id="T_fdf8a_level0_col1" class="col_heading level0 col1" data-quarto-table-cell-role="th">Médiane départementale</th>
<th id="T_fdf8a_level0_col2" class="col_heading level0 col2" data-quarto-table-cell-role="th">Étendue (min – max)</th>
<th id="T_fdf8a_level0_col3" class="col_heading level0 col3" data-quarto-table-cell-role="th">Source</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td id="T_fdf8a_row0_col0" class="data row0 col0">Total dossiers de surendettement déposés</td>
<td id="T_fdf8a_row0_col1" class="data row0 col1">1128</td>
<td id="T_fdf8a_row0_col2" class="data row0 col2">82 – 8329</td>
<td id="T_fdf8a_row0_col3" class="data row0 col3">Banque de France 2024</td>
</tr>
<tr class="even">
<td id="T_fdf8a_row1_col0" class="data row1 col0">Taux de surendettement (‰ ménages)</td>
<td id="T_fdf8a_row1_col1" class="data row1 col1">20.9 ‰</td>
<td id="T_fdf8a_row1_col2" class="data row1 col2">10.7 – 37.4 ‰</td>
<td id="T_fdf8a_row1_col3" class="data row1 col3">Banque de France 2024</td>
</tr>
<tr class="odd">
<td id="T_fdf8a_row2_col0" class="data row2 col0">Taux de chômage BIT</td>
<td id="T_fdf8a_row2_col1" class="data row2 col1">6.8 %</td>
<td id="T_fdf8a_row2_col2" class="data row2 col2">4.2 – 12.0 %</td>
<td id="T_fdf8a_row2_col3" class="data row2 col3">INSEE 2024</td>
</tr>
<tr class="even">
<td id="T_fdf8a_row3_col0" class="data row3 col0">Taux de pauvreté (seuil 60 %)</td>
<td id="T_fdf8a_row3_col1" class="data row3 col1">15.6 %</td>
<td id="T_fdf8a_row3_col2" class="data row3 col2">9.2 – 29.5 %</td>
<td id="T_fdf8a_row3_col3" class="data row3 col3">INSEE FiLoSoFi 2024</td>
</tr>
<tr class="odd">
<td id="T_fdf8a_row4_col0" class="data row4 col0">Part d'allocataires RSA</td>
<td id="T_fdf8a_row4_col1" class="data row4 col1">23.3 %</td>
<td id="T_fdf8a_row4_col2" class="data row4 col2">9.4 – 52.6 %</td>
<td id="T_fdf8a_row4_col3" class="data row4 col3">DREES 2024</td>
</tr>
</tbody>
</table>
</div>
</div>
</figure>
</div>
</div>
<hr>
</section>
</section>
<section id="sec-sources" class="level2">
<h2 class="anchored" data-anchor-id="sec-sources">Sources de données</h2>
<p>Cette analyse mobilise six sources de données publiques, toutes téléchargeables et reproductibles. Le tableau ci-dessous recense chaque source, les indicateurs retenus, le millésime de référence et la couverture géographique. Les données brutes sont stockées dans <code>data/raw/</code> (non versionnées) et retraitées par les scripts <code>02_clean.py</code> et <code>03_merge.py</code> avant d’être intégrées dans le jeu analytique (<code>analytical_dataset.csv</code>).</p>
<div class="cell" data-execution_count="3">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1">sources <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame({</span>
<span id="cb2-2">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Source"</span>: [</span>
<span id="cb2-3">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Banque de France — Synthèses surendettement"</span>,</span>
<span id="cb2-4">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"INSEE FiLoSoFi 2021"</span>,</span>
<span id="cb2-5">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"INSEE FiLoSoFi SUPRA 2019"</span>,</span>
<span id="cb2-6">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"INSEE Chômage localisé (TCRD)"</span>,</span>
<span id="cb2-7">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"INSEE Recensement (RP 2021)"</span>,</span>
<span id="cb2-8">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DREES / France Travail — Minimas sociaux"</span>,</span>
<span id="cb2-9">    ],</span>
<span id="cb2-10">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Indicateurs"</span>: [</span>
<span id="cb2-11">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dépôts de dossiers de surendettement"</span>,</span>
<span id="cb2-12">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Revenu médian UC, taux de pauvreté (60 %), interdécile D9/D1"</span>,</span>
<span id="cb2-13">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Coefficient de Gini"</span>,</span>
<span id="cb2-14">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taux de chômage BIT par département"</span>,</span>
<span id="cb2-15">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Structure ménages, logement, démographie"</span>,</span>
<span id="cb2-16">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"RSA, prime d'activité, ASS/ASPA"</span>,</span>
<span id="cb2-17">    ],</span>
<span id="cb2-18">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Millésime(s)"</span>: [</span>
<span id="cb2-19">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2018–2023"</span>,</span>
<span id="cb2-20">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,</span>
<span id="cb2-21">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2019"</span>,</span>
<span id="cb2-22">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2017–2024"</span>,</span>
<span id="cb2-23">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,</span>
<span id="cb2-24">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,</span>
<span id="cb2-25">    ],</span>
<span id="cb2-26">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Périmètre"</span>: [</span>
<span id="cb2-27">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"96 dép."</span>,</span>
<span id="cb2-28">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"96 dép."</span>,</span>
<span id="cb2-29">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"96 dép. (couverture ~20 %)"</span>,</span>
<span id="cb2-30">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"96 dép."</span>,</span>
<span id="cb2-31">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"96 dép."</span>,</span>
<span id="cb2-32">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"96 dép. (si disponible)"</span>,</span>
<span id="cb2-33">    ],</span>
<span id="cb2-34">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Identifiant / URL"</span>: [</span>
<span id="cb2-35">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"banque-france.fr/publications/synthese-nationale…"</span>,</span>
<span id="cb2-36">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"insee.fr/statistiques/7756729"</span>,</span>
<span id="cb2-37">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"insee.fr/statistiques/6036907"</span>,</span>
<span id="cb2-38">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"insee.fr/statistiques/2012804"</span>,</span>
<span id="cb2-39">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"insee.fr/statistiques/8268828"</span>,</span>
<span id="cb2-40">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drees.solidarites-sante.gouv.fr/isd"</span>,</span>
<span id="cb2-41">    ],</span>
<span id="cb2-42">})</span>
<span id="cb2-43"></span>
<span id="cb2-44"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Affichage HTML</span></span>
<span id="cb2-45">sources.style.set_properties(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-align"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>}).hide(axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"index"</span>)</span></code></pre></div>
</details>
<div id="tbl-sources-table" class="cell quarto-float anchored" data-execution_count="3">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-sources-table-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;2: Sources de données utilisées dans l’analyse
</figcaption>
<div aria-describedby="tbl-sources-table-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output cell-output-display" data-execution_count="3">
<style type="text/css">
#T_bd15f_row0_col0, #T_bd15f_row0_col1, #T_bd15f_row0_col2, #T_bd15f_row0_col3, #T_bd15f_row0_col4, #T_bd15f_row1_col0, #T_bd15f_row1_col1, #T_bd15f_row1_col2, #T_bd15f_row1_col3, #T_bd15f_row1_col4, #T_bd15f_row2_col0, #T_bd15f_row2_col1, #T_bd15f_row2_col2, #T_bd15f_row2_col3, #T_bd15f_row2_col4, #T_bd15f_row3_col0, #T_bd15f_row3_col1, #T_bd15f_row3_col2, #T_bd15f_row3_col3, #T_bd15f_row3_col4, #T_bd15f_row4_col0, #T_bd15f_row4_col1, #T_bd15f_row4_col2, #T_bd15f_row4_col3, #T_bd15f_row4_col4, #T_bd15f_row5_col0, #T_bd15f_row5_col1, #T_bd15f_row5_col2, #T_bd15f_row5_col3, #T_bd15f_row5_col4 {
  text-align: left;
}
</style>

<table id="T_bd15f" class="do-not-create-environment cell table table-sm table-striped small" data-quarto-postprocess="true">
<thead>
<tr class="header">
<th id="T_bd15f_level0_col0" class="col_heading level0 col0" data-quarto-table-cell-role="th">Source</th>
<th id="T_bd15f_level0_col1" class="col_heading level0 col1" data-quarto-table-cell-role="th">Indicateurs</th>
<th id="T_bd15f_level0_col2" class="col_heading level0 col2" data-quarto-table-cell-role="th">Millésime(s)</th>
<th id="T_bd15f_level0_col3" class="col_heading level0 col3" data-quarto-table-cell-role="th">Périmètre</th>
<th id="T_bd15f_level0_col4" class="col_heading level0 col4" data-quarto-table-cell-role="th">Identifiant / URL</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td id="T_bd15f_row0_col0" class="data row0 col0">Banque de France — Synthèses surendettement</td>
<td id="T_bd15f_row0_col1" class="data row0 col1">Dépôts de dossiers de surendettement</td>
<td id="T_bd15f_row0_col2" class="data row0 col2">2018–2023</td>
<td id="T_bd15f_row0_col3" class="data row0 col3">96 dép.</td>
<td id="T_bd15f_row0_col4" class="data row0 col4">banque-france.fr/publications/synthese-nationale…</td>
</tr>
<tr class="even">
<td id="T_bd15f_row1_col0" class="data row1 col0">INSEE FiLoSoFi 2021</td>
<td id="T_bd15f_row1_col1" class="data row1 col1">Revenu médian UC, taux de pauvreté (60 %), interdécile D9/D1</td>
<td id="T_bd15f_row1_col2" class="data row1 col2">2021</td>
<td id="T_bd15f_row1_col3" class="data row1 col3">96 dép.</td>
<td id="T_bd15f_row1_col4" class="data row1 col4">insee.fr/statistiques/7756729</td>
</tr>
<tr class="odd">
<td id="T_bd15f_row2_col0" class="data row2 col0">INSEE FiLoSoFi SUPRA 2019</td>
<td id="T_bd15f_row2_col1" class="data row2 col1">Coefficient de Gini</td>
<td id="T_bd15f_row2_col2" class="data row2 col2">2019</td>
<td id="T_bd15f_row2_col3" class="data row2 col3">96 dép. (couverture ~20 %)</td>
<td id="T_bd15f_row2_col4" class="data row2 col4">insee.fr/statistiques/6036907</td>
</tr>
<tr class="even">
<td id="T_bd15f_row3_col0" class="data row3 col0">INSEE Chômage localisé (TCRD)</td>
<td id="T_bd15f_row3_col1" class="data row3 col1">Taux de chômage BIT par département</td>
<td id="T_bd15f_row3_col2" class="data row3 col2">2017–2024</td>
<td id="T_bd15f_row3_col3" class="data row3 col3">96 dép.</td>
<td id="T_bd15f_row3_col4" class="data row3 col4">insee.fr/statistiques/2012804</td>
</tr>
<tr class="odd">
<td id="T_bd15f_row4_col0" class="data row4 col0">INSEE Recensement (RP 2021)</td>
<td id="T_bd15f_row4_col1" class="data row4 col1">Structure ménages, logement, démographie</td>
<td id="T_bd15f_row4_col2" class="data row4 col2">2021</td>
<td id="T_bd15f_row4_col3" class="data row4 col3">96 dép.</td>
<td id="T_bd15f_row4_col4" class="data row4 col4">insee.fr/statistiques/8268828</td>
</tr>
<tr class="even">
<td id="T_bd15f_row5_col0" class="data row5 col0">DREES / France Travail — Minimas sociaux</td>
<td id="T_bd15f_row5_col1" class="data row5 col1">RSA, prime d'activité, ASS/ASPA</td>
<td id="T_bd15f_row5_col2" class="data row5 col2">2021</td>
<td id="T_bd15f_row5_col3" class="data row5 col3">96 dép. (si disponible)</td>
<td id="T_bd15f_row5_col4" class="data row5 col4">drees.solidarites-sante.gouv.fr/isd</td>
</tr>
</tbody>
</table>
</div>
</div>
</figure>
</div>
</div>
<blockquote class="blockquote">
<p><strong>Note</strong> : Les données brutes (<code>data/raw/</code>) ne sont pas versionnées. Consulter <a href="specs/001-surendettement-analysis/quickstart.md"><code>quickstart.md</code></a> pour les instructions de téléchargement.</p>
</blockquote>
<hr>
</section>
<section id="sec-couverture" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="sec-couverture">Couverture des données</h2>
<p>Avant d’interpréter les résultats, il est indispensable de s’assurer que les données couvrent suffisamment les 96 départements. Le graphique ci-dessous indique, pour chaque variable analytique, le pourcentage de valeurs disponibles (non manquantes). Une couverture inférieure à 90 % (seuil rouge pointillé) appelle à la prudence : les variables concernées ne peuvent pas être incluses dans un modèle de régression sans risque de biais de sélection.</p>
<div class="callout callout-style-simple callout-warning">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-body-container">
<p>Le coefficient de <strong>Gini</strong> (FiLoSoFi SUPRA 2019) présente une couverture volontairement limitée à environ 20 % — il n’est disponible que pour les grandes unités territoriales et n’est donc pas intégré dans le modèle OLS principal.</p>
</div>
</div>
</div>
<div id="cell-fig-couverture-plot" class="cell page-columns page-full" data-execution_count="4">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> DATA_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">not</span> coverage.empty:</span>
<span id="cb3-2">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Sélectionner les variables analytiques (exclure métadonnées)</span></span>
<span id="cb3-3">    meta_cols <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_code"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_nom"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reg_code"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"annee"</span>,</span>
<span id="cb3-4">                 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"source_url"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"source_millesime"</span>}</span>
<span id="cb3-5">    cov_plot <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> coverage[<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>coverage[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variable"</span>].isin(meta_cols)].copy()</span>
<span id="cb3-6">    cov_plot <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> cov_plot.sort_values(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coverage_pct"</span>, ascending<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb3-7"></span>
<span id="cb3-8">    fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">max</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(cov_plot) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>)))</span>
<span id="cb3-9">    colors <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb3-10">        _PHOSPHOR <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> row[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coverage_pct"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span></span>
<span id="cb3-11">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> (_AMBER <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> row[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coverage_pct"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> _RED)</span>
<span id="cb3-12">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> _, row <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> cov_plot.iterrows()</span>
<span id="cb3-13">    ]</span>
<span id="cb3-14">    bars <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax.barh(cov_plot[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variable"</span>], cov_plot[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coverage_pct"</span>],</span>
<span id="cb3-15">                   color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>colors, edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, height<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>)</span>
<span id="cb3-16">    ax.axvline(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_CHALK_DIM, linestyle<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"--"</span>, linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb3-17">               label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Seuil 90 %"</span>, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>)</span>
<span id="cb3-18">    ax.set_xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Couverture (%)"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb3-19">    ax.set_title(</span>
<span id="cb3-20">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Couverture des variables analytiques</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb3-21">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(vert ≥ 90 %, orange ≥ 50 %, rouge &lt; 50 %)"</span>,</span>
<span id="cb3-22">        fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>, fontweight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span></span>
<span id="cb3-23">    )</span>
<span id="cb3-24">    ax.set_xlim(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">110</span>)</span>
<span id="cb3-25">    ax.legend(fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>)</span>
<span id="cb3-26">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> bar, val <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">zip</span>(bars, cov_plot[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coverage_pct"</span>]):</span>
<span id="cb3-27">        ax.text(bar.get_width() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, bar.get_y() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> bar.get_height() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb3-28">                <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>val<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.0f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">%"</span>, va<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)</span>
<span id="cb3-29">    fig.text(</span>
<span id="cb3-30">        <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>,</span>
<span id="cb3-31">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Source : calcul auteur d'après analytical_dataset.csv. "</span></span>
<span id="cb3-32">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Le Gini (FiLoSoFi SUPRA 2019) a une couverture ~20 % par construction."</span>,</span>
<span id="cb3-33">        ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"italic"</span></span>
<span id="cb3-34">    )</span>
<span id="cb3-35">    plt.tight_layout()</span>
<span id="cb3-36">    plt.show()</span>
<span id="cb3-37"></span>
<span id="cb3-38"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">elif</span> DATA_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> coverage.empty:</span>
<span id="cb3-39">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Calculer directement depuis le dataset</span></span>
<span id="cb3-40">    meta_cols <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_code"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_nom"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reg_code"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"annee"</span>}</span>
<span id="cb3-41">    cov_direct <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (df.notna().mean() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>).reset_index()</span>
<span id="cb3-42">    cov_direct.columns <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variable"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coverage_pct"</span>]</span>
<span id="cb3-43">    cov_direct <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> cov_direct[<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>cov_direct[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variable"</span>].isin(meta_cols)]</span>
<span id="cb3-44">    cov_direct <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> cov_direct.sort_values(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coverage_pct"</span>, ascending<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb3-45"></span>
<span id="cb3-46">    fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">max</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(cov_direct) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>)))</span>
<span id="cb3-47">    ax.barh(cov_direct[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variable"</span>], cov_direct[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coverage_pct"</span>],</span>
<span id="cb3-48">            color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_CYAN, edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb3-49">    ax.axvline(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_RED, linestyle<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"--"</span>, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Seuil 90 %"</span>)</span>
<span id="cb3-50">    ax.set_xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Couverture (%)"</span>)</span>
<span id="cb3-51">    ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Couverture des variables (calculée depuis analytical_dataset.csv)"</span>)</span>
<span id="cb3-52">    ax.legend()</span>
<span id="cb3-53">    plt.tight_layout()</span>
<span id="cb3-54">    plt.show()</span>
<span id="cb3-55"></span>
<span id="cb3-56"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb3-57">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Données non disponibles — exécuter les scripts 01-04 d'abord."</span>)</span>
<span id="cb3-58">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"   python scripts/01_download.py"</span>)</span>
<span id="cb3-59">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"   python scripts/02_clean.py"</span>)</span>
<span id="cb3-60">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"   python scripts/03_merge.py"</span>)</span>
<span id="cb3-61">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"   python scripts/04_validate.py"</span>)</span></code></pre></div>
</details>
<div class="cell-output cell-output-display page-columns page-full">
<div id="fig-couverture-plot" class="quarto-figure quarto-figure-center quarto-float anchored page-columns page-full" alt="Graphique en barres horizontales montrant le pourcentage de couverture de chaque variable analytique. Les variables principales dépassent 90 % ; le Gini est à ~20 % par construction.">
<figure class="quarto-float quarto-float-fig figure page-columns page-full">
<div aria-describedby="fig-couverture-plot-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca" class="page-columns page-full">
<img src="https://ggilles.dev/posts/dataviz-bdf/index_files/figure-html/fig-couverture-plot-output-1.png" class="img-fluid figure-img column-page" alt="Graphique en barres horizontales montrant le pourcentage de couverture de chaque variable analytique. Les variables principales dépassent 90 % ; le Gini est à ~20 % par construction.">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-couverture-plot-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Couverture des variables clés du jeu analytique (% de valeurs non-nulles)
</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell" data-execution_count="5">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> IPython.display <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> display</span>
<span id="cb4-2"></span>
<span id="cb4-3"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> COVERAGE_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">not</span> coverage.empty:</span>
<span id="cb4-4">    meta_cols <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_code"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_nom"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reg_code"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"annee"</span>}</span>
<span id="cb4-5">    cov_display <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> coverage[<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>coverage[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variable"</span>].isin(meta_cols)][</span>
<span id="cb4-6">        [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variable"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coverage_pct"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"threshold_pct"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"status"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"min"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"max"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"median"</span>]</span>
<span id="cb4-7">    ].copy()</span>
<span id="cb4-8">    cov_display[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coverage_pct"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> cov_display[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coverage_pct"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">apply</span>(</span>
<span id="cb4-9">        <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">lambda</span> x: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">%"</span></span>
<span id="cb4-10">    )</span>
<span id="cb4-11">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Mise en évidence des avertissements</span></span>
<span id="cb4-12">    <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">def</span> highlight_status(val):</span>
<span id="cb4-13">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WARNING"</span>:</span>
<span id="cb4-14">            <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"background-color: #ffe0b2"</span></span>
<span id="cb4-15">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">elif</span> val.startswith(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OK"</span>):</span>
<span id="cb4-16">            <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"background-color: #e8f5e9"</span></span>
<span id="cb4-17">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span></span>
<span id="cb4-18"></span>
<span id="cb4-19">    display(cov_display.style.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">map</span>(</span>
<span id="cb4-20">        highlight_status, subset<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"status"</span>]</span>
<span id="cb4-21">    ).hide(axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"index"</span>))</span>
<span id="cb4-22"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">elif</span> DATA_AVAILABLE:</span>
<span id="cb4-23">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ℹ️  Exécuter scripts/04_validate.py pour le rapport détaillé."</span>)</span></code></pre></div>
</details>
<div id="tbl-couverture-table" class="cell quarto-float anchored" data-execution_count="5">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-couverture-table-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;3: Rapport de couverture détaillé par variable
</figcaption>
<div aria-describedby="tbl-couverture-table-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output cell-output-display">
<style type="text/css">
#T_e9417_row0_col3, #T_e9417_row1_col3, #T_e9417_row2_col3, #T_e9417_row3_col3, #T_e9417_row4_col3, #T_e9417_row5_col3, #T_e9417_row6_col3, #T_e9417_row7_col3, #T_e9417_row8_col3, #T_e9417_row9_col3, #T_e9417_row10_col3, #T_e9417_row11_col3, #T_e9417_row12_col3, #T_e9417_row13_col3, #T_e9417_row14_col3, #T_e9417_row15_col3, #T_e9417_row16_col3, #T_e9417_row17_col3, #T_e9417_row18_col3, #T_e9417_row19_col3, #T_e9417_row20_col3, #T_e9417_row21_col3, #T_e9417_row22_col3 {
  background-color: #e8f5e9;
}
</style>

<table id="T_e9417" class="do-not-create-environment cell table table-sm table-striped small" data-quarto-postprocess="true">
<thead>
<tr class="header">
<th id="T_e9417_level0_col0" class="col_heading level0 col0" data-quarto-table-cell-role="th">variable</th>
<th id="T_e9417_level0_col1" class="col_heading level0 col1" data-quarto-table-cell-role="th">coverage_pct</th>
<th id="T_e9417_level0_col2" class="col_heading level0 col2" data-quarto-table-cell-role="th">threshold_pct</th>
<th id="T_e9417_level0_col3" class="col_heading level0 col3" data-quarto-table-cell-role="th">status</th>
<th id="T_e9417_level0_col4" class="col_heading level0 col4" data-quarto-table-cell-role="th">min</th>
<th id="T_e9417_level0_col5" class="col_heading level0 col5" data-quarto-table-cell-role="th">max</th>
<th id="T_e9417_level0_col6" class="col_heading level0 col6" data-quarto-table-cell-role="th">median</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td id="T_e9417_row0_col0" class="data row0 col0">suren_depot_nb</td>
<td id="T_e9417_row0_col1" class="data row0 col1">100.0%</td>
<td id="T_e9417_row0_col2" class="data row0 col2">90.000000</td>
<td id="T_e9417_row0_col3" class="data row0 col3">OK</td>
<td id="T_e9417_row0_col4" class="data row0 col4">62.000000</td>
<td id="T_e9417_row0_col5" class="data row0 col5">8848.000000</td>
<td id="T_e9417_row0_col6" class="data row0 col6">1018.500000</td>
</tr>
<tr class="even">
<td id="T_e9417_row1_col0" class="data row1 col0">suren_depot_taux</td>
<td id="T_e9417_row1_col1" class="data row1 col1">100.0%</td>
<td id="T_e9417_row1_col2" class="data row1 col2">90.000000</td>
<td id="T_e9417_row1_col3" class="data row1 col3">OK</td>
<td id="T_e9417_row1_col4" class="data row1 col4">8.104000</td>
<td id="T_e9417_row1_col5" class="data row1 col5">38.742000</td>
<td id="T_e9417_row1_col6" class="data row1 col6">18.727000</td>
</tr>
<tr class="odd">
<td id="T_e9417_row2_col0" class="data row2 col0">revenu_median_uc</td>
<td id="T_e9417_row2_col1" class="data row2 col1">100.0%</td>
<td id="T_e9417_row2_col2" class="data row2 col2">90.000000</td>
<td id="T_e9417_row2_col3" class="data row2 col3">OK</td>
<td id="T_e9417_row2_col4" class="data row2 col4">21250.000000</td>
<td id="T_e9417_row2_col5" class="data row2 col5">33790.000000</td>
<td id="T_e9417_row2_col6" class="data row2 col6">25140.000000</td>
</tr>
<tr class="even">
<td id="T_e9417_row3_col0" class="data row3 col0">taux_pauvrete</td>
<td id="T_e9417_row3_col1" class="data row3 col1">100.0%</td>
<td id="T_e9417_row3_col2" class="data row3 col2">90.000000</td>
<td id="T_e9417_row3_col3" class="data row3 col3">OK</td>
<td id="T_e9417_row3_col4" class="data row3 col4">9.200000</td>
<td id="T_e9417_row3_col5" class="data row3 col5">29.500000</td>
<td id="T_e9417_row3_col6" class="data row3 col6">15.600000</td>
</tr>
<tr class="odd">
<td id="T_e9417_row4_col0" class="data row4 col0">interdecile_d9d1</td>
<td id="T_e9417_row4_col1" class="data row4 col1">100.0%</td>
<td id="T_e9417_row4_col2" class="data row4 col2">90.000000</td>
<td id="T_e9417_row4_col3" class="data row4 col3">OK</td>
<td id="T_e9417_row4_col4" class="data row4 col4">2.500000</td>
<td id="T_e9417_row4_col5" class="data row4 col5">6.700000</td>
<td id="T_e9417_row4_col6" class="data row4 col6">3.100000</td>
</tr>
<tr class="even">
<td id="T_e9417_row5_col0" class="data row5 col0">gini</td>
<td id="T_e9417_row5_col1" class="data row5 col1">100.0%</td>
<td id="T_e9417_row5_col2" class="data row5 col2">0.000000</td>
<td id="T_e9417_row5_col3" class="data row5 col3">OK</td>
<td id="T_e9417_row5_col4" class="data row5 col4">0.225000</td>
<td id="T_e9417_row5_col5" class="data row5 col5">0.451000</td>
<td id="T_e9417_row5_col6" class="data row5 col6">0.260000</td>
</tr>
<tr class="odd">
<td id="T_e9417_row6_col0" class="data row6 col0">chomage_taux</td>
<td id="T_e9417_row6_col1" class="data row6 col1">100.0%</td>
<td id="T_e9417_row6_col2" class="data row6 col2">90.000000</td>
<td id="T_e9417_row6_col3" class="data row6 col3">OK</td>
<td id="T_e9417_row6_col4" class="data row6 col4">4.200000</td>
<td id="T_e9417_row6_col5" class="data row6 col5">12.000000</td>
<td id="T_e9417_row6_col6" class="data row6 col6">6.750000</td>
</tr>
<tr class="even">
<td id="T_e9417_row7_col0" class="data row7 col0">chomage_taux_t1</td>
<td id="T_e9417_row7_col1" class="data row7 col1">83.3%</td>
<td id="T_e9417_row7_col2" class="data row7 col2">50.000000</td>
<td id="T_e9417_row7_col3" class="data row7 col3">OK</td>
<td id="T_e9417_row7_col4" class="data row7 col4">4.200000</td>
<td id="T_e9417_row7_col5" class="data row7 col5">12.000000</td>
<td id="T_e9417_row7_col6" class="data row7 col6">6.750000</td>
</tr>
<tr class="odd">
<td id="T_e9417_row8_col0" class="data row8 col0">rsa_taux</td>
<td id="T_e9417_row8_col1" class="data row8 col1">100.0%</td>
<td id="T_e9417_row8_col2" class="data row8 col2">50.000000</td>
<td id="T_e9417_row8_col3" class="data row8 col3">OK</td>
<td id="T_e9417_row8_col4" class="data row8 col4">8.792000</td>
<td id="T_e9417_row8_col5" class="data row8 col5">54.545000</td>
<td id="T_e9417_row8_col6" class="data row8 col6">23.753000</td>
</tr>
<tr class="even">
<td id="T_e9417_row9_col0" class="data row9 col0">prime_activite_taux</td>
<td id="T_e9417_row9_col1" class="data row9 col1">100.0%</td>
<td id="T_e9417_row9_col2" class="data row9 col2">50.000000</td>
<td id="T_e9417_row9_col3" class="data row9 col3">OK</td>
<td id="T_e9417_row9_col4" class="data row9 col4">40.867000</td>
<td id="T_e9417_row9_col5" class="data row9 col5">95.159000</td>
<td id="T_e9417_row9_col6" class="data row9 col6">71.247000</td>
</tr>
<tr class="odd">
<td id="T_e9417_row10_col0" class="data row10 col0">ass_aspa_taux</td>
<td id="T_e9417_row10_col1" class="data row10 col1">100.0%</td>
<td id="T_e9417_row10_col2" class="data row10 col2">50.000000</td>
<td id="T_e9417_row10_col3" class="data row10 col3">OK</td>
<td id="T_e9417_row10_col4" class="data row10 col4">1.752000</td>
<td id="T_e9417_row10_col5" class="data row10 col5">8.949000</td>
<td id="T_e9417_row10_col6" class="data row10 col6">3.946000</td>
</tr>
<tr class="even">
<td id="T_e9417_row11_col0" class="data row11 col0">population_mun</td>
<td id="T_e9417_row11_col1" class="data row11 col1">100.0%</td>
<td id="T_e9417_row11_col2" class="data row11 col2">90.000000</td>
<td id="T_e9417_row11_col3" class="data row11 col3">OK</td>
<td id="T_e9417_row11_col4" class="data row11 col4">76503.000000</td>
<td id="T_e9417_row11_col5" class="data row11 col5">2616909.000000</td>
<td id="T_e9417_row11_col6" class="data row11 col6">543119.500000</td>
</tr>
<tr class="odd">
<td id="T_e9417_row12_col0" class="data row12 col0">part_locataires</td>
<td id="T_e9417_row12_col1" class="data row12 col1">100.0%</td>
<td id="T_e9417_row12_col2" class="data row12 col2">90.000000</td>
<td id="T_e9417_row12_col3" class="data row12 col3">OK</td>
<td id="T_e9417_row12_col4" class="data row12 col4">23.800000</td>
<td id="T_e9417_row12_col5" class="data row12 col5">61.870000</td>
<td id="T_e9417_row12_col6" class="data row12 col6">36.270000</td>
</tr>
<tr class="even">
<td id="T_e9417_row13_col0" class="data row13 col0">part_hlm</td>
<td id="T_e9417_row13_col1" class="data row13 col1">100.0%</td>
<td id="T_e9417_row13_col2" class="data row13 col2">90.000000</td>
<td id="T_e9417_row13_col3" class="data row13 col3">OK</td>
<td id="T_e9417_row13_col4" class="data row13 col4">4.450000</td>
<td id="T_e9417_row13_col5" class="data row13 col5">31.390000</td>
<td id="T_e9417_row13_col6" class="data row13 col6">11.880000</td>
</tr>
<tr class="odd">
<td id="T_e9417_row14_col0" class="data row14 col0">taux_surpeuplement</td>
<td id="T_e9417_row14_col1" class="data row14 col1">100.0%</td>
<td id="T_e9417_row14_col2" class="data row14 col2">90.000000</td>
<td id="T_e9417_row14_col3" class="data row14 col3">OK</td>
<td id="T_e9417_row14_col4" class="data row14 col4">2.580000</td>
<td id="T_e9417_row14_col5" class="data row14 col5">31.360000</td>
<td id="T_e9417_row14_col6" class="data row14 col6">5.245000</td>
</tr>
<tr class="even">
<td id="T_e9417_row15_col0" class="data row15 col0">part_familles_mono</td>
<td id="T_e9417_row15_col1" class="data row15 col1">100.0%</td>
<td id="T_e9417_row15_col2" class="data row15 col2">90.000000</td>
<td id="T_e9417_row15_col3" class="data row15 col3">OK</td>
<td id="T_e9417_row15_col4" class="data row15 col4">6.570000</td>
<td id="T_e9417_row15_col5" class="data row15 col5">15.370000</td>
<td id="T_e9417_row15_col6" class="data row15 col6">9.060000</td>
</tr>
<tr class="odd">
<td id="T_e9417_row16_col0" class="data row16 col0">part_menages_1pers</td>
<td id="T_e9417_row16_col1" class="data row16 col1">100.0%</td>
<td id="T_e9417_row16_col2" class="data row16 col2">90.000000</td>
<td id="T_e9417_row16_col3" class="data row16 col3">OK</td>
<td id="T_e9417_row16_col4" class="data row16 col4">31.550000</td>
<td id="T_e9417_row16_col5" class="data row16 col5">53.110000</td>
<td id="T_e9417_row16_col6" class="data row16 col6">38.945000</td>
</tr>
<tr class="even">
<td id="T_e9417_row17_col0" class="data row17 col0">part_25_54</td>
<td id="T_e9417_row17_col1" class="data row17 col1">100.0%</td>
<td id="T_e9417_row17_col2" class="data row17 col2">90.000000</td>
<td id="T_e9417_row17_col3" class="data row17 col3">OK</td>
<td id="T_e9417_row17_col4" class="data row17 col4">31.150000</td>
<td id="T_e9417_row17_col5" class="data row17 col5">44.460000</td>
<td id="T_e9417_row17_col6" class="data row17 col6">35.245000</td>
</tr>
<tr class="odd">
<td id="T_e9417_row18_col0" class="data row18 col0">part_65plus</td>
<td id="T_e9417_row18_col1" class="data row18 col1">100.0%</td>
<td id="T_e9417_row18_col2" class="data row18 col2">90.000000</td>
<td id="T_e9417_row18_col3" class="data row18 col3">OK</td>
<td id="T_e9417_row18_col4" class="data row18 col4">12.400000</td>
<td id="T_e9417_row18_col5" class="data row18 col5">31.460000</td>
<td id="T_e9417_row18_col6" class="data row18 col6">23.220000</td>
</tr>
<tr class="even">
<td id="T_e9417_row19_col0" class="data row19 col0">taux_pauvrete_t1</td>
<td id="T_e9417_row19_col1" class="data row19 col1">83.3%</td>
<td id="T_e9417_row19_col2" class="data row19 col2">50.000000</td>
<td id="T_e9417_row19_col3" class="data row19 col3">OK</td>
<td id="T_e9417_row19_col4" class="data row19 col4">9.200000</td>
<td id="T_e9417_row19_col5" class="data row19 col5">29.500000</td>
<td id="T_e9417_row19_col6" class="data row19 col6">15.600000</td>
</tr>
<tr class="odd">
<td id="T_e9417_row20_col0" class="data row20 col0">score_fragilite</td>
<td id="T_e9417_row20_col1" class="data row20 col1">100.0%</td>
<td id="T_e9417_row20_col2" class="data row20 col2">50.000000</td>
<td id="T_e9417_row20_col3" class="data row20 col3">OK</td>
<td id="T_e9417_row20_col4" class="data row20 col4">-1.656000</td>
<td id="T_e9417_row20_col5" class="data row20 col5">3.455000</td>
<td id="T_e9417_row20_col6" class="data row20 col6">-0.076000</td>
</tr>
<tr class="even">
<td id="T_e9417_row21_col0" class="data row21 col0">source_url</td>
<td id="T_e9417_row21_col1" class="data row21 col1">100.0%</td>
<td id="T_e9417_row21_col2" class="data row21 col2">90.000000</td>
<td id="T_e9417_row21_col3" class="data row21 col3">OK</td>
<td id="T_e9417_row21_col4" class="data row21 col4">nan</td>
<td id="T_e9417_row21_col5" class="data row21 col5">nan</td>
<td id="T_e9417_row21_col6" class="data row21 col6">nan</td>
</tr>
<tr class="odd">
<td id="T_e9417_row22_col0" class="data row22 col0">source_millesime</td>
<td id="T_e9417_row22_col1" class="data row22 col1">100.0%</td>
<td id="T_e9417_row22_col2" class="data row22 col2">90.000000</td>
<td id="T_e9417_row22_col3" class="data row22 col3">OK</td>
<td id="T_e9417_row22_col4" class="data row22 col4">2019.000000</td>
<td id="T_e9417_row22_col5" class="data row22 col5">2024.000000</td>
<td id="T_e9417_row22_col6" class="data row22 col6">2021.500000</td>
</tr>
</tbody>
</table>
</div>
</div>
</figure>
</div>
</div>
<hr>
</section>
<section id="sec-eda" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="sec-eda">Analyse exploratoire (EDA)</h2>
<p>L’analyse exploratoire vise à comprendre la structure des données et les relations entre variables avant toute modélisation. On examine successivement :</p>
<ol type="1">
<li><strong>La matrice de corrélation</strong> — pour identifier les associations bivariées entre toutes les variables et la cible (taux de surendettement) ;</li>
<li><strong>Les distributions</strong> — pour détecter les asymétries, les valeurs extrêmes et la dispersion territoriale ;</li>
<li><strong>Les tendances temporelles</strong> — pour situer l’année de référence dans une dynamique de moyen terme (2019–2024).</li>
</ol>
<p>Cette exploration guide ensuite les choix de spécification du modèle OLS (Section 4).</p>
<section id="sec-correlation" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="sec-correlation">Matrice de corrélation</h3>
<p>La <strong>corrélation de Pearson</strong> mesure l’intensité et la direction de la relation linéaire entre deux variables : un coefficient r proche de +1 indique que les deux variables augmentent conjointement, proche de −1 qu’elles varient en sens inverse, proche de 0 qu’il n’y a pas de relation linéaire. Les étoiles indiquent si la corrélation est statistiquement significative, c’est-à-dire peu susceptible d’être due au hasard seul.</p>
<div class="callout callout-style-simple callout-tip">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-body-container">
<p><strong>Comment lire cette matrice :</strong> chaque cellule donne le coefficient r entre deux variables. La diagonale vaut toujours 1 (une variable est parfaitement corrélée à elle-même). Pour l’interprétation, on se concentre sur la ligne ou la colonne correspondant à <code>suren_depot_taux</code> (taux de surendettement), qui est notre variable à expliquer.</p>
</div>
</div>
</div>
<div id="cell-fig-corr-matrix" class="cell page-columns page-full" data-fig-height="8" data-fig-width="10" data-execution_count="7">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> EDA_AVAILABLE:</span>
<span id="cb5-2">    <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> stats</span>
<span id="cb5-3"></span>
<span id="cb5-4">    corr_vars <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb5-5">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"revenu_median_uc"</span>,</span>
<span id="cb5-6">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"taux_pauvrete"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rsa_taux"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part_locataires"</span>,</span>
<span id="cb5-7">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part_familles_mono"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"interdecile_d9d1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"score_fragilite"</span>,</span>
<span id="cb5-8">    ]</span>
<span id="cb5-9">    corr_vars_available <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [v <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> v <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> corr_vars <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> v <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> df_2021.columns]</span>
<span id="cb5-10">    df_corr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_2021[corr_vars_available].copy()</span>
<span id="cb5-11"></span>
<span id="cb5-12">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Convertir en numérique</span></span>
<span id="cb5-13">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> col <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> corr_vars_available:</span>
<span id="cb5-14">        df_corr[col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_corr[col], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb5-15">    df_corr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_corr.dropna(how<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb5-16"></span>
<span id="cb5-17">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Filtrer les colonnes avec suffisamment de données</span></span>
<span id="cb5-18">    min_obs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span></span>
<span id="cb5-19">    cols_ok <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb5-20">        c <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> c <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> corr_vars_available</span>
<span id="cb5-21">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> df_corr[c].notna().<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> min_obs</span>
<span id="cb5-22">    ]</span>
<span id="cb5-23">    df_corr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_corr[cols_ok].dropna()</span>
<span id="cb5-24"></span>
<span id="cb5-25">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(df_corr) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> min_obs <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(cols_ok) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>:</span>
<span id="cb5-26">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Matrice de corrélation Pearson</span></span>
<span id="cb5-27">        corr_matrix <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_corr.corr(method<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pearson"</span>)</span>
<span id="cb5-28"></span>
<span id="cb5-29">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Matrice de p-values</span></span>
<span id="cb5-30">        pval_matrix <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame(</span>
<span id="cb5-31">            np.ones_like(corr_matrix),</span>
<span id="cb5-32">            index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>corr_matrix.index,</span>
<span id="cb5-33">            columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>corr_matrix.columns,</span>
<span id="cb5-34">        )</span>
<span id="cb5-35">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> i <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> corr_matrix.index:</span>
<span id="cb5-36">            <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> j <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> corr_matrix.columns:</span>
<span id="cb5-37">                <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> j:</span>
<span id="cb5-38">                    valid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_corr[[i, j]].dropna()</span>
<span id="cb5-39">                    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(valid) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>:</span>
<span id="cb5-40">                        _, p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> stats.pearsonr(valid[i], valid[j])</span>
<span id="cb5-41">                        pval_matrix.loc[i, j] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> p</span>
<span id="cb5-42"></span>
<span id="cb5-43">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Heatmap</span></span>
<span id="cb5-44">        fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>))</span>
<span id="cb5-45">        im <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax.imshow(</span>
<span id="cb5-46">            corr_matrix, cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coolwarm"</span>, vmin<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, vmax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, aspect<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span></span>
<span id="cb5-47">        )</span>
<span id="cb5-48">        plt.colorbar(im, ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>ax, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Coefficient de corrélation de Pearson"</span>)</span>
<span id="cb5-49"></span>
<span id="cb5-50">        labels <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [v.replace(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> v <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> cols_ok]</span>
<span id="cb5-51">        ax.set_xticks(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(labels)))</span>
<span id="cb5-52">        ax.set_yticks(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(labels)))</span>
<span id="cb5-53">        ax.set_xticklabels(labels, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, rotation<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>)</span>
<span id="cb5-54">        ax.set_yticklabels(labels, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)</span>
<span id="cb5-55"></span>
<span id="cb5-56">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Annotations avec étoiles de significativité</span></span>
<span id="cb5-57">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> i <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(corr_matrix)):</span>
<span id="cb5-58">            <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> j <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(corr_matrix)):</span>
<span id="cb5-59">                val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> corr_matrix.iloc[i, j]</span>
<span id="cb5-60">                p   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pval_matrix.iloc[i, j]</span>
<span id="cb5-61">                star <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (</span>
<span id="cb5-62">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"***"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span></span>
<span id="cb5-63">                    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"**"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span></span>
<span id="cb5-64">                    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"*"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>))</span>
<span id="cb5-65">                )</span>
<span id="cb5-66">                color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(val) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span></span>
<span id="cb5-67">                ax.text(</span>
<span id="cb5-68">                    j, i, <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>val<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.2f}{</span>star<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb5-69">                    ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>, va<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>,</span>
<span id="cb5-70">                    fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>color,</span>
<span id="cb5-71">                )</span>
<span id="cb5-72"></span>
<span id="cb5-73">        ax.set_title(</span>
<span id="cb5-74">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Matrice de corrélation de Pearson — Variables départementales (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">)</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb5-75">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"* p&lt;0,05   ** p&lt;0,01   *** p&lt;0,001"</span>,</span>
<span id="cb5-76">            fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>, pad<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>,</span>
<span id="cb5-77">        )</span>
<span id="cb5-78">        fig.text(</span>
<span id="cb5-79">            <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.03</span>,</span>
<span id="cb5-80">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Source : Banque de France, INSEE, DREES — année de référence </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">. "</span></span>
<span id="cb5-81">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Les variables présentant les corrélations les plus fortes avec le taux "</span></span>
<span id="cb5-82">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"de surendettement sont identifiées."</span>,</span>
<span id="cb5-83">            ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"italic"</span>, wrap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb5-84">        )</span>
<span id="cb5-85">        plt.tight_layout()</span>
<span id="cb5-86">        plt.show()</span>
<span id="cb5-87"></span>
<span id="cb5-88">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Tableau récapitulatif</span></span>
<span id="cb5-89">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> corr_matrix.columns:</span>
<span id="cb5-90">            corr_target <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (</span>
<span id="cb5-91">                corr_matrix[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span>]</span>
<span id="cb5-92">                .drop(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span>, errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ignore"</span>)</span>
<span id="cb5-93">                .sort_values(key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>, ascending<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span>
<span id="cb5-94">            )</span>
<span id="cb5-95">            <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Corrélations avec le taux de surendettement :"</span>)</span>
<span id="cb5-96">            <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Variable'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:&lt;30}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'r'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:&gt;8}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Sig.'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb5-97">            <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>)</span>
<span id="cb5-98">            <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> var, corr_val <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> corr_target.items():</span>
<span id="cb5-99">                p   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pval_matrix.loc[var, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span>]</span>
<span id="cb5-100">                sig <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (</span>
<span id="cb5-101">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"***"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span></span>
<span id="cb5-102">                    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"**"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span></span>
<span id="cb5-103">                    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"*"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(ns)"</span>))</span>
<span id="cb5-104">                )</span>
<span id="cb5-105">                <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>var<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:&lt;30}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>corr_val<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:+8.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sig<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb5-106">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb5-107">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(</span>
<span id="cb5-108">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"⚠️ Données insuffisantes pour la matrice de corrélation "</span></span>
<span id="cb5-109">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(df_corr)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> obs., </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(cols_ok)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> variables disponibles)."</span></span>
<span id="cb5-110">        )</span>
<span id="cb5-111"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb5-112">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Données EDA non disponibles — exécuter les scripts 01-04 d'abord."</span>)</span></code></pre></div>
</details>
<div class="cell-output cell-output-display page-columns page-full">
<div id="fig-corr-matrix" class="quarto-figure quarto-figure-center quarto-float anchored page-columns page-full" alt="Heatmap de corrélation colorée (rouge = corrélation positive, bleu = négative) entre les variables économiques départementales et le taux de surendettement.">
<figure class="quarto-float quarto-float-fig figure page-columns page-full">
<div aria-describedby="fig-corr-matrix-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca" class="page-columns page-full">
<img src="https://ggilles.dev/posts/dataviz-bdf/index_files/figure-html/fig-corr-matrix-output-1.png" class="img-fluid figure-img column-page" alt="Heatmap de corrélation colorée (rouge = corrélation positive, bleu = négative) entre les variables économiques départementales et le taux de surendettement.">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-corr-matrix-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Matrice de corrélation de Pearson entre variables départementales (année de référence). Les étoiles indiquent le niveau de significativité : * p&lt;0,05 ; ** p&lt;0,01 ; *** p&lt;0,001.
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>
Corrélations avec le taux de surendettement :
Variable                              r  Sig.
--------------------------------------------------
revenu_median_uc                 -0.509  ***
chomage_taux                     +0.463  ***
rsa_taux                         +0.433  ***
taux_pauvrete                    +0.372  ***
score_fragilite                  +0.370  ***
interdecile_d9d1                 -0.265  **
part_locataires                  -0.121  (ns)
part_familles_mono               +0.120  (ns)</code></pre>
</div>
</div>
</section>
<section id="sec-distributions" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="sec-distributions">Distributions des variables clés</h3>
<p>Chaque histogramme représente la répartition des 96 départements selon la valeur de l’indicateur. La ligne rouge pointillée matérialise la <strong>médiane</strong> (valeur centrale). Une distribution fortement asymétrique — avec une longue queue vers les valeurs élevées — signale la présence de quelques départements avec des valeurs extrêmes qui peuvent influencer les estimations OLS. Ces outliers sont à surveiller lors de l’interprétation des coefficients.</p>
<div id="cell-fig-distributions" class="cell page-columns page-full" data-fig-height="8" data-fig-width="14" data-execution_count="8">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> EDA_AVAILABLE:</span>
<span id="cb7-2">    plot_vars <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb7-3">        (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span>,  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taux de surendettement"</span>,     suren_unit_label,       <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"BdF </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb7-4">        (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux"</span>,      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taux de chômage"</span>,            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%"</span>,                    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"INSEE </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb7-5">        (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"taux_pauvrete"</span>,     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taux de pauvreté (seuil 60%)"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%"</span>,                  <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"FiLoSoFi </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_FILOSOFI<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb7-6">        (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rsa_taux"</span>,          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Part allocataires RSA"</span>,       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%"</span>,                    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"DREES </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb7-7">        (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part_locataires"</span>,   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Part des ménages locataires"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%"</span>,                    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"RP </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb7-8">        (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part_familles_mono"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Part familles monoparentales"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%"</span>,                    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"RP </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb7-9">    ]</span>
<span id="cb7-10"></span>
<span id="cb7-11">    available_plot_vars <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb7-12">        (col, label, unit, src)</span>
<span id="cb7-13">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> col, label, unit, src <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> plot_vars</span>
<span id="cb7-14">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> col <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> df_2021.columns</span>
<span id="cb7-15">        <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> pd.to_numeric(df_2021[col], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>).notna().<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span></span>
<span id="cb7-16">    ]</span>
<span id="cb7-17"></span>
<span id="cb7-18">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> available_plot_vars:</span>
<span id="cb7-19">        n_vars <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(available_plot_vars)</span>
<span id="cb7-20">        n_cols <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span></span>
<span id="cb7-21">        n_rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (n_vars <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> n_cols <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//</span> n_cols</span>
<span id="cb7-22">        fig, axes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(n_rows, n_cols, figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> n_rows))</span>
<span id="cb7-23">        axes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> axes.flatten()</span>
<span id="cb7-24"></span>
<span id="cb7-25">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> idx, (col, label, unit, src) <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">enumerate</span>(available_plot_vars[:<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>]):</span>
<span id="cb7-26">            ax  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> axes[idx]</span>
<span id="cb7-27">            data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_2021[col], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>).dropna()</span>
<span id="cb7-28">            ax.hist(data, bins<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_CYAN, edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>)</span>
<span id="cb7-29">            ax.axvline(</span>
<span id="cb7-30">                data.median(), color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_AMBER, linestyle<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"--"</span>, linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>,</span>
<span id="cb7-31">                label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Médiane : </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>median()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb7-32">            )</span>
<span id="cb7-33">            ax.set_xlabel(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>label<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>unit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>)</span>
<span id="cb7-34">            ax.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Nombre de départements"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>)</span>
<span id="cb7-35">            ax.set_title(label, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, fontweight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>)</span>
<span id="cb7-36">            ax.legend(fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)</span>
<span id="cb7-37">            ax.text(</span>
<span id="cb7-38">                <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.98</span>, <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Source : </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>src<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb7-39">                transform<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>ax.transAxes, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>, va<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span>, style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"italic"</span>,</span>
<span id="cb7-40">            )</span>
<span id="cb7-41"></span>
<span id="cb7-42">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Masquer les axes inutilisés</span></span>
<span id="cb7-43">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> idx <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(available_plot_vars), <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(axes)):</span>
<span id="cb7-44">            axes[idx].set_visible(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span>
<span id="cb7-45"></span>
<span id="cb7-46">        fig.suptitle(</span>
<span id="cb7-47">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Distribution des variables clés par département (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>,</span>
<span id="cb7-48">            fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, fontweight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.02</span>,</span>
<span id="cb7-49">        )</span>
<span id="cb7-50">        fig.text(</span>
<span id="cb7-51">            <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>,</span>
<span id="cb7-52">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Les distributions révèlent une forte hétérogénéité territoriale pour "</span></span>
<span id="cb7-53">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"le surendettement et la pauvreté, suggérant des effets de clustering géographique."</span>,</span>
<span id="cb7-54">            ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>, style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"italic"</span>, wrap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb7-55">        )</span>
<span id="cb7-56">        plt.tight_layout()</span>
<span id="cb7-57">        plt.show()</span>
<span id="cb7-58">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb7-59">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Aucune variable disponible pour les distributions (données manquantes)."</span>)</span>
<span id="cb7-60"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb7-61">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Données EDA non disponibles — exécuter les scripts 01-04 d'abord."</span>)</span></code></pre></div>
</details>
<div class="cell-output cell-output-display page-columns page-full">
<div id="fig-distributions" class="quarto-figure quarto-figure-center quarto-float anchored page-columns page-full" alt="Six histogrammes côte à côte montrant les distributions départementales du surendettement, chômage, pauvreté, RSA, logement locatif et familles monoparentales.">
<figure class="quarto-float quarto-float-fig figure page-columns page-full">
<div aria-describedby="fig-distributions-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca" class="page-columns page-full">
<img src="https://ggilles.dev/posts/dataviz-bdf/index_files/figure-html/fig-distributions-output-1.png" class="img-fluid figure-img column-screen-inset" alt="Six histogrammes côte à côte montrant les distributions départementales du surendettement, chômage, pauvreté, RSA, logement locatif et familles monoparentales.">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-distributions-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: Distribution des variables clés par département (année de référence). La ligne rouge pointillée indique la médiane.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="sec-tendances" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="sec-tendances">Tendances temporelles (2019–2024)</h3>
<p>Ce graphique retrace l’évolution de la <strong>médiane départementale</strong> sur la période disponible. Il permet d’identifier des tendances structurelles (baisse du surendettement depuis le pic des années 2010) et des ruptures conjoncturelles (effet de la crise sanitaire de 2020). Un double axe est utilisé pour permettre la comparaison entre des variables exprimées dans des unités différentes — pourcentages pour le chômage et la pauvreté, nombre de dossiers ou taux ‰ pour le surendettement.</p>
<div class="callout callout-style-simple callout-note">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-body-container">
<p>La tendance nationale à la baisse du surendettement depuis 2018 coïncide avec la période de baisse du chômage et de renforcement des minimas sociaux (prime d’activité). La section de modélisation teste si cette co-évolution temporelle se retrouve dans les disparités spatiales entre départements.</p>
</div>
</div>
</div>
<div id="cell-fig-tendances" class="cell page-columns page-full" data-fig-height="5" data-fig-width="10" data-execution_count="9">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> DATA_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(df) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>:</span>
<span id="cb8-2">    trend_vars <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"taux_pauvrete"</span>]</span>
<span id="cb8-3">    available_trend <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [v <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> v <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> trend_vars <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> v <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> df.columns]</span>
<span id="cb8-4"></span>
<span id="cb8-5">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Convertir en numérique</span></span>
<span id="cb8-6">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> v <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> available_trend:</span>
<span id="cb8-7">        df[v] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df[v], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb8-8"></span>
<span id="cb8-9">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> available_trend <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"annee"</span>].nunique() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>:</span>
<span id="cb8-10">        trend_data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (</span>
<span id="cb8-11">            df.groupby(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"annee"</span>)[available_trend].median().reset_index()</span>
<span id="cb8-12">        )</span>
<span id="cb8-13"></span>
<span id="cb8-14">        colors <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb8-15">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span>: _RED,</span>
<span id="cb8-16">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux"</span>:     _CYAN,</span>
<span id="cb8-17">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"taux_pauvrete"</span>:    _AMBER,</span>
<span id="cb8-18">        }</span>
<span id="cb8-19">        labels_fr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb8-20">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span>: suren_axis_label,</span>
<span id="cb8-21">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux"</span>:     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taux de chômage (%)"</span>,</span>
<span id="cb8-22">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"taux_pauvrete"</span>:    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taux de pauvreté (%)"</span>,</span>
<span id="cb8-23">        }</span>
<span id="cb8-24"></span>
<span id="cb8-25">        fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb8-26">        ax2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax.twinx()</span>
<span id="cb8-27"></span>
<span id="cb8-28">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> var <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> available_trend:</span>
<span id="cb8-29">            <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> trend_data[var].notna().<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>:</span>
<span id="cb8-30">                <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">continue</span></span>
<span id="cb8-31">            target_ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax2 <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> var <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> ax</span>
<span id="cb8-32">            target_ax.plot(</span>
<span id="cb8-33">                trend_data[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"annee"</span>], trend_data[var],</span>
<span id="cb8-34">                marker<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"o"</span>, linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb8-35">                color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>colors.get(var, _CHALK_DIM),</span>
<span id="cb8-36">                label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>labels_fr.get(var, var),</span>
<span id="cb8-37">            )</span>
<span id="cb8-38"></span>
<span id="cb8-39">        ax.set_xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Année"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb8-40">        ax.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taux (%)"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb8-41">        ax2.set_ylabel(suren_axis_label, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_RED)</span>
<span id="cb8-42">        ax2.tick_params(axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>, labelcolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_RED)</span>
<span id="cb8-43"></span>
<span id="cb8-44">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Légende combinée</span></span>
<span id="cb8-45">        lines1, labels1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax.get_legend_handles_labels()</span>
<span id="cb8-46">        lines2, labels2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax2.get_legend_handles_labels()</span>
<span id="cb8-47">        ax.legend(lines1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> lines2, labels1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> labels2, loc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"upper right"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>)</span>
<span id="cb8-48"></span>
<span id="cb8-49">        ax.set_title(</span>
<span id="cb8-50">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Évolution médiane des indicateurs départementaux (2019–2024)"</span>,</span>
<span id="cb8-51">            fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>, fontweight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>,</span>
<span id="cb8-52">        )</span>
<span id="cb8-53">        ax.set_xticks(trend_data[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"annee"</span>])</span>
<span id="cb8-54">        ax.grid(axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>)</span>
<span id="cb8-55"></span>
<span id="cb8-56">        fig.text(</span>
<span id="cb8-57">            <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.04</span>,</span>
<span id="cb8-58">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Source : Banque de France, INSEE. Médiane des 96 départements métropolitains. "</span></span>
<span id="cb8-59">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Le recul du surendettement post-2018 coïncide avec la baisse du chômage."</span>,</span>
<span id="cb8-60">            ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"italic"</span>, wrap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb8-61">        )</span>
<span id="cb8-62">        plt.tight_layout()</span>
<span id="cb8-63">        plt.show()</span>
<span id="cb8-64"></span>
<span id="cb8-65">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">elif</span> available_trend:</span>
<span id="cb8-66">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(</span>
<span id="cb8-67">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"⚠️ Une seule année disponible (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'annee'</span>]<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>unique()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">) "</span></span>
<span id="cb8-68">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"— graphique de tendance non produit."</span></span>
<span id="cb8-69">        )</span>
<span id="cb8-70">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb8-71">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Variables de tendance non disponibles dans le dataset."</span>)</span>
<span id="cb8-72"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb8-73">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Données non disponibles — exécuter les scripts 01-04 d'abord."</span>)</span></code></pre></div>
</details>
<div class="cell-output cell-output-display page-columns page-full">
<div id="fig-tendances" class="quarto-figure quarto-figure-center quarto-float anchored page-columns page-full" alt="Graphique en lignes double-axe montrant l'évolution temporelle du surendettement (rouge), du chômage (bleu) et de la pauvreté (orange) entre 2019 et 2024 au niveau départemental médian.">
<figure class="quarto-float quarto-float-fig figure page-columns page-full">
<div aria-describedby="fig-tendances-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca" class="page-columns page-full">
<img src="https://ggilles.dev/posts/dataviz-bdf/index_files/figure-html/fig-tendances-output-1.png" class="img-fluid figure-img column-page" alt="Graphique en lignes double-axe montrant l'évolution temporelle du surendettement (rouge), du chômage (bleu) et de la pauvreté (orange) entre 2019 et 2024 au niveau départemental médian.">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-tendances-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: Évolution médiane des indicateurs départementaux (2019–2024). Axe gauche : chômage et pauvreté (%) ; axe droit : surendettement.
</figcaption>
</figure>
</div>
</div>
</div>
<hr>
</section>
</section>
<section id="sec-ols" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="sec-ols">Modélisation OLS</h2>
<p>La <strong>régression OLS</strong> (Ordinary Least Squares — moindres carrés ordinaires) est la méthode de référence pour estimer l’effet de plusieurs variables indépendantes sur une variable cible tout en contrôlant simultanément les autres facteurs. Contrairement à la corrélation bivariée, elle permet d’isoler l’effet « net » de chaque prédicteur.</p>
<p>Dans ce modèle, la variable à expliquer est le <strong>taux de surendettement</strong> (dossiers déposés pour 1 000 ménages) au niveau départemental pour le millésime retenu par les données FiLoSoFi. Les six prédicteurs du modèle de base sont : le taux de chômage, le revenu médian par unité de consommation, le taux de pauvreté, la part d’allocataires RSA, la part de ménages locataires et la part de familles monoparentales.</p>
<div class="callout callout-style-simple callout-note">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-body-container">
<p>Le modèle OLS est estimé sur le millésime 2021, car les variables FiLoSoFi (<code>revenu_median_uc</code>, <code>taux_pauvrete</code>) ne sont actuellement disponibles que pour cette année.</p>
</div>
</div>
</div>
<p><strong>Comment lire un tableau OLS :</strong></p>
<ul>
<li>Le <strong>coefficient</strong> (Coef.) indique de combien varie le taux de surendettement lorsque la variable explicative augmente d’une unité, toutes les autres variables étant maintenues constantes.</li>
<li>L’<strong>erreur standard</strong> mesure la précision de cette estimation.</li>
<li>La <strong>p-value</strong> indique la probabilité d’observer ce coefficient par hasard si l’effet réel était nul. Une p-value &lt; 0,05 est conventionnellement considérée comme statistiquement significative.</li>
<li>Le <strong>R² ajusté</strong> mesure la proportion de la variance du surendettement expliquée par l’ensemble des prédicteurs (0 = aucun pouvoir explicatif, 1 = explication parfaite).</li>
</ul>
<section id="sec-ols-base" class="level3">
<h3 class="anchored" data-anchor-id="sec-ols-base">Modèle OLS de base</h3>
<p>Le tableau suivant présente les résultats du modèle de base estimé sur les 96 départements métropolitains pour l’année FiLoSoFi disponible. Un R² ajusté supérieur à 0,40 confirmerait que les conditions économiques locales expliquent une part substantielle des disparités départementales de surendettement.</p>
<div class="cell" data-execution_count="11">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> IPython.display <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> display, Markdown</span>
<span id="cb9-2"></span>
<span id="cb9-3"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> OLS_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"base"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> ols_results:</span>
<span id="cb9-4">    model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ols_results[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"base"</span>][<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"model"</span>]</span>
<span id="cb9-5">    res <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model.summary2().tables[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>].copy()</span>
<span id="cb9-6">    res.columns <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Coef."</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Err. Std."</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p-value"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"IC 2,5%"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"IC 97,5%"</span>]</span>
<span id="cb9-7">    res[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sig."</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> res[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p-value"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">apply</span>(</span>
<span id="cb9-8">        <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">lambda</span> p: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"***"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"**"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"*"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>))</span>
<span id="cb9-9">    )</span>
<span id="cb9-10">    res <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> res[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Coef."</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Err. Std."</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p-value"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sig."</span>]]</span>
<span id="cb9-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> col <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Coef."</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Err. Std."</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span>]:</span>
<span id="cb9-12">        res[col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> res[col].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">apply</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">lambda</span> x: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.4f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb9-13">    res[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p-value"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> res[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p-value"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">apply</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">lambda</span> x: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.4f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb9-14"></span>
<span id="cb9-15">    display(Markdown(</span>
<span id="cb9-16">        <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"**R² ajusté : </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>model<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>rsquared_adj<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">** &amp;nbsp;|&amp;nbsp; "</span></span>
<span id="cb9-17">        <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"N = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>(model.nobs)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> &amp;nbsp;|&amp;nbsp; "</span></span>
<span id="cb9-18">        <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"F-stat p-value : </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>model<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>f_pvalue<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.4f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb9-19">    ))</span>
<span id="cb9-20">    display(res.style.set_properties(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-align"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>}).set_table_styles(</span>
<span id="cb9-21">        [{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"selector"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"th"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"props"</span>: [(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-align"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>)]}]</span>
<span id="cb9-22">    ))</span>
<span id="cb9-23"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">elif</span> EDA_AVAILABLE:</span>
<span id="cb9-24">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(</span>
<span id="cb9-25">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Données insuffisantes pour le modèle OLS de base — "</span></span>
<span id="cb9-26">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variables explicatives non disponibles (FiLoSoFi/RP/Minimas non téléchargées).</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb9-27">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Exécuter scripts/01_download.py et scripts/02_clean.py pour acquérir les données."</span></span>
<span id="cb9-28">    )</span>
<span id="cb9-29"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb9-30">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Données non disponibles — exécuter les scripts 01-04 d'abord."</span>)</span></code></pre></div>
</details>
<div id="tbl-ols-base" class="cell quarto-float anchored" data-execution_count="11">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-ols-base-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;4: Résultats OLS — Modèle de base (année FiLoSoFi disponible, 96 départements). Variable dépendante : taux de surendettement. * p&lt;0,05 ; ** p&lt;0,01 ; *** p&lt;0,001.
</figcaption>
<div aria-describedby="tbl-ols-base-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output cell-output-display cell-output-markdown">
<p><strong>R² ajusté : 0.306</strong> &nbsp;|&nbsp; N = 96 &nbsp;|&nbsp; F-stat p-value : 0.0000</p>
</div>
<div class="cell-output cell-output-display">
<style type="text/css">
#T_9874e th {
  text-align: center;
}
#T_9874e_row0_col0, #T_9874e_row0_col1, #T_9874e_row0_col2, #T_9874e_row0_col3, #T_9874e_row0_col4, #T_9874e_row1_col0, #T_9874e_row1_col1, #T_9874e_row1_col2, #T_9874e_row1_col3, #T_9874e_row1_col4, #T_9874e_row2_col0, #T_9874e_row2_col1, #T_9874e_row2_col2, #T_9874e_row2_col3, #T_9874e_row2_col4, #T_9874e_row3_col0, #T_9874e_row3_col1, #T_9874e_row3_col2, #T_9874e_row3_col3, #T_9874e_row3_col4, #T_9874e_row4_col0, #T_9874e_row4_col1, #T_9874e_row4_col2, #T_9874e_row4_col3, #T_9874e_row4_col4, #T_9874e_row5_col0, #T_9874e_row5_col1, #T_9874e_row5_col2, #T_9874e_row5_col3, #T_9874e_row5_col4, #T_9874e_row6_col0, #T_9874e_row6_col1, #T_9874e_row6_col2, #T_9874e_row6_col3, #T_9874e_row6_col4 {
  text-align: right;
}
</style>

<table id="T_9874e" class="do-not-create-environment cell table table-sm table-striped small" data-quarto-postprocess="true">
<thead>
<tr class="header">
<th class="blank level0" data-quarto-table-cell-role="th">&nbsp;</th>
<th id="T_9874e_level0_col0" class="col_heading level0 col0" data-quarto-table-cell-role="th">Coef.</th>
<th id="T_9874e_level0_col1" class="col_heading level0 col1" data-quarto-table-cell-role="th">Err. Std.</th>
<th id="T_9874e_level0_col2" class="col_heading level0 col2" data-quarto-table-cell-role="th">t</th>
<th id="T_9874e_level0_col3" class="col_heading level0 col3" data-quarto-table-cell-role="th">p-value</th>
<th id="T_9874e_level0_col4" class="col_heading level0 col4" data-quarto-table-cell-role="th">Sig.</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td id="T_9874e_level0_row0" class="row_heading level0 row0" data-quarto-table-cell-role="th">const</td>
<td id="T_9874e_row0_col0" class="data row0 col0">39.0623</td>
<td id="T_9874e_row0_col1" class="data row0 col1">10.9921</td>
<td id="T_9874e_row0_col2" class="data row0 col2">3.5537</td>
<td id="T_9874e_row0_col3" class="data row0 col3">0.0006</td>
<td id="T_9874e_row0_col4" class="data row0 col4">***</td>
</tr>
<tr class="even">
<td id="T_9874e_level0_row1" class="row_heading level0 row1" data-quarto-table-cell-role="th">chomage_taux</td>
<td id="T_9874e_row1_col0" class="data row1 col0">0.9972</td>
<td id="T_9874e_row1_col1" class="data row1 col1">0.6586</td>
<td id="T_9874e_row1_col2" class="data row1 col2">1.5141</td>
<td id="T_9874e_row1_col3" class="data row1 col3">0.1335</td>
<td id="T_9874e_row1_col4" class="data row1 col4"></td>
</tr>
<tr class="odd">
<td id="T_9874e_level0_row2" class="row_heading level0 row2" data-quarto-table-cell-role="th">revenu_median_uc</td>
<td id="T_9874e_row2_col0" class="data row2 col0">-0.0008</td>
<td id="T_9874e_row2_col1" class="data row2 col1">0.0004</td>
<td id="T_9874e_row2_col2" class="data row2 col2">-2.0319</td>
<td id="T_9874e_row2_col3" class="data row2 col3">0.0451</td>
<td id="T_9874e_row2_col4" class="data row2 col4">*</td>
</tr>
<tr class="even">
<td id="T_9874e_level0_row3" class="row_heading level0 row3" data-quarto-table-cell-role="th">taux_pauvrete</td>
<td id="T_9874e_row3_col0" class="data row3 col0">-0.2348</td>
<td id="T_9874e_row3_col1" class="data row3 col1">0.3287</td>
<td id="T_9874e_row3_col2" class="data row3 col2">-0.7143</td>
<td id="T_9874e_row3_col3" class="data row3 col3">0.4769</td>
<td id="T_9874e_row3_col4" class="data row3 col4"></td>
</tr>
<tr class="odd">
<td id="T_9874e_level0_row4" class="row_heading level0 row4" data-quarto-table-cell-role="th">rsa_taux</td>
<td id="T_9874e_row4_col0" class="data row4 col0">0.1574</td>
<td id="T_9874e_row4_col1" class="data row4 col1">0.1202</td>
<td id="T_9874e_row4_col2" class="data row4 col2">1.3094</td>
<td id="T_9874e_row4_col3" class="data row4 col3">0.1938</td>
<td id="T_9874e_row4_col4" class="data row4 col4"></td>
</tr>
<tr class="even">
<td id="T_9874e_level0_row5" class="row_heading level0 row5" data-quarto-table-cell-role="th">part_locataires</td>
<td id="T_9874e_row5_col0" class="data row5 col0">-0.0573</td>
<td id="T_9874e_row5_col1" class="data row5 col1">0.1072</td>
<td id="T_9874e_row5_col2" class="data row5 col2">-0.5349</td>
<td id="T_9874e_row5_col3" class="data row5 col3">0.5941</td>
<td id="T_9874e_row5_col4" class="data row5 col4"></td>
</tr>
<tr class="odd">
<td id="T_9874e_level0_row6" class="row_heading level0 row6" data-quarto-table-cell-role="th">part_familles_mono</td>
<td id="T_9874e_row6_col0" class="data row6 col0">-0.1614</td>
<td id="T_9874e_row6_col1" class="data row6 col1">0.4904</td>
<td id="T_9874e_row6_col2" class="data row6 col2">-0.3292</td>
<td id="T_9874e_row6_col3" class="data row6 col3">0.7428</td>
<td id="T_9874e_row6_col4" class="data row6 col4"></td>
</tr>
</tbody>
</table>
</div>
</div>
</figure>
</div>
</div>
</section>
<section id="sec-vif" class="level3">
<h3 class="anchored" data-anchor-id="sec-vif">Diagnostic VIF</h3>
<p>Lorsque plusieurs variables explicatives sont fortement corrélées entre elles (<strong>multicolinéarité</strong>), les estimations OLS deviennent instables : les coefficients peuvent changer de signe ou voir leur erreur standard augmenter fortement, rendant les tests de significativité peu fiables.</p>
<p>Le <strong>Facteur d’Inflation de la Variance</strong> (VIF) quantifie ce problème pour chaque prédicteur. Il se lit ainsi :</p>
<ul>
<li><strong>VIF &lt; 5</strong> : multicolinéarité faible, pas de problème ✅</li>
<li><strong>5 ≤ VIF &lt; 10</strong> : multicolinéarité modérée, interpréter avec prudence ⚡</li>
<li><strong>VIF ≥ 10</strong> : multicolinéarité élevée, les coefficients sont potentiellement biaisés ⚠️</li>
</ul>
<p>En présence de VIF ≥ 10 sur au moins deux variables simultanément, une Analyse en Composantes Principales (ACP, section suivante) peut être appliquée pour réduire la redondance.</p>
<div class="cell" data-execution_count="12">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> IPython.display <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> display, Markdown</span>
<span id="cb10-2"></span>
<span id="cb10-3"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> OLS_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"base"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> ols_results:</span>
<span id="cb10-4">    X_vif <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ols_results[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"base"</span>][<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X"</span>].copy()</span>
<span id="cb10-5">    X_vif_const <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sm.add_constant(X_vif)</span>
<span id="cb10-6"></span>
<span id="cb10-7">    vif_data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame({</span>
<span id="cb10-8">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Variable"</span>: X_vif.columns,</span>
<span id="cb10-9">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"VIF"</span>: [</span>
<span id="cb10-10">            variance_inflation_factor(X_vif_const.values, i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb10-11">            <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> i <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(X_vif.columns))</span>
<span id="cb10-12">        ],</span>
<span id="cb10-13">    })</span>
<span id="cb10-14">    vif_data[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"VIF"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vif_data[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"VIF"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">apply</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">lambda</span> x: <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.2f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb10-15">    vif_data[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Alerte"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vif_data[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"VIF"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">apply</span>(</span>
<span id="cb10-16">        <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">lambda</span> x: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Multicolinéarité élevée"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">float</span>(x) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚡ Modéré"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">float</span>(x) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"✅ OK"</span>)</span>
<span id="cb10-17">    )</span>
<span id="cb10-18"></span>
<span id="cb10-19">    display(vif_data.style.hide(axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"index"</span>))</span>
<span id="cb10-20"></span>
<span id="cb10-21">    high_vif <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vif_data[vif_data[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"VIF"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">apply</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">lambda</span> x: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">float</span>(x) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)]</span>
<span id="cb10-22">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">not</span> high_vif.empty:</span>
<span id="cb10-23">        display(Markdown(</span>
<span id="cb10-24">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"⚠️ **Variables avec VIF ≥ 10 :** </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">', '</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>join(high_vif[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Variable'</span>].tolist())<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">. "</span></span>
<span id="cb10-25">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Une ACP ou une sélection de variables est recommandée."</span></span>
<span id="cb10-26">        ))</span>
<span id="cb10-27">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb10-28">        display(Markdown(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"✅ **Aucun VIF ≥ 10 détecté** — multicolinéarité acceptable pour toutes les spécifications."</span>))</span>
<span id="cb10-29"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">elif</span> EDA_AVAILABLE:</span>
<span id="cb10-30">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ VIF non calculable — données insuffisantes pour le modèle de base."</span>)</span>
<span id="cb10-31"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb10-32">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Données non disponibles."</span>)</span></code></pre></div>
</details>
<div id="tbl-vif" class="cell quarto-float anchored" data-execution_count="12">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-vif-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;5: Facteur d’inflation de la variance (VIF) par prédicteur. VIF &gt; 10 indique une multicolinéarité préoccupante.
</figcaption>
<div aria-describedby="tbl-vif-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output cell-output-display">
<style type="text/css">
</style>

<table id="T_2e7ab" class="do-not-create-environment cell table table-sm table-striped small" data-quarto-postprocess="true">
<thead>
<tr class="header">
<th id="T_2e7ab_level0_col0" class="col_heading level0 col0" data-quarto-table-cell-role="th">Variable</th>
<th id="T_2e7ab_level0_col1" class="col_heading level0 col1" data-quarto-table-cell-role="th">VIF</th>
<th id="T_2e7ab_level0_col2" class="col_heading level0 col2" data-quarto-table-cell-role="th">Alerte</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td id="T_2e7ab_row0_col0" class="data row0 col0">chomage_taux</td>
<td id="T_2e7ab_row0_col1" class="data row0 col1">4.46</td>
<td id="T_2e7ab_row0_col2" class="data row0 col2">✅ OK</td>
</tr>
<tr class="even">
<td id="T_2e7ab_row1_col0" class="data row1 col0">revenu_median_uc</td>
<td id="T_2e7ab_row1_col1" class="data row1 col1">3.64</td>
<td id="T_2e7ab_row1_col2" class="data row1 col2">✅ OK</td>
</tr>
<tr class="odd">
<td id="T_2e7ab_row2_col0" class="data row2 col0">taux_pauvrete</td>
<td id="T_2e7ab_row2_col1" class="data row2 col1">6.05</td>
<td id="T_2e7ab_row2_col2" class="data row2 col2">⚡ Modéré</td>
</tr>
<tr class="even">
<td id="T_2e7ab_row3_col0" class="data row3 col0">rsa_taux</td>
<td id="T_2e7ab_row3_col1" class="data row3 col1">4.81</td>
<td id="T_2e7ab_row3_col2" class="data row3 col2">✅ OK</td>
</tr>
<tr class="odd">
<td id="T_2e7ab_row4_col0" class="data row4 col0">part_locataires</td>
<td id="T_2e7ab_row4_col1" class="data row4 col1">3.05</td>
<td id="T_2e7ab_row4_col2" class="data row4 col2">✅ OK</td>
</tr>
<tr class="even">
<td id="T_2e7ab_row5_col0" class="data row5 col0">part_familles_mono</td>
<td id="T_2e7ab_row5_col1" class="data row5 col1">2.94</td>
<td id="T_2e7ab_row5_col2" class="data row5 col2">✅ OK</td>
</tr>
</tbody>
</table>
</div>
<div class="cell-output cell-output-display cell-output-markdown">
<p>✅ <strong>Aucun VIF ≥ 10 détecté</strong> — multicolinéarité acceptable pour toutes les spécifications.</p>
</div>
</div>
</figure>
</div>
</div>
</section>
<section id="sec-ols-lag" class="level3">
<h3 class="anchored" data-anchor-id="sec-ols-lag">Comparaison avec effets de lag (t-1)</h3>
<p>Les effets économiques sur le surendettement ne sont pas forcément immédiats. Un ménage qui perd son emploi en année t peut accumuler des dettes pendant plusieurs mois avant de déposer un dossier en année t+1. On parle d’un <strong>effet de lag</strong> (décalage temporel) d’un an.</p>
<p>Pour tester cette hypothèse, on compare deux spécifications :</p>
<ul>
<li><strong>Modèle sans lag</strong> : les variables explicatives (chômage, pauvreté) sont mesurées la même année que le surendettement (millésime FiLoSoFi disponible).</li>
<li><strong>Modèle avec lag t-1</strong> : chômage et pauvreté sont mesurés l’année précédente, le surendettement au millésime FiLoSoFi disponible.</li>
</ul>
<p>Si le modèle avec lag présente un <strong>R² ajusté plus élevé</strong> et un <strong>AIC plus faible</strong> (critère d’information d’Akaike — plus bas = meilleur), cela suggère que les effets économiques s’expriment avec un délai d’un an.</p>
<div class="cell" data-execution_count="13">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> IPython.display <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> display, Markdown</span>
<span id="cb11-2"></span>
<span id="cb11-3"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> OLS_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lag"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> ols_results <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"base"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> ols_results:</span>
<span id="cb11-4">    m_base <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ols_results[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"base"</span>][<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"model"</span>]</span>
<span id="cb11-5">    m_lag  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ols_results[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lag"</span>][<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"model"</span>]</span>
<span id="cb11-6"></span>
<span id="cb11-7">    comparison <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame({</span>
<span id="cb11-8">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Indicateur"</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R²"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R² ajusté"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AIC"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"N"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"F-stat (p-value)"</span>],</span>
<span id="cb11-9">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Modèle sans lag"</span>: [</span>
<span id="cb11-10">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>m_base<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>rsquared<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb11-11">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>m_base<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>rsquared_adj<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb11-12">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>m_base<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>aic<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb11-13">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>(m_base.nobs)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb11-14">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>m_base<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>f_pvalue<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.4f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb11-15">        ],</span>
<span id="cb11-16">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Modèle avec lag t-1"</span>: [</span>
<span id="cb11-17">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>m_lag<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>rsquared<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb11-18">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>m_lag<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>rsquared_adj<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb11-19">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>m_lag<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>aic<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb11-20">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>(m_lag.nobs)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb11-21">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>m_lag<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>f_pvalue<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.4f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb11-22">        ],</span>
<span id="cb11-23">    })</span>
<span id="cb11-24">    display(comparison.style.hide(axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"index"</span>))</span>
<span id="cb11-25"></span>
<span id="cb11-26">    delta_r2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> m_lag.rsquared_adj <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> m_base.rsquared_adj</span>
<span id="cb11-27">    delta_aic <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> m_lag.aic <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> m_base.aic</span>
<span id="cb11-28">    conclusion <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (</span>
<span id="cb11-29">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Les effets de lag améliorent le modèle."</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> delta_r2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> delta_aic <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb11-30">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Les effets contemporains sont prédominants."</span></span>
<span id="cb11-31">    )</span>
<span id="cb11-32">    display(Markdown(</span>
<span id="cb11-33">        <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"**Conclusion :** Le modèle avec lag présente un R² ajusté "</span></span>
<span id="cb11-34">        <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'**supérieur**'</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> delta_r2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'inférieur'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> "</span></span>
<span id="cb11-35">        <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"(Δ = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>delta_r2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:+.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">) et un AIC </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'**inférieur** (meilleur)'</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> delta_aic <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'supérieur'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> "</span></span>
<span id="cb11-36">        <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"(Δ = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>delta_aic<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:+.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">). </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>conclusion<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb11-37">    ))</span>
<span id="cb11-38"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">elif</span> OLS_AVAILABLE:</span>
<span id="cb11-39">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(</span>
<span id="cb11-40">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Modèle avec lag non disponible — "</span></span>
<span id="cb11-41">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"vérifier que chomage_taux_t1 et taux_pauvrete_t1 sont bien calculés dans 03_merge.py."</span></span>
<span id="cb11-42">    )</span>
<span id="cb11-43"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">elif</span> EDA_AVAILABLE:</span>
<span id="cb11-44">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Modèles OLS non disponibles — données insuffisantes."</span>)</span>
<span id="cb11-45"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb11-46">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Données non disponibles."</span>)</span></code></pre></div>
</details>
<div id="tbl-ols-lag" class="cell quarto-float anchored" data-execution_count="13">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-ols-lag-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;6: Comparaison OLS — Spécification sans lag vs avec lag t-1. Variable dépendante : taux de surendettement.
</figcaption>
<div aria-describedby="tbl-ols-lag-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output cell-output-display">
<style type="text/css">
</style>

<table id="T_fabef" class="do-not-create-environment cell table table-sm table-striped small" data-quarto-postprocess="true">
<thead>
<tr class="header">
<th id="T_fabef_level0_col0" class="col_heading level0 col0" data-quarto-table-cell-role="th">Indicateur</th>
<th id="T_fabef_level0_col1" class="col_heading level0 col1" data-quarto-table-cell-role="th">Modèle sans lag</th>
<th id="T_fabef_level0_col2" class="col_heading level0 col2" data-quarto-table-cell-role="th">Modèle avec lag t-1</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td id="T_fabef_row0_col0" class="data row0 col0">R²</td>
<td id="T_fabef_row0_col1" class="data row0 col1">0.350</td>
<td id="T_fabef_row0_col2" class="data row0 col2">0.350</td>
</tr>
<tr class="even">
<td id="T_fabef_row1_col0" class="data row1 col0">R² ajusté</td>
<td id="T_fabef_row1_col1" class="data row1 col1">0.306</td>
<td id="T_fabef_row1_col2" class="data row1 col2">0.306</td>
</tr>
<tr class="odd">
<td id="T_fabef_row2_col0" class="data row2 col0">AIC</td>
<td id="T_fabef_row2_col1" class="data row2 col1">553.1</td>
<td id="T_fabef_row2_col2" class="data row2 col2">553.1</td>
</tr>
<tr class="even">
<td id="T_fabef_row3_col0" class="data row3 col0">N</td>
<td id="T_fabef_row3_col1" class="data row3 col1">96</td>
<td id="T_fabef_row3_col2" class="data row3 col2">96</td>
</tr>
<tr class="odd">
<td id="T_fabef_row4_col0" class="data row4 col0">F-stat (p-value)</td>
<td id="T_fabef_row4_col1" class="data row4 col1">0.0000</td>
<td id="T_fabef_row4_col2" class="data row4 col2">0.0000</td>
</tr>
</tbody>
</table>
</div>
<div class="cell-output cell-output-display cell-output-markdown">
<p><strong>Conclusion :</strong> Le modèle avec lag présente un R² ajusté inférieur (Δ = +0.000) et un AIC supérieur (Δ = +0.0). Les effets contemporains sont prédominants.</p>
</div>
</div>
</figure>
</div>
</div>
</section>
<section id="sec-ols-zscore" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="sec-ols-zscore">Coefficients bêta standardisés (z-scores)</h3>
<p>Les variables du modèle sont exprimées dans des unités différentes (%, ‰, €), ce qui rend les coefficients OLS bruts <strong>incomparables</strong> entre eux en termes d’importance relative. Pour remédier à ce problème, on standardise toutes les variables en <strong>z-score</strong> (on soustrait la moyenne et on divise par l’écart-type de chaque variable). Les coefficients bêta standardisés obtenus s’interprètent ainsi : une variation d’un écart-type de la variable X entraîne β écarts-types de variation du taux de surendettement.</p>
<div class="callout callout-style-simple callout-tip">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-body-container">
<p><strong>Lecture pratique :</strong> le prédicteur avec le coefficient bêta <strong>le plus grand en valeur absolue</strong> est celui qui, parmi les variables disponibles, contribue le plus à expliquer les écarts de surendettement entre départements, indépendamment de son unité de mesure.</p>
</div>
</div>
</div>
<div id="cell-fig-ols-zscore" class="cell page-columns page-full" data-execution_count="14">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb12-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> OLS_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zscore"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> ols_results:</span>
<span id="cb12-2">    model_z <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ols_results[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zscore"</span>][<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"model"</span>]</span>
<span id="cb12-3">    params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model_z.params.drop(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"const"</span>, errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ignore"</span>)</span>
<span id="cb12-4">    pvals  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model_z.pvalues.drop(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"const"</span>, errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ignore"</span>)</span>
<span id="cb12-5">    conf   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model_z.conf_int().drop(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"const"</span>, errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ignore"</span>)</span>
<span id="cb12-6"></span>
<span id="cb12-7">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Trier par valeur absolue</span></span>
<span id="cb12-8">    order  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> params.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>().sort_values(ascending<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>).index</span>
<span id="cb12-9">    params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> params[order]</span>
<span id="cb12-10">    pvals  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pvals[order]</span>
<span id="cb12-11">    conf   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> conf.loc[order]</span>
<span id="cb12-12"></span>
<span id="cb12-13">    colors <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [_RED <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> _CHALK_DIM <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> p <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> pvals]</span>
<span id="cb12-14"></span>
<span id="cb12-15">    fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">max</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(params) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>)))</span>
<span id="cb12-16">    bars <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax.barh(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(params)), params.values, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>colors, edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.85</span>)</span>
<span id="cb12-17">    ax.errorbar(</span>
<span id="cb12-18">        params.values, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(params)),</span>
<span id="cb12-19">        xerr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[params.values <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> conf[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>].values, conf[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>].values <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> params.values],</span>
<span id="cb12-20">        fmt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, capsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>,</span>
<span id="cb12-21">    )</span>
<span id="cb12-22">    ax.axvline(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>, linestyle<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"--"</span>)</span>
<span id="cb12-23">    ax.set_yticks(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(params)))</span>
<span id="cb12-24">    ax.set_yticklabels(params.index.tolist(), fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>)</span>
<span id="cb12-25">    ax.set_xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Coefficient bêta standardisé (IC 95 %)"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb12-26">    ax.set_title(</span>
<span id="cb12-27">        <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Importance relative des prédicteurs</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">(OLS sur z-scores — </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_FILOSOFI<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>,</span>
<span id="cb12-28">        fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>, fontweight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>,</span>
<span id="cb12-29">    )</span>
<span id="cb12-30"></span>
<span id="cb12-31">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Légende</span></span>
<span id="cb12-32">    <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> matplotlib.patches <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> Patch</span>
<span id="cb12-33">    legend_elems <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb12-34">        Patch(facecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_RED,       label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p &lt; 0,05 (significatif)"</span>),</span>
<span id="cb12-35">        Patch(facecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_CHALK_DIM, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p ≥ 0,05 (non significatif)"</span>),</span>
<span id="cb12-36">    ]</span>
<span id="cb12-37">    ax.legend(handles<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>legend_elems, loc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lower right"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)</span>
<span id="cb12-38">    ax.grid(axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>)</span>
<span id="cb12-39"></span>
<span id="cb12-40">    fig.text(</span>
<span id="cb12-41">        <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.04</span>,</span>
<span id="cb12-42">        <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Source : Banque de France, INSEE, DREES. Données </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_FILOSOFI<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> — 96 départements métropolitains. "</span></span>
<span id="cb12-43">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Les coefficients standardisés permettent de comparer l'effet relatif de chaque prédicteur."</span>,</span>
<span id="cb12-44">        ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"italic"</span>, wrap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb12-45">    )</span>
<span id="cb12-46">    plt.tight_layout()</span>
<span id="cb12-47">    plt.show()</span>
<span id="cb12-48"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">elif</span> EDA_AVAILABLE:</span>
<span id="cb12-49">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Modèle z-score non disponible — données insuffisantes."</span>)</span>
<span id="cb12-50"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb12-51">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Données non disponibles."</span>)</span></code></pre></div>
</details>
<div class="cell-output cell-output-display page-columns page-full">
<div id="fig-ols-zscore" class="quarto-figure quarto-figure-center quarto-float anchored page-columns page-full" alt="Graphique en barres horizontales des coefficients bêta standardisés, du plus fort au plus faible en valeur absolue. Les barres en rouge indiquent une significativité p<0,05.">
<figure class="quarto-float quarto-float-fig figure page-columns page-full">
<div aria-describedby="fig-ols-zscore-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca" class="page-columns page-full">
<img src="https://ggilles.dev/posts/dataviz-bdf/index_files/figure-html/fig-ols-zscore-output-1.png" class="img-fluid figure-img column-page" alt="Graphique en barres horizontales des coefficients bêta standardisés, du plus fort au plus faible en valeur absolue. Les barres en rouge indiquent une significativité p<0,05.">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-ols-zscore-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: Coefficients bêta standardisés — Modèle OLS avec variables normalisées en z-score (année FiLoSoFi disponible). Permet la comparaison de l’importance relative des prédicteurs, indépendamment de leurs unités.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="sec-pca" class="level3">
<h3 class="anchored" data-anchor-id="sec-pca">ACP conditionnelle (si multicolinéarité élevée)</h3>
<p>Si plusieurs prédicteurs présentent un VIF ≥ 10 simultanément, une <strong>Analyse en Composantes Principales</strong> (ACP) peut synthétiser l’information redondante en un nombre réduit de composantes orthogonales (c’est-à-dire indépendantes entre elles par construction). Chaque composante est une combinaison linéaire des variables d’origine.</p>
<p>Le graphique ci-dessous — produit uniquement lorsqu’une multicolinéarité élevée est détectée — présente la part de variance expliquée par chaque composante. Le nombre de composantes à retenir est conventionnellement fixé au seuil de 80 % de variance cumulée, ou par le critère du coude (elbow criterion).</p>
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb13-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> OLS_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"base"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> ols_results:</span>
<span id="cb13-2">    <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.decomposition <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> PCA</span>
<span id="cb13-3"></span>
<span id="cb13-4">    X_vif_check <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ols_results[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"base"</span>][<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X"</span>].copy()</span>
<span id="cb13-5">    X_vif_const <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sm.add_constant(X_vif_check)</span>
<span id="cb13-6">    vif_vals <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb13-7">        variance_inflation_factor(X_vif_const.values, i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb13-8">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> i <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(X_vif_check.columns))</span>
<span id="cb13-9">    ]</span>
<span id="cb13-10">    n_high_vif <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(v <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> v <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> vif_vals)</span>
<span id="cb13-11"></span>
<span id="cb13-12">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> n_high_vif <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>:</span>
<span id="cb13-13">        scaler_pca <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> StandardScaler()</span>
<span id="cb13-14">        X_scaled <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> scaler_pca.fit_transform(X_vif_check)</span>
<span id="cb13-15">        pca <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> PCA()</span>
<span id="cb13-16">        pca.fit(X_scaled)</span>
<span id="cb13-17"></span>
<span id="cb13-18">        var_exp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pca.explained_variance_ratio_</span>
<span id="cb13-19">        cum_var <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.cumsum(var_exp)</span>
<span id="cb13-20">        n_comp_80 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">next</span>((i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> i, cv <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">enumerate</span>(cum_var) <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> cv <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.80</span>), <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(var_exp))</span>
<span id="cb13-21"></span>
<span id="cb13-22">        fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>))</span>
<span id="cb13-23">        ax.bar(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(var_exp) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), var_exp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_CYAN, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"% variance par composante"</span>)</span>
<span id="cb13-24">        ax2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax.twinx()</span>
<span id="cb13-25">        ax2.plot(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(var_exp) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), cum_var <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_AMBER, marker<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"o"</span>, linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% c</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">umulé"</span>)</span>
<span id="cb13-26">        ax2.axhline(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_CHALK_DIM, linestyle<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"--"</span>, linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Seuil 80 %"</span>)</span>
<span id="cb13-27">        ax.set_xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Composante principale"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb13-28">        ax.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Variance expliquée (%)"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb13-29">        ax2.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Variance cumulée (%)"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_AMBER)</span>
<span id="cb13-30">        ax2.tick_params(axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>, labelcolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_AMBER)</span>
<span id="cb13-31">        ax.set_xticks(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(var_exp) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb13-32">        ax.set_title(</span>
<span id="cb13-33">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"ACP — Variance expliquée (VIF ≥ 10 détecté sur </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>n_high_vif<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> variables)"</span>,</span>
<span id="cb13-34">            fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>, fontweight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>,</span>
<span id="cb13-35">        )</span>
<span id="cb13-36">        lines1, labels1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax.get_legend_handles_labels()</span>
<span id="cb13-37">        lines2, labels2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax2.get_legend_handles_labels()</span>
<span id="cb13-38">        ax.legend(lines1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> lines2, labels1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> labels2, loc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center right"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)</span>
<span id="cb13-39">        fig.text(</span>
<span id="cb13-40">            <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>,</span>
<span id="cb13-41">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Source : Banque de France, INSEE, DREES (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_FILOSOFI<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">). "</span></span>
<span id="cb13-42">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>n_comp_80<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> composante(s) expliquent ≥ 80 % de la variance. "</span></span>
<span id="cb13-43">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Une ACP préalable peut réduire la multicolinéarité avant réestimation."</span>,</span>
<span id="cb13-44">            ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"italic"</span>, wrap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb13-45">        )</span>
<span id="cb13-46">        plt.tight_layout()</span>
<span id="cb13-47">        plt.show()</span>
<span id="cb13-48">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb13-49">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(</span>
<span id="cb13-50">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"✅ ACP non nécessaire : VIF &lt; 10 pour toutes les variables "</span></span>
<span id="cb13-51">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>n_high_vif<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> variable(s) avec VIF ≥ 10 — seuil : 2). "</span></span>
<span id="cb13-52">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"La multicolinéarité est acceptable pour l'interprétation des coefficients OLS."</span></span>
<span id="cb13-53">        )</span>
<span id="cb13-54"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">elif</span> EDA_AVAILABLE:</span>
<span id="cb13-55">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ ACP non disponible — modèle de base absent (données insuffisantes)."</span>)</span>
<span id="cb13-56"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb13-57">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Données non disponibles."</span>)</span></code></pre></div>
</details>
<div id="fig-pca" class="cell quarto-figure quarto-figure-center quarto-float anchored" data-execution_count="15">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-pca-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output cell-output-stdout">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-pca-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6
</figcaption>
</figure>
</div>
<hr>
</section>
</section>
<section id="sec-carto" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="sec-carto">Cartographie départementale</h2>
<p>La modélisation statistique a permis d’identifier les prédicteurs les plus associés au surendettement. La cartographie situe maintenant ces résultats dans l’espace géographique.</p>
<p>Les <strong>cartes choroplèthes</strong> représentent la France métropolitaine découpée en 96 départements, chacun coloré selon la valeur de l’indicateur — de la couleur la plus claire (valeur faible) à la plus saturée (valeur élevée). Cette représentation met en évidence les <strong>clusters géographiques</strong>, c’est-à-dire les zones où plusieurs départements voisins présentent des valeurs similaires — un phénomène que les analyses statistiques purement tabulaires ne permettent pas de percevoir.</p>
<div class="callout callout-style-simple callout-note">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-body-container">
<p><strong>Note méthodologique :</strong> les cartes présentées utilisent des palettes de couleur adaptées aux personnes daltoniennes. La palette <strong>YlOrRd</strong> (jaune → orange → rouge) est utilisée pour les indicateurs positifs (surendettement, chômage). La palette <strong>RdYlBu_r</strong> (rouge → jaune → bleu) est utilisée pour les variations et scores composites, où les deux extrêmes ont des significations distinctes. La palette <strong>viridis</strong> est utilisée pour les variables explicatives.</p>
</div>
</div>
</div>
<section id="sec-carto-suren" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="sec-carto-suren">Taux de surendettement par département</h3>
<p>Cette première carte dresse le <strong>portrait territorial du surendettement</strong>. Elle constitue la variable à expliquer tout au long de cette analyse. Les départements les plus touchés (teinte rouge foncée) sont généralement situés dans le Nord industriel, l’Île-de-France périphérique et certains territoires du bassin méditerranéen. Les départements alpins, bretons et du Grand Ouest présentent historiquement les taux les plus faibles.</p>
<div id="cell-fig-carto-suren" class="cell page-columns page-full" data-fig-height="8" data-fig-width="10" data-execution_count="17">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb14-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> CARTO_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> gdf_merged <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">is</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">not</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span>:</span>
<span id="cb14-2">    col_map <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span></span>
<span id="cb14-3">    col_label <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dossiers déposés (nb)"</span></span>
<span id="cb14-4"></span>
<span id="cb14-5">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Utiliser le taux / 10 000 hab. si disponible (RP 2022 PMUN)</span></span>
<span id="cb14-6">    suren_vals <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(gdf_merged[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span>], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb14-7">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> suren_vals.median() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>:</span>
<span id="cb14-8">        col_map <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span></span>
<span id="cb14-9">        col_label <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dépôts pour 10 000 habitants"</span></span>
<span id="cb14-10"></span>
<span id="cb14-11">    gdf_plot <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gdf_merged.copy()</span>
<span id="cb14-12">    gdf_plot[col_map] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(gdf_plot[col_map], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb14-13"></span>
<span id="cb14-14">    fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>))</span>
<span id="cb14-15">    divider <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> make_axes_locatable(ax)</span>
<span id="cb14-16">    cax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> divider.append_axes(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4%"</span>, pad<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span>
<span id="cb14-17">    cax.set_facecolor(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb14-18"></span>
<span id="cb14-19">    gdf_plot.plot(</span>
<span id="cb14-20">        column<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>col_map,</span>
<span id="cb14-21">        cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"YlOrRd"</span>,</span>
<span id="cb14-22">        legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb14-23">        legend_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>: col_label, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"orientation"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"vertical"</span>},</span>
<span id="cb14-24">        missing_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"color"</span>: _BOARD_LIGHT, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Données manquantes"</span>},</span>
<span id="cb14-25">        ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>ax,</span>
<span id="cb14-26">        cax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>cax,</span>
<span id="cb14-27">        linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>,</span>
<span id="cb14-28">        edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_BOARD_LIGHTER,</span>
<span id="cb14-29">    )</span>
<span id="cb14-30">    ax.set_axis_off()</span>
<span id="cb14-31">    ax.set_facecolor(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb14-32">    ax.set_title(</span>
<span id="cb14-33">        <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Surendettement par département — </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>col_label<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>,</span>
<span id="cb14-34">        fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">13</span>, fontweight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, pad<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>,</span>
<span id="cb14-35">    )</span>
<span id="cb14-36">    fig.text(</span>
<span id="cb14-37">        <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>,</span>
<span id="cb14-38">        <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Source : Banque de France, Synthèses surendettement </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">. "</span></span>
<span id="cb14-39">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"96 départements métropolitains (DOM-TOM exclus). "</span></span>
<span id="cb14-40">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Les zones les plus foncées concentrent les dossiers de surendettement les plus nombreux."</span>,</span>
<span id="cb14-41">        ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"italic"</span>, wrap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb14-42">    )</span>
<span id="cb14-43">    plt.tight_layout()</span>
<span id="cb14-44">    plt.show()</span>
<span id="cb14-45"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb14-46">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Cartographie non disponible — GeoDataFrame non chargé ou données manquantes."</span>)</span></code></pre></div>
</details>
<div class="cell-output cell-output-display page-columns page-full">
<div id="fig-carto-suren" class="quarto-figure quarto-figure-center quarto-float anchored page-columns page-full" alt="Carte choroplèthe de France métropolitaine représentant le nombre de dossiers de surendettement déposés pour 1 000 ménages par département durant l'année de référence. Les départements du Nord, du Pas-de-Calais et de la Seine-Saint-Denis apparaissent en rouge foncé.">
<figure class="quarto-float quarto-float-fig figure page-columns page-full">
<div aria-describedby="fig-carto-suren-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca" class="page-columns page-full">
<img src="https://ggilles.dev/posts/dataviz-bdf/index_files/figure-html/fig-carto-suren-output-1.png" class="img-fluid figure-img column-page" alt="Carte choroplèthe de France métropolitaine représentant le nombre de dossiers de surendettement déposés pour 1 000 ménages par département durant l'année de référence. Les départements du Nord, du Pas-de-Calais et de la Seine-Saint-Denis apparaissent en rouge foncé.">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-carto-suren-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;7: Taux de surendettement par département (année de référence). Palette YlOrRd : plus la couleur est foncée, plus le taux est élevé. Source : Banque de France.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="sec-carto-evol" class="level3">
<h3 class="anchored" data-anchor-id="sec-carto-evol">Évolution du surendettement depuis 2018</h3>
<p>Entre 2018 et l’année de référence retenue, le nombre de dossiers de surendettement a connu une <strong>baisse généralisée</strong> au niveau national. Cette tendance est attribuable à plusieurs facteurs : la réforme de la procédure de surendettement (loi Lagarde, effets de long terme), la baisse du chômage jusqu’en 2020 et le renforcement des minimas sociaux.</p>
<p>La carte suivante représente la <strong>variation absolue</strong> entre 2018 et l’année de référence par département. La palette divergente (rouge = hausse, bleu = baisse) permet d’identifier :</p>
<ul>
<li>Les départements qui ont <strong>le plus bénéficié</strong> de la tendance baissière (bleu intense) ;</li>
<li>Les rares départements qui restent structurellement fragilisés et <strong>résistants à la baisse</strong> (rouge).</li>
</ul>
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb15-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> CARTO_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> gdf_merged <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">is</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">not</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> DATA_AVAILABLE:</span>
<span id="cb15-2">    df_2018 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df[df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"annee"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2018</span>].copy()</span>
<span id="cb15-3">    df_2021_evol <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df[df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"annee"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> YEAR_TARGET].copy()</span>
<span id="cb15-4"></span>
<span id="cb15-5">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(df_2018) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(df_2021_evol) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>:</span>
<span id="cb15-6">        df_2018[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_code"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_2018[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_code"</span>].astype(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>.zfill(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb15-7">        df_2021_evol[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_code"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_2021_evol[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_code"</span>].astype(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>.zfill(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb15-8">        df_2018[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_2018[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb15-9">        df_2021_evol[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_2021_evol[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb15-10"></span>
<span id="cb15-11">        df_evol <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_2021_evol[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_code"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>]].merge(</span>
<span id="cb15-12">            df_2018[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_code"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>]], on<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_code"</span>, suffixes<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_target"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_2018"</span>)</span>
<span id="cb15-13">        )</span>
<span id="cb15-14">        df_evol[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variation_abs"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_evol[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb_target"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> df_evol[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb_2018"</span>]</span>
<span id="cb15-15">        df_evol[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variation_pct"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (</span>
<span id="cb15-16">            (df_evol[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb_target"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> df_evol[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb_2018"</span>])</span>
<span id="cb15-17">            <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> df_evol[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb_2018"</span>].replace(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, np.nan)</span>
<span id="cb15-18">        ) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span></span>
<span id="cb15-19"></span>
<span id="cb15-20">        gdf_evol <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gdf.merge(df_evol[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_code"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variation_abs"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variation_pct"</span>]], on<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_code"</span>, how<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>)</span>
<span id="cb15-21"></span>
<span id="cb15-22">        fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>))</span>
<span id="cb15-23">        divider <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> make_axes_locatable(ax)</span>
<span id="cb15-24">        cax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> divider.append_axes(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4%"</span>, pad<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span>
<span id="cb15-25">        cax.set_facecolor(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb15-26"></span>
<span id="cb15-27">        vmax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gdf_evol[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variation_abs"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>().quantile(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>)</span>
<span id="cb15-28">        gdf_evol.plot(</span>
<span id="cb15-29">            column<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variation_abs"</span>,</span>
<span id="cb15-30">            cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"RdYlBu_r"</span>,</span>
<span id="cb15-31">            vmin<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=-</span>vmax,</span>
<span id="cb15-32">            vmax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>vmax,</span>
<span id="cb15-33">            legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb15-34">            legend_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Variation absolue (nb dossiers)"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"orientation"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"vertical"</span>},</span>
<span id="cb15-35">            missing_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"color"</span>: _BOARD_LIGHT, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Données manquantes"</span>},</span>
<span id="cb15-36">            ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>ax,</span>
<span id="cb15-37">            cax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>cax,</span>
<span id="cb15-38">            linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>,</span>
<span id="cb15-39">            edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_BOARD_LIGHTER,</span>
<span id="cb15-40">        )</span>
<span id="cb15-41">        ax.set_axis_off()</span>
<span id="cb15-42">        ax.set_facecolor(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb15-43">        ax.set_title(</span>
<span id="cb15-44">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Évolution du surendettement 2018–</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">(Variation absolue du nombre de dossiers déposés)"</span>,</span>
<span id="cb15-45">            fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">13</span>, fontweight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, pad<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>,</span>
<span id="cb15-46">        )</span>
<span id="cb15-47">        n_baisse <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (df_evol[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variation_abs"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb15-48">        n_total  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_evol[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"variation_abs"</span>].notna().<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb15-49">        fig.text(</span>
<span id="cb15-50">            <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>,</span>
<span id="cb15-51">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Source : Banque de France 2018 et </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">. "</span></span>
<span id="cb15-52">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>n_baisse<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">/</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>n_total<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> départements enregistrent une baisse entre 2018 et </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">. "</span></span>
<span id="cb15-53">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"La tendance nationale à la baisse masque des disparités territoriales persistantes."</span>,</span>
<span id="cb15-54">            ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"italic"</span>, wrap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb15-55">        )</span>
<span id="cb15-56">        plt.tight_layout()</span>
<span id="cb15-57">        plt.show()</span>
<span id="cb15-58">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb15-59">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"⚠️ Données 2018 insuffisantes (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(df_2018)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> départements) — carte d'évolution non produite."</span>)</span>
<span id="cb15-60"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb15-61">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Cartographie non disponible."</span>)</span></code></pre></div>
</details>
<div id="fig-carto-evol" class="cell quarto-figure quarto-figure-center quarto-float anchored" data-fig-height="8" data-fig-width="10" data-execution_count="18">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-carto-evol-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output cell-output-stdout">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-carto-evol-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;8
</figcaption>
</figure>
</div>
</section>
<section id="sec-carto-vars" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="sec-carto-vars">Variables explicatives clés</h3>
<p>Ces quatre cartes présentent les <strong>principales variables explicatives</strong> retenues dans le modèle OLS. La comparaison visuelle avec la carte du surendettement (section précédente) permet d’identifier des structures géographiques similaires, cohérentes avec les corrélations mesurées dans la matrice de corrélation.</p>
<p>Un <strong>clustering géographique</strong> similaire entre deux cartes suggère une corrélation spatiale entre les deux indicateurs. À titre d’exemple, si les mêmes départements apparaissent en rouge foncé sur la carte du chômage et sur la carte du surendettement, cela renforce l’hypothèse d’une association entre les deux indicateurs au-delà des résultats statistiques.</p>
<div id="cell-fig-carto-vars" class="cell page-columns page-full" data-fig-height="10" data-fig-width="14" data-execution_count="19">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb16-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> CARTO_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> gdf_merged <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">is</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">not</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span>:</span>
<span id="cb16-2">    carto_vars <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb16-3">        (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux"</span>,      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taux de chômage (%)"</span>,            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"INSEE </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb16-4">        (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"taux_pauvrete"</span>,     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taux de pauvreté (%)"</span>,           <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"FiLoSoFi </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_FILOSOFI<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb16-5">        (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rsa_taux"</span>,          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Part allocataires RSA (%)"</span>,      <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"DREES </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb16-6">        (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part_locataires"</span>,   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Part ménages locataires (%)"</span>,    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"RP </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb16-7">    ]</span>
<span id="cb16-8">    available_carto <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb16-9">        (col, label, src)</span>
<span id="cb16-10">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> col, label, src <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> carto_vars</span>
<span id="cb16-11">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> col <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> gdf_merged.columns</span>
<span id="cb16-12">        <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> pd.to_numeric(gdf_merged[col], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>).notna().<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span></span>
<span id="cb16-13">    ]</span>
<span id="cb16-14"></span>
<span id="cb16-15">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> available_carto:</span>
<span id="cb16-16">        n_cols <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">min</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(available_carto))</span>
<span id="cb16-17">        n_rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(available_carto) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> n_cols <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//</span> n_cols</span>
<span id="cb16-18">        fig, axes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(n_rows, n_cols, figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> n_rows))</span>
<span id="cb16-19">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(available_carto) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>:</span>
<span id="cb16-20">            axes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [[axes]]</span>
<span id="cb16-21">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">elif</span> n_rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>:</span>
<span id="cb16-22">            axes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [axes]</span>
<span id="cb16-23"></span>
<span id="cb16-24">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> idx, (col, label, src) <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">enumerate</span>(available_carto):</span>
<span id="cb16-25">            row, col_idx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">divmod</span>(idx, n_cols)</span>
<span id="cb16-26">            ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> axes[row][col_idx] <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> n_rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> axes[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>][col_idx]</span>
<span id="cb16-27">            gdf_plot <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gdf_merged.copy()</span>
<span id="cb16-28">            gdf_plot[col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(gdf_plot[col], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb16-29">            gdf_plot.plot(</span>
<span id="cb16-30">                column<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>col,</span>
<span id="cb16-31">                cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"viridis"</span>,</span>
<span id="cb16-32">                legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb16-33">                missing_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"color"</span>: _BOARD_LIGHT},</span>
<span id="cb16-34">                ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>ax,</span>
<span id="cb16-35">                linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,</span>
<span id="cb16-36">                edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_BOARD_LIGHTER,</span>
<span id="cb16-37">            )</span>
<span id="cb16-38">            ax.set_axis_off()</span>
<span id="cb16-39">            ax.set_facecolor(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb16-40">            ax.set_title(label, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, fontweight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>)</span>
<span id="cb16-41">            ax.text(</span>
<span id="cb16-42">                <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>, <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Source : </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>src<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb16-43">                transform<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>ax.transAxes, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>, style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"italic"</span>, va<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>,</span>
<span id="cb16-44">            )</span>
<span id="cb16-45"></span>
<span id="cb16-46">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Masquer axes inutilisés</span></span>
<span id="cb16-47">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> idx <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(available_carto), n_rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> n_cols):</span>
<span id="cb16-48">            row, col_idx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">divmod</span>(idx, n_cols)</span>
<span id="cb16-49">            <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> n_rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>:</span>
<span id="cb16-50">                axes[row][col_idx].set_visible(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span>
<span id="cb16-51">            <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb16-52">                axes[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>][col_idx].set_visible(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span>
<span id="cb16-53"></span>
<span id="cb16-54">        fig.suptitle(</span>
<span id="cb16-55">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Variables explicatives clés — Disparités départementales (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>,</span>
<span id="cb16-56">            fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">13</span>, fontweight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.01</span>,</span>
<span id="cb16-57">        )</span>
<span id="cb16-58">        fig.text(</span>
<span id="cb16-59">            <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>,</span>
<span id="cb16-60">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Source : INSEE (chômage localisé </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">, FiLoSoFi </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_FILOSOFI<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">), DREES. "</span></span>
<span id="cb16-61">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Les cartes révèlent une concentration géographique similaire à celle du surendettement."</span>,</span>
<span id="cb16-62">            ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"italic"</span>, wrap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb16-63">        )</span>
<span id="cb16-64">        plt.tight_layout()</span>
<span id="cb16-65">        plt.show()</span>
<span id="cb16-66">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb16-67">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(</span>
<span id="cb16-68">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Cartes des variables explicatives non disponibles — "</span></span>
<span id="cb16-69">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"données FiLoSoFi, RP et minimas sociaux absentes.</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb16-70">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Exécuter scripts/01_download.py pour télécharger les données INSEE."</span></span>
<span id="cb16-71">        )</span>
<span id="cb16-72"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb16-73">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Cartographie non disponible."</span>)</span></code></pre></div>
</details>
<div class="cell-output cell-output-display page-columns page-full">
<div id="fig-carto-vars" class="quarto-figure quarto-figure-center quarto-float anchored page-columns page-full" alt="Quatre cartes de France métropolitaine côte à côte représentant le taux de chômage, le taux de pauvreté, le taux de RSA et la part de ménages locataires par département durant l'année de référence.">
<figure class="quarto-float quarto-float-fig figure page-columns page-full">
<div aria-describedby="fig-carto-vars-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca" class="page-columns page-full">
<img src="https://ggilles.dev/posts/dataviz-bdf/index_files/figure-html/fig-carto-vars-output-1.png" class="img-fluid figure-img column-screen-inset" alt="Quatre cartes de France métropolitaine côte à côte représentant le taux de chômage, le taux de pauvreté, le taux de RSA et la part de ménages locataires par département durant l'année de référence.">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-carto-vars-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;9: Cartes choroplèthes des principales variables explicatives (année de référence). Palette viridis. Source : INSEE et DREES.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="sec-carto-score" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="sec-carto-score">Score de fragilité territoriale</h3>
<p>Le <strong>score de fragilité financière territoriale</strong> est un indicateur composite qui synthétise quatre dimensions de vulnérabilité en un seul chiffre par département. Il est calculé comme une combinaison pondérée de z-scores :</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Ctext%7BScore%7D%20=%200%7B,%7D3%20%5Ctimes%20z_%7B%5Ctext%7Bch%C3%B4mage%7D%7D%20+%200%7B,%7D3%20%5Ctimes%20z_%7B%5Ctext%7Bpauvret%C3%A9%7D%7D%20+%200%7B,%7D2%20%5Ctimes%20z_%7B%5Ctext%7BRSA%7D%7D%20+%200%7B,%7D2%20%5Ctimes%20z_%7B%5Ctext%7Blocataires%7D%7D"></p>
<p>Les <strong>z-scores</strong> permettent de comparer des variables d’unités différentes en les ramenant à une échelle commune (moyenne 0, écart-type 1). Les pondérations reflètent la hiérarchie des corrélations observées avec le surendettement.</p>
<div class="callout callout-style-simple callout-tip">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-body-container">
<p><strong>Interprétation :</strong> un score positif indique que le département cumule plusieurs facteurs de vulnérabilité <strong>au-dessus de la moyenne nationale</strong> ; un score négatif reflète une situation favorable. La corrélation de Pearson entre le score et le taux de surendettement évalue la pertinence prédictive de cet agrégat.</p>
</div>
</div>
</div>
<div id="cell-fig-carto-score" class="cell page-columns page-full" data-fig-height="8" data-fig-width="10" data-execution_count="20">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb17-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> CARTO_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> gdf_merged <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">is</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">not</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span>:</span>
<span id="cb17-2">    gdf_score <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gdf_merged.copy()</span>
<span id="cb17-3">    gdf_score[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"score_fragilite"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(gdf_score[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"score_fragilite"</span>], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb17-4"></span>
<span id="cb17-5">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> gdf_score[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"score_fragilite"</span>].notna().<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>:</span>
<span id="cb17-6">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Corrélation spatiale avec surendettement</span></span>
<span id="cb17-7">        gdf_score[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb_num"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(gdf_score[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb17-8">        corr_score_suren <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.nan</span>
<span id="cb17-9">        valid_pair <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gdf_score[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"score_fragilite"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb_num"</span>]].dropna()</span>
<span id="cb17-10">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(valid_pair) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>:</span>
<span id="cb17-11">            <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> stats <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> scipy_stats</span>
<span id="cb17-12">            corr_score_suren, _ <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> scipy_stats.pearsonr(</span>
<span id="cb17-13">                valid_pair[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"score_fragilite"</span>], valid_pair[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb_num"</span>]</span>
<span id="cb17-14">            )</span>
<span id="cb17-15"></span>
<span id="cb17-16">        fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>))</span>
<span id="cb17-17">        divider <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> make_axes_locatable(ax)</span>
<span id="cb17-18">        cax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> divider.append_axes(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4%"</span>, pad<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span>
<span id="cb17-19">        cax.set_facecolor(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb17-20"></span>
<span id="cb17-21">        vabs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gdf_score[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"score_fragilite"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>().quantile(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>)</span>
<span id="cb17-22">        gdf_score.plot(</span>
<span id="cb17-23">            column<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"score_fragilite"</span>,</span>
<span id="cb17-24">            cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"RdYlBu_r"</span>,</span>
<span id="cb17-25">            vmin<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=-</span>vabs,</span>
<span id="cb17-26">            vmax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>vabs,</span>
<span id="cb17-27">            legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb17-28">            legend_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Score de fragilité (z-score composite)"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"orientation"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"vertical"</span>},</span>
<span id="cb17-29">            missing_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"color"</span>: _BOARD_LIGHT, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Données manquantes"</span>},</span>
<span id="cb17-30">            ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>ax,</span>
<span id="cb17-31">            cax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>cax,</span>
<span id="cb17-32">            linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>,</span>
<span id="cb17-33">            edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_BOARD_LIGHTER,</span>
<span id="cb17-34">        )</span>
<span id="cb17-35">        ax.set_axis_off()</span>
<span id="cb17-36">        ax.set_facecolor(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb17-37">        ax.set_title(</span>
<span id="cb17-38">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Score de fragilité financière territoriale (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">)</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb17-39">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chômage×0,3 + pauvreté×0,3 + RSA×0,2 + locataires×0,2 (z-scores)"</span>,</span>
<span id="cb17-40">            fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, fontweight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, pad<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>,</span>
<span id="cb17-41">        )</span>
<span id="cb17-42">        corr_txt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (</span>
<span id="cb17-43">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"r = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>corr_score_suren<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.2f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> avec le surendettement"</span></span>
<span id="cb17-44">            <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">not</span> np.isnan(corr_score_suren)</span>
<span id="cb17-45">            <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"corrélation avec surendettement : données insuffisantes"</span></span>
<span id="cb17-46">        )</span>
<span id="cb17-47">        fig.text(</span>
<span id="cb17-48">            <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>,</span>
<span id="cb17-49">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Source : Banque de France, INSEE, DREES </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">. "</span></span>
<span id="cb17-50">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Corrélation de Pearson score–surendettement : </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>corr_txt<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">. "</span></span>
<span id="cb17-51">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Les zones rouges concentrent les multiples facteurs de vulnérabilité financière."</span>,</span>
<span id="cb17-52">            ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"italic"</span>, wrap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb17-53">        )</span>
<span id="cb17-54">        plt.tight_layout()</span>
<span id="cb17-55">        plt.show()</span>
<span id="cb17-56">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb17-57">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Score de fragilité indisponible ou insuffisamment couvert (&lt; 50 départements avec données)."</span>)</span>
<span id="cb17-58"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb17-59">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Cartographie non disponible."</span>)</span></code></pre></div>
</details>
<div class="cell-output cell-output-display page-columns page-full">
<div id="fig-carto-score" class="quarto-figure quarto-figure-center quarto-float anchored page-columns page-full" alt="Carte choroplèthe du score composite de fragilité financière. Les départements en rouge présentent une fragilité élevée (score positif), les bleus une fragilité faible.">
<figure class="quarto-float quarto-float-fig figure page-columns page-full">
<div aria-describedby="fig-carto-score-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca" class="page-columns page-full">
<img src="https://ggilles.dev/posts/dataviz-bdf/index_files/figure-html/fig-carto-score-output-1.png" class="img-fluid figure-img column-page" alt="Carte choroplèthe du score composite de fragilité financière. Les départements en rouge présentent une fragilité élevée (score positif), les bleus une fragilité faible.">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-carto-score-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;10: Score de fragilité financière territoriale par département (année de référence). Formule : chomage_z × 0,3 + pauvreté_z × 0,3 + RSA_z × 0,2 + locataires_z × 0,2. Palette divergente RdYlBu_r. Source : BdF, INSEE, DREES.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="sec-carto-scatter" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="sec-carto-scatter">Graphiques bivariés : surendettement vs.&nbsp;prédicteurs</h3>
<p>Ces <strong>nuages de points</strong> examinent la relation entre le surendettement et chaque variable explicative prise <strong>séparément</strong> (sans contrôle des autres variables). Chaque point représente un département ; la droite rouge est la droite de régression linéaire simple. Le coefficient r et sa p-value indiquent l’intensité et la significativité de l’association.</p>
<p>Ces graphiques bivariés complètent la matrice de corrélation en rendant visibles :</p>
<ul>
<li>La <strong>dispersion</strong> autour de la tendance (points proches ou éloignés de la droite) ;</li>
<li>Les <strong>outliers</strong> (départements qui s’écartent de la tendance générale) ;</li>
<li>La <strong>forme</strong> de la relation (linéaire, ou peut-être curvilinéaire pour certaines variables).</li>
</ul>
<div class="callout callout-style-simple callout-note">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-body-container">
<p>Ces graphiques représentent des corrélations bivariées non contrôlées. Un coefficient r élevé ici ne garantit pas que la variable reste significative dans le modèle OLS multivarié, où les effets des autres prédicteurs sont simultanément pris en compte.</p>
</div>
</div>
</div>
<div id="cell-fig-scatter-bivariate" class="cell page-columns page-full" data-fig-height="10" data-fig-width="14" data-execution_count="21">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb18-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> EDA_AVAILABLE:</span>
<span id="cb18-2">    scatter_vars <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb18-3">        (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux"</span>,      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taux de chômage (%)"</span>,            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"INSEE </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb18-4">        (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"taux_pauvrete"</span>,     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taux de pauvreté (%)"</span>,           <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"FiLoSoFi </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_FILOSOFI<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb18-5">        (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rsa_taux"</span>,          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Part allocataires RSA (%)"</span>,      <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"DREES </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb18-6">        (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part_locataires"</span>,   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Part ménages locataires (%)"</span>,    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"RP </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb18-7">    ]</span>
<span id="cb18-8">    y_col_scatter <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span></span>
<span id="cb18-9">    y_label <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dossiers de surendettement (nb)"</span></span>
<span id="cb18-10"></span>
<span id="cb18-11">    available_scatter <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb18-12">        (col, label, src) <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> col, label, src <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> scatter_vars</span>
<span id="cb18-13">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> col <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> df_2021.columns</span>
<span id="cb18-14">        <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> pd.to_numeric(df_2021[col], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>).notna().<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span></span>
<span id="cb18-15">    ]</span>
<span id="cb18-16"></span>
<span id="cb18-17">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> available_scatter:</span>
<span id="cb18-18">        <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> stats <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> scipy_stats</span>
<span id="cb18-19"></span>
<span id="cb18-20">        n_cols <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">min</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(available_scatter))</span>
<span id="cb18-21">        n_rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(available_scatter) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> n_cols <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//</span> n_cols</span>
<span id="cb18-22">        fig, axes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(n_rows, n_cols, figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> n_rows))</span>
<span id="cb18-23">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(available_scatter) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>:</span>
<span id="cb18-24">            axes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [[axes]]</span>
<span id="cb18-25">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">elif</span> n_rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>:</span>
<span id="cb18-26">            axes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [axes]</span>
<span id="cb18-27"></span>
<span id="cb18-28">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> idx, (col, label, src) <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">enumerate</span>(available_scatter):</span>
<span id="cb18-29">            row, col_idx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">divmod</span>(idx, n_cols)</span>
<span id="cb18-30">            ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> axes[row][col_idx] <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> n_rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> axes[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>][col_idx]</span>
<span id="cb18-31"></span>
<span id="cb18-32">            x_data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_2021[col], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb18-33">            y_data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_2021[y_col_scatter], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb18-34">            valid  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame({<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>: x_data, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>: y_data}).dropna()</span>
<span id="cb18-35"></span>
<span id="cb18-36">            ax.scatter(valid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>], valid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>], color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_CYAN, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>, s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>)</span>
<span id="cb18-37"></span>
<span id="cb18-38">            <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(valid) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>:</span>
<span id="cb18-39">                slope, intercept, r_val, p_val, _ <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> scipy_stats.linregress(valid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>], valid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>])</span>
<span id="cb18-40">                x_line <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.linspace(valid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">min</span>(), valid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">max</span>(), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb18-41">                ax.plot(x_line, intercept <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> slope <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x_line, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_RED, linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb18-42">                        label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"r=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>r_val<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.2f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">, p=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'&lt;0,001'</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>p_val<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb18-43">                ax.legend(fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>)</span>
<span id="cb18-44"></span>
<span id="cb18-45">            ax.set_xlabel(label, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb18-46">            ax.set_ylabel(y_label, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb18-47">            ax.set_title(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>y_label<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">vs. </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>label<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, fontweight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>)</span>
<span id="cb18-48">            ax.grid(alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>)</span>
<span id="cb18-49">            ax.text(</span>
<span id="cb18-50">                <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.98</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>, <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Source : </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>src<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb18-51">                transform<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>ax.transAxes, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>, style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"italic"</span>, va<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>, ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>,</span>
<span id="cb18-52">            )</span>
<span id="cb18-53"></span>
<span id="cb18-54">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> idx <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(available_scatter), n_rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> n_cols):</span>
<span id="cb18-55">            row, col_idx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">divmod</span>(idx, n_cols)</span>
<span id="cb18-56">            <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> n_rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>:</span>
<span id="cb18-57">                axes[row][col_idx].set_visible(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span>
<span id="cb18-58">            <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb18-59">                axes[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>][col_idx].set_visible(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span>
<span id="cb18-60"></span>
<span id="cb18-61">        fig.suptitle(</span>
<span id="cb18-62">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Relations bivariées : surendettement vs. prédicteurs (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>,</span>
<span id="cb18-63">            fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">13</span>, fontweight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.01</span>,</span>
<span id="cb18-64">        )</span>
<span id="cb18-65">        fig.text(</span>
<span id="cb18-66">            <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>,</span>
<span id="cb18-67">            <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Source : Banque de France, INSEE, DREES. Données </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> — 96 départements métropolitains. "</span></span>
<span id="cb18-68">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Chaque point représente un département. La droite de régression indique la tendance linéaire."</span>,</span>
<span id="cb18-69">            ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"italic"</span>, wrap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb18-70">        )</span>
<span id="cb18-71">        plt.tight_layout()</span>
<span id="cb18-72">        plt.show()</span>
<span id="cb18-73">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb18-74">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(</span>
<span id="cb18-75">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Graphiques bivariés limités aux variables disponibles.</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb18-76">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Variables FiLoSoFi, RP, minimas sociaux indisponibles — "</span></span>
<span id="cb18-77">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"seul le chômage peut être représenté une fois les données téléchargées."</span></span>
<span id="cb18-78">        )</span>
<span id="cb18-79">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Scatter chômage seul si disponible</span></span>
<span id="cb18-80">        x_data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_2021[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux"</span>], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb18-81">        y_data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_2021[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb18-82">        valid  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame({<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>: x_data, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>: y_data}).dropna()</span>
<span id="cb18-83">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(valid) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>:</span>
<span id="cb18-84">            <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> stats <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> scipy_stats</span>
<span id="cb18-85">            fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb18-86">            ax.scatter(valid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>], valid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>], color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_CYAN, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>, s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>)</span>
<span id="cb18-87">            slope, intercept, r_val, p_val, _ <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> scipy_stats.linregress(valid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>], valid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>])</span>
<span id="cb18-88">            x_line <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.linspace(valid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">min</span>(), valid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">max</span>(), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb18-89">            ax.plot(x_line, intercept <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> slope <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x_line, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_RED, linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb18-90">                    label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"r=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>r_val<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.2f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">, p=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'&lt;0,001'</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>p_val<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb18-91">            ax.legend(fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>)</span>
<span id="cb18-92">            ax.set_xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taux de chômage (%)"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb18-93">            ax.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dossiers de surendettement (nb)"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb18-94">            ax.set_title(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Surendettement vs. Chômage (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>, fontweight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>)</span>
<span id="cb18-95">            ax.grid(alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>)</span>
<span id="cb18-96">            fig.text(</span>
<span id="cb18-97">                <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.04</span>,</span>
<span id="cb18-98">                <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Source : Banque de France (surendettement), INSEE chômage localisé (chômage). </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> — 96 départements."</span>,</span>
<span id="cb18-99">                ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"italic"</span></span>
<span id="cb18-100">            )</span>
<span id="cb18-101">            plt.tight_layout()</span>
<span id="cb18-102">            plt.show()</span>
<span id="cb18-103"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb18-104">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Données EDA non disponibles — exécuter les scripts 01-04 d'abord."</span>)</span></code></pre></div>
</details>
<div class="cell-output cell-output-display page-columns page-full">
<div id="fig-scatter-bivariate" class="quarto-figure quarto-figure-center quarto-float anchored page-columns page-full" alt="Quatre nuages de points : surendettement (axe Y) en fonction du chômage, de la pauvreté, du RSA et de la part de locataires (axe X). Chaque graphique inclut une droite de régression rouge.">
<figure class="quarto-float quarto-float-fig figure page-columns page-full">
<div aria-describedby="fig-scatter-bivariate-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca" class="page-columns page-full">
<img src="https://ggilles.dev/posts/dataviz-bdf/index_files/figure-html/fig-scatter-bivariate-output-1.png" class="img-fluid figure-img column-screen-inset" alt="Quatre nuages de points : surendettement (axe Y) en fonction du chômage, de la pauvreté, du RSA et de la part de locataires (axe X). Chaque graphique inclut une droite de régression rouge.">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-scatter-bivariate-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;11: Nuages de points bivariés : taux de surendettement vs.&nbsp;chaque prédicteur principal (année de référence). La droite de régression linéaire est représentée en rouge. Source : BdF, INSEE, DREES.
</figcaption>
</figure>
</div>
</div>
</div>
<hr>
</section>
</section>
<section id="sec-conclusion" class="level2">
<h2 class="anchored" data-anchor-id="sec-conclusion">Conclusion</h2>
<p>Cette section récapitule les résultats en répondant aux trois questions de recherche posées en introduction, puis expose les limites méthodologiques de l’analyse et les pistes d’extension pour des travaux futurs.</p>
<section id="réponses-aux-questions-de-recherche" class="level3">
<h3 class="anchored" data-anchor-id="réponses-aux-questions-de-recherche">Réponses aux questions de recherche</h3>
<p><strong>1. Quelles variables économiques sont les plus corrélées au taux de surendettement ?</strong></p>
<div id="conclusion-q1" class="cell" data-execution_count="23">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb19-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> EDA_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> df_2021.columns <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">or</span> (EDA_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> df_2021.columns):</span>
<span id="cb19-2">    <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> stats <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> scipy_stats</span>
<span id="cb19-3">    y_col_c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">not</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> df_2021.columns <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">or</span> pd.to_numeric(df_2021.get(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span>), errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>).notna().<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_taux"</span></span>
<span id="cb19-4">    corr_candidates <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"taux_pauvrete"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rsa_taux"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part_locataires"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part_familles_mono"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"revenu_median_uc"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"score_fragilite"</span>]</span>
<span id="cb19-5">    results_q1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb19-6">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> var <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> corr_candidates:</span>
<span id="cb19-7">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> var <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> df_2021.columns:</span>
<span id="cb19-8">            x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_2021[var], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb19-9">            y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_2021[y_col_c], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb19-10">            valid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame({<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>: x, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>: y}).dropna()</span>
<span id="cb19-11">            <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(valid) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>:</span>
<span id="cb19-12">                r, p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> scipy_stats.pearsonr(valid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>], valid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>])</span>
<span id="cb19-13">                results_q1.append((var, r, p, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(valid)))</span>
<span id="cb19-14">    results_q1.sort(key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">lambda</span> x: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(x[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]), reverse<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb19-15"></span>
<span id="cb19-16">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> results_q1:</span>
<span id="cb19-17">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Variables par ordre de corrélation (Pearson) avec le surendettement :"</span>)</span>
<span id="cb19-18">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> var, r, p, n <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> results_q1:</span>
<span id="cb19-19">            sig <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"***"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"**"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"*"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(ns)"</span>))</span>
<span id="cb19-20">            <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"  </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>var<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:&lt;30}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> r = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:+.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sig<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  (n=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>)</span>
<span id="cb19-21">        top_var <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> results_q1[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> results_q1 <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"données insuffisantes"</span></span>
<span id="cb19-22">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">→ Prédicteur le plus corrélé au millésime </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>YEAR_TARGET<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> : </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>top_var<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb19-23">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb19-24">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"→ Analyse de corrélation : seule la variable 'chomage_taux' est disponible (autres sources non téléchargées)."</span>)</span>
<span id="cb19-25">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"  Le chômage départemental présente une corrélation positive avec le nombre de dossiers de surendettement."</span>)</span>
<span id="cb19-26"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb19-27">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"→ Données insuffisantes pour répondre à cette question — exécuter le pipeline complet."</span>)</span></code></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Variables par ordre de corrélation (Pearson) avec le surendettement :
  revenu_median_uc               r = -0.509  ***  (n=96)
  chomage_taux                   r = +0.463  ***  (n=96)
  rsa_taux                       r = +0.433  ***  (n=96)
  taux_pauvrete                  r = +0.372  ***  (n=96)
  score_fragilite                r = +0.370  ***  (n=96)
  part_locataires                r = -0.121  (ns)  (n=96)
  part_familles_mono             r = +0.120  (ns)  (n=96)

→ Prédicteur le plus corrélé au millésime 2024 : revenu_median_uc</code></pre>
</div>
</div>
<p><strong>2. Les effets du chômage et de la pauvreté sont-ils contemporains ou décalés ?</strong></p>
<div id="conclusion-q2" class="cell" data-execution_count="24">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb21-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> OLS_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lag"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> ols_results <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"base"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> ols_results:</span>
<span id="cb21-2">    m_b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ols_results[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"base"</span>][<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"model"</span>]</span>
<span id="cb21-3">    m_l <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ols_results[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lag"</span>][<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"model"</span>]</span>
<span id="cb21-4">    delta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> m_l.rsquared_adj <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> m_b.rsquared_adj</span>
<span id="cb21-5">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> delta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>:</span>
<span id="cb21-6">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"→ Les effets de lag t-1 améliorent le R² ajusté (Δ = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>delta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:+.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">). Le chômage et la pauvreté exercent un effet différé sur le surendettement."</span>)</span>
<span id="cb21-7">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb21-8">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"→ Les effets contemporains dominent (Δ R² ajusté = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>delta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:+.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">). L'association chômage-surendettement est essentiellement simultanée à l'échelle annuelle."</span>)</span>
<span id="cb21-9"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">elif</span> DATA_AVAILABLE:</span>
<span id="cb21-10">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Vérifier avec les données disponibles (chômage uniquement)</span></span>
<span id="cb21-11">    df_lag <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df[df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"annee"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> YEAR_TARGET][[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_code"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux_t1"</span>]].copy()</span>
<span id="cb21-12">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> c <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">in</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux_t1"</span>]:</span>
<span id="cb21-13">        df_lag[c] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_lag[c], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb21-14">    df_lag <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_lag.dropna()</span>
<span id="cb21-15">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(df_lag) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>:</span>
<span id="cb21-16">        <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> stats <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> scipy_stats</span>
<span id="cb21-17">        r_contemp, _ <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> scipy_stats.pearsonr(df_lag[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux"</span>], df_lag[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>])</span>
<span id="cb21-18">        r_lag, _ <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> scipy_stats.pearsonr(df_lag[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chomage_taux_t1"</span>], df_lag[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>])</span>
<span id="cb21-19">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"→ Corrélation chômage contemporain vs. surendettement : r = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>r_contemp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb21-20">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"→ Corrélation chômage t-1 vs. surendettement : r = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>r_lag<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb21-21">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(r_lag) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(r_contemp):</span>
<span id="cb21-22">            <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"  → L'effet du chômage est légèrement plus fort avec un lag d'un an."</span>)</span>
<span id="cb21-23">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb21-24">            <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"  → L'effet du chômage contemporain domine sur le chômage décalé."</span>)</span>
<span id="cb21-25">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb21-26">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"→ Données insuffisantes pour comparer effets contemporains et décalés."</span>)</span>
<span id="cb21-27"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb21-28">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"→ Données non disponibles."</span>)</span></code></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>→ Les effets contemporains dominent (Δ R² ajusté = +0.000). L'association chômage-surendettement est essentiellement simultanée à l'échelle annuelle.</code></pre>
</div>
</div>
<p><strong>3. Le score de fragilité composite est-il prédictif du surendettement ?</strong></p>
<div id="conclusion-q3" class="cell" data-execution_count="25">
<details class="code-fold">
<summary>Voir le code</summary>
<div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb23-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> DATA_AVAILABLE <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">and</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(df) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>:</span>
<span id="cb23-2">    df_q3 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df[df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"annee"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> YEAR_TARGET][[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dep_code"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"score_fragilite"</span>]].copy()</span>
<span id="cb23-3">    df_q3[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_q3[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb23-4">    df_q3[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"score_fragilite"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(df_q3[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"score_fragilite"</span>], errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coerce"</span>)</span>
<span id="cb23-5">    df_q3 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_q3.dropna()</span>
<span id="cb23-6"></span>
<span id="cb23-7">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(df_q3) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>:</span>
<span id="cb23-8">        <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> stats <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> scipy_stats</span>
<span id="cb23-9">        r_score, p_score <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> scipy_stats.pearsonr(df_q3[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"score_fragilite"</span>], df_q3[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"suren_depot_nb"</span>])</span>
<span id="cb23-10">        sig <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"***"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p_score <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"**"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p_score <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"*"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> p_score <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(ns)"</span>))</span>
<span id="cb23-11">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"→ Corrélation score de fragilité – surendettement : r = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>r_score<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sig<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> (n=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(df_q3)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>)</span>
<span id="cb23-12">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(r_score) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>:</span>
<span id="cb23-13">            <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"  → Le score composite présente une association forte avec le surendettement."</span>)</span>
<span id="cb23-14">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">elif</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(r_score) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>:</span>
<span id="cb23-15">            <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"  → Le score composite présente une association modérée avec le surendettement."</span>)</span>
<span id="cb23-16">        <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb23-17">            <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"  → Association faible — le score composite nécessite l'ajout de données FiLoSoFi/RP/Minimas pour être prédictif."</span>)</span>
<span id="cb23-18">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb23-19">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"→ Données insuffisantes pour évaluer le score de fragilité."</span>)</span>
<span id="cb23-20"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">else</span>:</span>
<span id="cb23-21">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"→ Données non disponibles."</span>)</span></code></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>→ Corrélation score de fragilité – surendettement : r = 0.406 *** (n=96)
  → Le score composite présente une association modérée avec le surendettement.</code></pre>
</div>
</div>
</section>
<section id="limites-et-perspectives" class="level3">
<h3 class="anchored" data-anchor-id="limites-et-perspectives">Limites et perspectives</h3>
<p><strong>Limites de l’analyse :</strong></p>
<ul>
<li><strong>Couverture FiLoSoFi</strong> : les données de revenus, pauvreté et indicateurs de distribution (Gini) sont partiellement disponibles ou d’un millésime antérieur (2019 pour Gini). L’OLS multivarié est donc indicatif.</li>
<li><strong>Absence de correction spatiale</strong> : les cartes choroplèthes révèlent une auto-corrélation spatiale probable (clustering Nord, Île-de-France) qui n’est pas prise en compte dans le modèle OLS standard.</li>
<li><strong>Biais de composition</strong> : les taux de surendettement bruts (sans pondération par le nombre de ménages) peuvent avantager les grands départements.</li>
<li><strong>Causalité</strong> : les corrélations observées ne permettent pas d’établir des relations causales.</li>
</ul>
<p><strong>Perspectives d’extension :</strong></p>
<ul>
<li>Régression spatiale (SAR/SLM) pour corriger l’autocorrélation spatiale et calculer l’indice de Moran’s I</li>
<li>Intégration des données FiLoSoFi complètes (revenu médian, taux de pauvreté, Gini) pour enrichir le modèle</li>
<li>Analyse longitudinale (effets fixes département) sur 2018–2023</li>
<li>Décomposition du score de fragilité composite avec pondération empirique</li>
<li>Comparaison entre millésimes pour quantifier l’effet des politiques publiques (prime d’activité, RSA, plan pauvreté)</li>
</ul>
<blockquote class="blockquote">
<p><strong>Sources</strong> : Banque de France (synthèses surendettement 2018–2024), INSEE FiLoSoFi 2021, INSEE chômage localisé, INSEE RP 2021, DREES (indicateurs sociaux départementaux). Périmètre : 96 départements métropolitains (DOM-TOM exclus).</p>
</blockquote>


</section>
</section>

 ]]></description>
  <guid>https://ggilles.dev/posts/dataviz-bdf/</guid>
  <pubDate>Sun, 17 May 2026 22:00:00 GMT</pubDate>
  <media:content url="https://ggilles.dev/posts/dataviz-bdf/image.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>Adding an AI Chat Assistant to a Static Website</title>
  <link>https://ggilles.dev/posts/resume-chat/</link>
  <description><![CDATA[ 




<section id="why-bother" class="level2">
<h2 class="anchored" data-anchor-id="why-bother">Why bother?</h2>
<p>A PDF résumé is a frozen snapshot. Visitors have to skim it, guess what is relevant to them, and hope they find the right section. A recruiter looking for Python experience and a professor curious about your teaching history need very different things — but they both have to read the same document.</p>
<p>An AI assistant changes that dynamic. Instead of making the visitor do the work, you let them ask in plain language: <em>“Does he have any experience with time-series forecasting?”</em> or <em>“What level does he teach at?”</em> and get a direct, personalised answer in seconds.</p>
<p>The goal of this post is to build exactly that, in a way that is:</p>
<ul>
<li><strong>Free</strong> — Cloudflare Workers has a generous free tier (100,000 requests/day); Cloudflare Workers AI also runs on the free tier, so this stack costs nothing to operate.</li>
<li><strong>Maintenance-free</strong> — no server to patch, no database, no uptime to worry about.</li>
<li><strong>Portable</strong> — the approach works with any static site generator (Quarto, Hugo, Jekyll, plain HTML…).</li>
</ul>
</section>
<section id="the-big-picture" class="level2">
<h2 class="anchored" data-anchor-id="the-big-picture">The big picture</h2>
<p>Three moving parts, one simple flow:</p>
<pre><code>Visitor's browser
      │  1. types a question
      ▼
Chat widget (HTML/JS)
      │  2. POST { message, history } to Worker URL
      ▼
Cloudflare Worker  ──►  Cloudflare Workers AI
      │                     │
      │  3. system prompt   │  4. returns answer
      │     + message       │
      ◄─────────────────────┘
      │  5. forwards { reply }
      ▼
Chat widget displays reply</code></pre>
<p><strong>The widget</strong> is an inline HTML+JS block in <code>index.qmd</code>. It captures the visitor’s message and sends it to the Worker.</p>
<p><strong>The Worker</strong> is a tiny JavaScript function running on Cloudflare’s global edge network. It prepends a <em>system prompt</em> containing your full background, then forwards the conversation to Cloudflare Workers AI using the <code>env.AI</code> binding — no external API key required.</p>
<p><strong>The key insight</strong> is that the browser never talks to the AI model directly — everything goes through your Worker, where you can add rate limits or filters later if you need them.</p>
<hr>
</section>
<section id="part-1-the-cloudflare-worker" class="level2">
<h2 class="anchored" data-anchor-id="part-1-the-cloudflare-worker">Part 1 — The Cloudflare Worker</h2>
<p><a href="https://developers.cloudflare.com/workers/wrangler/">Wrangler</a> is the official Cloudflare CLI. Install it once, authenticate, and you’re ready to deploy:</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">npm</span> install <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-g</span> wrangler</span>
<span id="cb2-2"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">wrangler</span> login   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># opens a browser window for OAuth</span></span></code></pre></div>
<p>The project needs two files inside a <code>worker/</code> directory at your site root.</p>
<pre><code>website/
├── assets/
│   └── dark.scss          # site theme — includes chat widget styles
├── posts/
│   └── resume-chat/
│       └── index.qmd      # this post
├── worker/
│   ├── index.js           # Cloudflare Worker — calls Workers AI, returns reply
│   └── wrangler.toml      # Worker config — AI binding, model var, deployment
├── _quarto.yml            # site-wide Quarto config
└── index.qmd              # landing page — embeds the chat widget</code></pre>
<p><code>wrangler.toml</code> is the configuration:</p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode toml code-with-copy"><code class="sourceCode toml"><span id="cb4-1"><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">name</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"resume-chat"</span></span>
<span id="cb4-2"><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">main</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"index.js"</span></span>
<span id="cb4-3"><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">compatibility_date</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2024-09-01"</span></span>
<span id="cb4-4"></span>
<span id="cb4-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">[ai]</span></span>
<span id="cb4-6"><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">binding</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AI"</span></span>
<span id="cb4-7"></span>
<span id="cb4-8"><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">[vars]</span></span>
<span id="cb4-9"><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">AI_MODEL</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"@cf/meta/llama-3.1-8b-instruct"</span></span></code></pre></div>
<p><code>name</code> sets the subdomain (<code>resume-chat.&lt;account&gt;.workers.dev</code>); <code>main</code> points to the Worker entry-point. The <code>[ai]</code> binding gives the Worker access to <code>env.AI</code> — Cloudflare’s built-in AI runtime, no external API key needed. <code>AI_MODEL</code> in <code>[vars]</code> makes the model configurable: change it in <code>wrangler.toml</code> and redeploy without touching any code.</p>
<p>The real work happens in <code>index.js</code>. Scroll through the walkthrough below.</p>
<div class="cr-section cr-column-screen sidebar-left">
<div class="narrative-col">
<div class="trigger new-trigger" data-focus-on="cr-prompt">
<div class="narrative">
<p>Here is a walkthrough of <code>worker/index.js</code>. Every section has a job — let’s go through them one by one.</p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-prompt">
<div class="narrative">
<p><strong>The system prompt</strong> is the most important part of the setup. It is prepended to <em>every</em> conversation before the visitor’s message. The instruction <em>“based strictly on the information below”</em> keeps the model from hallucinating anything that isn’t in your résumé. Keep this section updated whenever your situation changes.</p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-cors">
<div class="narrative">
<p><strong>CORS headers</strong> tell the browser that your Worker accepts cross-origin requests. Your widget lives on <code>ggilles.dev</code>; the Worker lives on <code>workers.dev</code> — without these headers, the browser would silently block every fetch. Setting <code>https://ggilles.dev</code> restricts access to the Worker only from your exact domain.</p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-preflight">
<div class="narrative">
<p><strong>The OPTIONS preflight</strong> is an automatic browser check sent before every cross-origin POST: <em>“Are you OK with this?”</em> The Worker must respond to it correctly, or the real request never goes through. Parsing the body is straightforward but worth wrapping in a try/catch — you want clear error responses rather than uncaught exceptions if something malformed hits the endpoint.</p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-messages">
<div class="narrative">
<p><strong>Building the messages array</strong> is where context lives. The system prompt anchors every conversation. <code>history.slice(-6)</code> keeps the last three exchanges (six messages: three user, three assistant) so the model can handle follow-up questions without ballooning the token count.</p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-ai">
<div class="narrative">
<p><strong>Calling Cloudflare Workers AI</strong> uses <code>env.AI.run()</code> with the model read from <code>env.AI_MODEL</code> (falling back to <code>@cf/meta/llama-3.1-8b-instruct</code> if the variable is unset). Keeping the model name in <code>wrangler.toml</code> means you can swap it without touching the Worker code — just edit <code>[vars]</code> and redeploy. <code>max_tokens: 400</code> caps reply length. The call is wrapped in a try/catch so failures return a clean, user-friendly error. On success, the Worker sends the browser a clean <code>{ reply: "…" }</code> JSON object with CORS headers attached so the browser actually accepts it.</p>
</div>
</div>
</div>
<div class="sticky-col">
<div class="sticky-col-stack">
<div id="cr-prompt" class="sticky">
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb5-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> SYSTEM_PROMPT <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`You are an AI assistant representing Guillaume Gilles.</span></span>
<span id="cb5-2"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">Answer questions based strictly on the information below.</span></span>
<span id="cb5-3"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">Be concise, friendly, and professional.</span></span>
<span id="cb5-4"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">If asked about something not covered, say you don't have that information.</span></span>
<span id="cb5-5"></span>
<span id="cb5-6"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">--- PROFILE / EXPERIENCE / EDUCATION / SKILLS ---</span></span>
<span id="cb5-7"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">…`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div>
</div>
<div id="cr-cors" class="sticky">
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb6-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> CORS_HEADERS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb6-2">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Access-Control-Allow-Origin"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://ggilles.dev"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-3">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Access-Control-Allow-Methods"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"POST, OPTIONS"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-4">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Access-Control-Allow-Headers"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Content-Type"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-5">}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div>
</div>
<div id="cr-preflight" class="sticky">
<div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb7-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">export</span> <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">default</span> {</span>
<span id="cb7-2">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">async</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fetch</span>(request<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> env) {</span>
<span id="cb7-3"></span>
<span id="cb7-4">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> (request<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OPTIONS"</span>) {</span>
<span id="cb7-5">      <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">new</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Response</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">headers</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> CORS_HEADERS })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb7-6">    }</span>
<span id="cb7-7"></span>
<span id="cb7-8">    <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">let</span> body<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb7-9">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">try</span> {</span>
<span id="cb7-10">      body <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">await</span> request<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">json</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb7-11">    } <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">catch</span> {</span>
<span id="cb7-12">      <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">new</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Response</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Invalid JSON"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">status</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">400</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb7-13">    }</span>
<span id="cb7-14"></span>
<span id="cb7-15">    <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> { message<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> history <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [] } <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> body<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb7-16">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-17">}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div>
</div>
<div id="cr-messages" class="sticky">
<div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb8-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> messages <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb8-2">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">role</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"system"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">content</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> SYSTEM_PROMPT }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb8-3">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>history<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb8-4">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">role</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"user"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">content</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> message }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb8-5">]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div>
</div>
<div id="cr-ai" class="sticky">
<div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb9-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">let</span> reply<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-2"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">try</span> {</span>
<span id="cb9-3">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> aiRes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">await</span> env<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AI</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">run</span>(</span>
<span id="cb9-4">    env<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AI_MODEL</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">??</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"@cf/meta/llama-3.1-8b-instruct"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb9-5">    { messages<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">max_tokens</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">400</span> }</span>
<span id="cb9-6">  )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-7">  reply <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> aiRes<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">response</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-8">} <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">catch</span> (err) {</span>
<span id="cb9-9">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">new</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Response</span>(</span>
<span id="cb9-10">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">JSON</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stringify</span>({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">error</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AI service unavailable. Please try again later."</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb9-11">    { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">status</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">502</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">headers</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Content-Type"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"application/json"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>CORS_HEADERS } }</span>
<span id="cb9-12">  )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-13">}</span>
<span id="cb9-14"></span>
<span id="cb9-15"><span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">new</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Response</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">JSON</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stringify</span>({ reply })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb9-16">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">headers</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Content-Type"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"application/json"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>CORS_HEADERS }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb9-17">})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div>
</div>
</div>
</div>
</div>
<section id="deploying" class="level3">
<h3 class="anchored" data-anchor-id="deploying">Deploying</h3>
<p>No secrets to manage — the AI binding is configured in <code>wrangler.toml</code> and Cloudflare handles everything else. Just deploy:</p>
<div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb10-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">cd</span> worker/</span>
<span id="cb10-2"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">wrangler</span> deploy</span>
<span id="cb10-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># → Deployed: https://resume-chat.&lt;account&gt;.workers.dev</span></span></code></pre></div>
<p>Test it immediately from the terminal:</p>
<div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb11-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">curl</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-X</span> POST https://resume-chat.<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>account<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>.workers.dev <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb11-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-H</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Content-Type: application/json"</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb11-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-d</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'{"message": "What is his current job?"}'</span></span>
<span id="cb11-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># → {"reply":"Guillaume is currently a Regional Economist at the Banque de France…"}</span></span></code></pre></div>
<hr>
</section>
</section>
<section id="part-2-the-chat-widget" class="level2">
<h2 class="anchored" data-anchor-id="part-2-the-chat-widget">Part 2 — The chat widget</h2>
<p>The widget is a raw HTML block embedded directly in <code>index.qmd</code> using Quarto’s <code>{=html}</code> fence. It has two parts: markup and JavaScript.</p>
<div class="cr-section cr-column-screen sidebar-left">
<div class="narrative-col">
<div class="trigger new-trigger" data-focus-on="cr-html">
<div class="narrative">
<p>The complete widget — HTML structure up top, self-contained JavaScript below. Let’s walk through it.</p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-html">
<div class="narrative">
<p><strong>The HTML structure</strong> is minimal on purpose. <code>#chat-box</code> is a flex column: <code>#chat-messages</code> scrolls vertically as the conversation grows; <code>#chat-input-row</code> stays pinned at the bottom. No toggles, no overlays — the box lives inline in the page, right below the landing page text.</p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-state">
<div class="narrative">
<p><strong><code>WORKER_URL</code></strong> is the only value you need to change when you adapt this for your own site. <code>history</code> accumulates the conversation turn by turn; <code>busy</code> is a simple mutex that prevents double-sends while a fetch is in flight.</p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-append">
<div class="narrative">
<p><strong><code>appendMsg</code></strong> is a small factory: it creates a <code>div</code>, stamps it with the right CSS class (<code>user</code> or <code>bot</code>), appends it to the message area, and scrolls to the bottom. It returns the element so the caller can mutate it later — e.g.&nbsp;replace “Thinking…” with the actual reply in place.</p>
</div>
</div>
<div class="trigger new-trigger" data-focus-on="cr-send">
<div class="narrative">
<p><strong><code>sendMessage</code></strong> opens with a guard clause — if the input is empty or a fetch is already running, it exits immediately. It then clears the input, renders the user bubble, and shows a “Thinking…” placeholder that gets replaced in-place once the response arrives. Both sides of the exchange are pushed into <code>history</code> for the next round. Error handling covers the case where the Worker is unreachable: after either path the busy flag is reset, the Send button re-enabled, and focus returned to the input.</p>
</div>
</div>
</div>
<div class="sticky-col">
<div class="sticky-col-stack">
<div id="cr-html" class="sticky">
<div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode html code-with-copy"><code class="sourceCode html"><span id="cb12-1"><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">div</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;"> id</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chat-box"</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb12-2">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">div</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;"> id</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chat-messages"</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb12-3">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">div</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;"> class</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chat-msg bot"</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb12-4">      Hi! I'm an AI assistant. Ask me anything</span>
<span id="cb12-5">      about Guillaume's background. 👋</span>
<span id="cb12-6">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;/</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">div</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb12-7">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;/</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">div</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb12-8">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">div</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;"> id</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chat-input-row"</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb12-9">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">input</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;"> id</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chat-input"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;"> type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span></span>
<span id="cb12-10"><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">           placeholder</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"e.g. What's his Python experience?"</span></span>
<span id="cb12-11"><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">           autocomplete</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"off"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;"> </span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">/&gt;</span></span>
<span id="cb12-12">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">button</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;"> id</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chat-send"</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span>Send<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;/</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">button</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb12-13">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;/</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">div</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb12-14"><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;/</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">div</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span></span></code></pre></div>
</div>
<div id="cr-state" class="sticky">
<div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb13-1">(<span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span> () {</span>
<span id="cb13-2">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> WORKER_URL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://resume-chat.&lt;account&gt;.workers.dev"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb13-3"></span>
<span id="cb13-4">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> msgs  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getElementById</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chat-messages"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb13-5">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> input <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getElementById</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chat-input"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb13-6">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> send  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getElementById</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chat-send"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb13-7">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">let</span> history <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb13-8">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">let</span> busy    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb13-9"></span>
<span id="cb13-10">  send<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">addEventListener</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"click"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> sendMessage)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb13-11">  input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">addEventListener</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"keydown"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> (e) <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb13-12">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> (e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">key</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Enter"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shiftKey</span>) {</span>
<span id="cb13-13">      e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">preventDefault</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sendMessage</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb13-14">    }</span>
<span id="cb13-15">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb13-16">})()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div>
</div>
<div id="cr-append" class="sticky">
<div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb14-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appendMsg</span>(text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> role) {</span>
<span id="cb14-2">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> div <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">createElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"div"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb14-3">  div<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">className</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`chat-msg </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>role<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb14-4">  div<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">textContent</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb14-5">  msgs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appendChild</span>(div)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb14-6">  msgs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scrollTop</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> msgs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scrollHeight</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb14-7">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> div<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb14-8">}</span></code></pre></div>
</div>
<div id="cr-send" class="sticky">
<div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb15-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">async</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sendMessage</span>() {</span>
<span id="cb15-2">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> text <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">trim</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-3">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>text <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> busy) <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-4">  busy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> send<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disabled</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-5"></span>
<span id="cb15-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appendMsg</span>(text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"user"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-7">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> thinking <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appendMsg</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Thinking…"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bot typing"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-8"></span>
<span id="cb15-9">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">try</span> {</span>
<span id="cb15-10">    <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> res <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">await</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fetch</span>(WORKER_URL<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb15-11">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">method</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"POST"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-12">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">headers</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Content-Type"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"application/json"</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-13">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">body</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">JSON</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stringify</span>({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">message</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> history })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-14">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-15">    <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">await</span> res<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">json</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-16">    <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> reply <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reply</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">error</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Something went wrong."</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-17">    thinking<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">className</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chat-msg bot"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-18">    thinking<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">textContent</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> reply<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-19">    history<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">role</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"user"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">content</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> text  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-20">    history<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">role</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"assistant"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">content</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> reply })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-21">  } <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">catch</span> {</span>
<span id="cb15-22">    thinking<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">className</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chat-msg bot"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-23">    thinking<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">textContent</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⚠️ Could not reach the assistant."</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-24">  }</span>
<span id="cb15-25"></span>
<span id="cb15-26">  busy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> send<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disabled</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-27">  input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">focus</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> msgs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scrollTop</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> msgs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scrollHeight</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-28">}</span></code></pre></div>
</div>
</div>
</div>
</div>
<hr>
</section>
<section id="part-3-integrating-with-quarto" class="level2">
<h2 class="anchored" data-anchor-id="part-3-integrating-with-quarto">Part 3 — Integrating with Quarto</h2>
<p>Quarto’s <code>{=html}</code> raw block passes content through to the rendered page verbatim. Drop the widget anywhere in a <code>.qmd</code> file:</p>
<pre class="qmd"><code>```{=html}
&lt;div id="chat-box"&gt;
  …
&lt;/div&gt;
&lt;script&gt;
(function () {
  const WORKER_URL = "https://resume-chat.&lt;account&gt;.workers.dev";
  …
})();
&lt;/script&gt;
```</code></pre>
<p>Because the block is scoped to <code>index.qmd</code>, the widget only appears on the landing page — not on blog posts or teaching pages, where it would be out of place. If you later want it site-wide, Quarto’s <code>include-after-body</code> option in <code>_quarto.yml</code> can inject an HTML file into every page instead.</p>
<hr>
</section>
<section id="putting-it-all-together" class="level2">
<h2 class="anchored" data-anchor-id="putting-it-all-together">Putting it all together</h2>
<div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb17-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 1. Install Wrangler</span></span>
<span id="cb17-2"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">npm</span> install <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-g</span> wrangler</span>
<span id="cb17-3"></span>
<span id="cb17-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 2. Authenticate with Cloudflare (creates a free account if needed)</span></span>
<span id="cb17-5"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">wrangler</span> login</span>
<span id="cb17-6"></span>
<span id="cb17-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 3. Deploy the Worker (the [ai] binding in wrangler.toml is all you need)</span></span>
<span id="cb17-8"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">cd</span> worker/</span>
<span id="cb17-9"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">wrangler</span> deploy</span>
<span id="cb17-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Note the URL printed: https://resume-chat.&lt;subdomain&gt;.workers.dev</span></span>
<span id="cb17-11"></span>
<span id="cb17-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 4. Update the widget with your Worker URL</span></span>
<span id="cb17-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Open index.qmd and change:</span></span>
<span id="cb17-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#   const WORKER_URL = "https://resume-chat.YOUR-SUBDOMAIN.workers.dev";</span></span>
<span id="cb17-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># to your actual URL.</span></span>
<span id="cb17-16"></span>
<span id="cb17-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 5. Rebuild the landing page</span></span>
<span id="cb17-18"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">cd</span> ..</span>
<span id="cb17-19"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">quarto</span> render index.qmd</span>
<span id="cb17-20"></span>
<span id="cb17-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 6. Publish</span></span>
<span id="cb17-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> add <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-A</span></span>
<span id="cb17-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> commit <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-m</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Add AI résumé chat assistant"</span></span>
<span id="cb17-24"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> push</span></code></pre></div>
<hr>
</section>
<section id="what-to-customise" class="level2">
<h2 class="anchored" data-anchor-id="what-to-customise">What to customise</h2>
<p><strong>Update the résumé content</strong> — open <code>worker/index.js</code> and edit the <code>SYSTEM_PROMPT</code> string. Then run <code>wrangler deploy</code> again to push the update. The website itself does not need to be rebuilt.</p>
<p><strong>Show the widget on every page</strong> — instead of embedding it in <code>index.qmd</code>, use Quarto’s <code>include-after-body</code> option in <code>_quarto.yml</code>:</p>
<div class="sourceCode" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb18-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">:</span></span>
<span id="cb18-2"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">:</span></span>
<span id="cb18-3"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">    </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">include-after-body</span><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> _partials/chat-widget.html</span></span></code></pre></div>
<p>Move the HTML+JS block to <code>_partials/chat-widget.html</code> and <code>quarto render</code> will inject it at the bottom of every page.</p>
<p><strong>Update the CORS origin</strong> — the Worker is already restricted to a single origin. When you adapt this for your own site, change <code>ggilles.dev</code> to your domain in <code>worker/index.js</code>:</p>
<div class="sourceCode" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb19-1"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Access-Control-Allow-Origin"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://your-domain.com"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span></code></pre></div>
<p><strong>Swap the model</strong> — edit <code>AI_MODEL</code> in <code>wrangler.toml</code> and run <code>wrangler deploy</code>. No code change needed:</p>
<div class="sourceCode" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode toml code-with-copy"><code class="sourceCode toml"><span id="cb20-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">[vars]</span></span>
<span id="cb20-2"><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">AI_MODEL</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"@cf/mistral/mistral-7b-instruct-v0.1"</span></span></code></pre></div>
<p>Browse the full catalogue at <a href="https://developers.cloudflare.com/workers-ai/models/">developers.cloudflare.com/workers-ai/models</a>.</p>
<hr>
</section>
<section id="closing-thoughts" class="level2">
<h2 class="anchored" data-anchor-id="closing-thoughts">Closing thoughts</h2>
<p>The whole implementation is roughly 150-200 lines of code spread across three files (<code>worker/index.js</code>, <code>assets/dark.scss</code>, and the raw HTML block in <code>index.qmd</code>). Despite its small footprint, it covers several important concepts that show up in many real-world projects: serverless functions, CORS, prompt engineering, and progressive enhancement (the site works perfectly for visitors who never open the chat).</p>
<p>If you replicate this on your own site, feel free to open a <a href="https://github.com/guillaumegilles/guillaumegilles.github.io">GitHub issue</a> or reach out on <a href="https://www.linkedin.com/in/guillaumegilles">LinkedIn</a> — I’d be happy to help you debug it.</p>
<script>
document.addEventListener('DOMContentLoaded', () => {
  const toc = document.querySelector('#TOC, .sidebar.toc-left, nav[role="doc-toc"]');
  const crSections = document.querySelectorAll('.cr-section');
  if (!toc || !crSections.length) return;
  const observer = new IntersectionObserver((entries) => {
    const anyVisible = entries.some(e => e.isIntersecting);
    toc.style.visibility = anyVisible ? 'hidden' : 'visible';
    toc.style.opacity    = anyVisible ? '0'       : '1';
    toc.style.transition = 'opacity 0.2s, visibility 0.2s';
  }, { threshold: 0 });
  crSections.forEach(s => observer.observe(s));
});
</script>


</section>

 ]]></description>
  <category>AI</category>
  <category>Cloudflare</category>
  <category>Quarto</category>
  <category>Web</category>
  <guid>https://ggilles.dev/posts/resume-chat/</guid>
  <pubDate>Sat, 07 Mar 2026 23:00:00 GMT</pubDate>
  <media:content url="https://ggilles.dev/posts/resume-chat/image.jpg" medium="image" type="image/jpeg"/>
</item>
</channel>
</rss>
