<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 600">
    <!-- Background -->
    <rect width="800" height="600" fill="#f8f9fa" rx="10" ry="10" />

    <!-- Title -->
    <text x="400" y="50" font-family="Arial, sans-serif" font-size="24" font-weight="bold"
        text-anchor="middle" fill="#333">XGBoost Algorithm</text>
    <text x="400" y="80" font-family="Arial, sans-serif" font-size="16" text-anchor="middle"
        fill="#666">Gradient Boosting with Decision Trees</text>

    <!-- Main flow diagram -->
    <g transform="translate(0, 20)">
        <!-- Step 1: Initial Model -->
        <rect x="100" y="120" width="160" height="80" rx="5" ry="5" fill="#e3f2fd" stroke="#2196f3"
            stroke-width="2" />
        <text x="180" y="155" font-family="Arial, sans-serif" font-size="14" text-anchor="middle"
            fill="#333">Initial Prediction</text>
        <text x="180" y="175" font-family="Arial, sans-serif" font-size="12" text-anchor="middle"
            fill="#666">F₀(x) = Constant</text>

        <!-- Step 2: Calculate Residuals -->
        <rect x="320" y="120" width="160" height="80" rx="5" ry="5" fill="#e8f5e9" stroke="#4caf50"
            stroke-width="2" />
        <text x="400" y="145" font-family="Arial, sans-serif" font-size="14" text-anchor="middle"
            fill="#333">Calculate Residuals</text>
        <text x="400" y="165" font-family="Arial, sans-serif" font-size="12" text-anchor="middle"
            fill="#666">r = y - ŷ</text>
        <text x="400" y="185" font-family="Arial, sans-serif" font-size="12" text-anchor="middle"
            fill="#666">Gradient of Loss</text>

        <!-- Step 3: Train Tree -->
        <rect x="540" y="120" width="160" height="80" rx="5" ry="5" fill="#fff3e0" stroke="#ff9800"
            stroke-width="2" />
        <text x="620" y="155" font-family="Arial, sans-serif" font-size="14" text-anchor="middle"
            fill="#333">Train Decision Tree</text>
        <text x="620" y="175" font-family="Arial, sans-serif" font-size="12" text-anchor="middle"
            fill="#666">on Residuals</text>

        <!-- Step 4: Add Prediction -->
        <rect x="320" y="260" width="160" height="80" rx="5" ry="5" fill="#e8eaf6" stroke="#3f51b5"
            stroke-width="2" />
        <text x="400" y="285" font-family="Arial, sans-serif" font-size="14" text-anchor="middle"
            fill="#333">Update Model</text>
        <text x="400" y="305" font-family="Arial, sans-serif" font-size="12" text-anchor="middle"
            fill="#666">Fₜ(x) = Fₜ₋₁(x) + η·hₜ(x)</text>
        <text x="400" y="325" font-family="Arial, sans-serif" font-size="10" text-anchor="middle"
            fill="#666">Learning Rate: η</text>

        <!-- Decision Tree Example -->
        <g transform="translate(150, 380)">
            <rect x="0" y="0" width="500" height="160" rx="5" ry="5" fill="#f5f5f5" stroke="#9e9e9e"
                stroke-width="1" />
            <text x="250" y="25" font-family="Arial, sans-serif" font-size="14" font-weight="bold"
                text-anchor="middle" fill="#333">Decision Tree Structure</text>

            <!-- Root node -->
            <circle cx="250" cy="55" r="20" fill="#bbdefb" stroke="#1976d2" stroke-width="1.5" />
            <text x="250" y="59" font-family="Arial, sans-serif" font-size="10" text-anchor="middle"
                fill="#333">x₁ > 5?</text>

            <!-- Branches -->
            <line x1="235" y1="70" x2="175" y2="95" stroke="#666" stroke-width="1.5" />
            <text x="200" y="85" font-family="Arial, sans-serif" font-size="10" text-anchor="middle"
                fill="#333">False</text>

            <line x1="265" y1="70" x2="325" y2="95" stroke="#666" stroke-width="1.5" />
            <text x="300" y="85" font-family="Arial, sans-serif" font-size="10" text-anchor="middle"
                fill="#333">True</text>

            <!-- Left child node -->
            <circle cx="175" cy="105" r="20" fill="#c8e6c9" stroke="#388e3c" stroke-width="1.5" />
            <text x="175" y="109" font-family="Arial, sans-serif" font-size="10"
                text-anchor="middle" fill="#333">3 > x₂?</text>

            <!-- Right child node -->
            <circle cx="325" cy="105" r="20" fill="#c8e6c9" stroke="#388e3c" stroke-width="1.5" />
            <text x="325" y="109" font-family="Arial, sans-serif" font-size="10"
                text-anchor="middle" fill="#333">x₃ = 1?</text>

            <!-- Left leaf nodes -->
            <line x1="160" y1="120" x2="135" y2="140" stroke="#666" stroke-width="1.5" />
            <rect x="120" y="140" width="30" height="20" rx="3" ry="3" fill="#ffccbc"
                stroke="#e64a19" stroke-width="1" />
            <text x="135" y="155" font-family="Arial, sans-serif" font-size="10"
                text-anchor="middle" fill="#333">-0.2</text>

            <line x1="190" y1="120" x2="215" y2="140" stroke="#666" stroke-width="1.5" />
            <rect x="200" y="140" width="30" height="20" rx="3" ry="3" fill="#ffccbc"
                stroke="#e64a19" stroke-width="1" />
            <text x="215" y="155" font-family="Arial, sans-serif" font-size="10"
                text-anchor="middle" fill="#333">0.5</text>

            <!-- Right leaf nodes -->
            <line x1="310" y1="120" x2="285" y2="140" stroke="#666" stroke-width="1.5" />
            <rect x="270" y="140" width="30" height="20" rx="3" ry="3" fill="#ffccbc"
                stroke="#e64a19" stroke-width="1" />
            <text x="285" y="155" font-family="Arial, sans-serif" font-size="10"
                text-anchor="middle" fill="#333">0.1</text>

            <line x1="340" y1="120" x2="365" y2="140" stroke="#666" stroke-width="1.5" />
            <rect x="350" y="140" width="30" height="20" rx="3" ry="3" fill="#ffccbc"
                stroke="#e64a19" stroke-width="1" />
            <text x="365" y="155" font-family="Arial, sans-serif" font-size="10"
                text-anchor="middle" fill="#333">0.7</text>
        </g>

        <!-- Flow Arrows -->
        <g stroke="#555" stroke-width="2" fill="none">
            <path d="M260,160 L320,160" marker-end="url(#arrowhead)" />
            <path d="M480,160 L540,160" marker-end="url(#arrowhead)" />
            <path d="M620,200 L620,240 L480,260" marker-end="url(#arrowhead)" />
            <path d="M320,300 L280,300 L180,200" marker-end="url(#arrowhead)" />
        </g>

        <!-- Key XGBoost Features -->
        <g transform="translate(600, 270)">
            <rect x="0" y="0" width="180" height="100" rx="5" ry="5" fill="#fce4ec" stroke="#e91e63"
                stroke-width="1" />
            <text x="90" y="20" font-family="Arial, sans-serif" font-size="12" font-weight="bold"
                text-anchor="middle" fill="#333">XGBoost Features</text>
            <text x="10" y="40" font-family="Arial, sans-serif" font-size="10" fill="#333">•
                Regularization</text>
            <text x="10" y="60" font-family="Arial, sans-serif" font-size="10" fill="#333">•
                Parallel Processing</text>
            <text x="10" y="80" font-family="Arial, sans-serif" font-size="10" fill="#333">• Handle
                Missing Values</text>
            <text x="10" y="100" font-family="Arial, sans-serif" font-size="10" fill="#333">• Tree
                Pruning</text>
        </g>
    </g>

    <!-- Arrowhead marker -->
    <defs>
        <marker id="arrowhead" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
            <polygon points="0 0, 10 3.5, 0 7" fill="#555" />
        </marker>
    </defs>
</svg>