All guides
IntermediateSelf-pacedFree GuideSection 12/27

Lead scoring ML et pipeline forecasting

Explore AI for marketing and sales operations: CRM, prospect follow-up, workflows and measurement. Practise checks using educational examples.

The full lessons for this course are currently available in French. Use the section menu to navigate the French course.

💡

Free content, available without an account. Tools and models change: use the current model guide to check their versions. Models and sources

Section 14.4.1 : Lead scoring ML et pipeline forecasting

🎯 Objectif pédagogique

Implémenter un système de lead scoring ML en production et un modèle de forecasting de pipeline commercial pour prédire les revenus futurs avec précision.


Lead scoring ML en production

Le scoring ML va au-delà du prototype — il faut le maintenir et le monitorer en production :

# Pipeline ML complet pour lead scoring en production

# 1. Feature engineering
def create_features(lead_data, enrichment_data, activity_data):
    features = {
        # Firmographiques (enrichissement)
        'company_size': enrichment_data.get('employees', 0),
        'industry_match': 1 if enrichment_data.get('industry') in TARGET_INDUSTRIES else 0,
        'funding_total': enrichment_data.get('funding_total', 0),
        'tech_stack_overlap': calculate_tech_overlap(enrichment_data.get('tech', [])),

        # Démographiques
        'seniority_score': seniority_to_score(lead_data.get('title', '')),
        'department_match': 1 if is_target_department(lead_data.get('title', '')) else 0,

        # Comportementaux (activité)
        'pages_visited_7d': activity_data.get('pages_7d', 0),
        'time_on_site_7d': activity_data.get('time_7d', 0),
        'pricing_page_visits': activity_data.get('pricing_visits', 0),
        'content_downloads': activity_data.get('downloads', 0),
        'email_opens_30d': activity_data.get('email_opens_30d', 0),
        'email_clicks_30d': activity_data.get('email_clicks_30d', 0),

        # Temporels
        'days_since_first_touch': activity_data.get('days_since_first', 0),
        'days_since_last_activity': activity_data.get('days_inactive', 0),
        'activity_acceleration': activity_data.get('acceleration', 0)
    }
    return features

# 2. Scoring en temps réel
def score_lead(lead_id):
    lead = CRM.get_lead(lead_id)
    enrichment = EnrichmentService.get(lead['email'])
    activity = ActivityTracker.get(lead_id)

    features = create_features(lead, enrichment, activity)
    score = model.predict_proba([list(features.values())])[0][1]

    # Mettre à jour le CRM
    CRM.update_lead(lead_id, {
        'ml_score': round(score * 100),
        'ml_score_updated_at': datetime.now(),
        'ml_tier': 'hot' if score > 0.7 else 'warm' if score > 0.3 else 'cold'
    })

    return score

Pipeline forecasting

La prédiction du pipeline permet d'anticiper le revenu futur et de prendre des décisions business informées :

# Forecasting de pipeline avec ML

import pandas as pd
from sklearn.ensemble import RandomForestRegressor

def forecast_pipeline():
    # Données : chaque deal avec ses caractéristiques
    deals = pd.DataFrame([{
        'deal_size': deal.amount,
        'days_in_stage': deal.days_in_current_stage,
        'total_activities': deal.total_activities,
        'champion_engaged': deal.champion_score,
        'competitor_mentioned': deal.competitor_flag,
        'stage_numeric': stage_to_number(deal.stage),
        'historical_win_rate_segment': segment_win_rate(deal),
        'closed_won': deal.is_won  # Target
    } for deal in Deal.objects.filter(closed=True)])

    # Entraîner le modèle
    X = deals.drop('closed_won', axis=1)
    y = deals['closed_won']
    model = RandomForestRegressor(n_estimators=100)
    model.fit(X, y)

    # Prédire sur le pipeline actuel
    open_deals = Deal.objects.filter(closed=False)
    for deal in open_deals:
        features = extract_features(deal)
        win_probability = model.predict([features])[0]
        weighted_amount = deal.amount * win_probability

        deal.ai_win_probability = win_probability
        deal.ai_weighted_amount = weighted_amount
        deal.save()

    # Forecast total
    total_pipeline = sum(d.amount for d in open_deals)
    weighted_pipeline = sum(d.ai_weighted_amount for d in open_deals)

    return {
        'total_pipeline': total_pipeline,
        'weighted_forecast': weighted_pipeline,
        'confidence_interval': calculate_confidence(open_deals)
    }

Dashboard de forecasting

Quick Check

Pourquoi le pipeline weighted (pondéré par probabilité ML) est-il plus fiable que le pipeline brut ?

Learn AI, from prompts to agents

15 free guidesQuizzes, diagrams and workshopsNo account needed

Your progress

Progress is self-reported and stored in your browser. The final completion record is not a qualification or an independent assessment.

View progress and completion record

Learn AI, from prompts to agents

15 free guidesQuizzes, diagrams and workshopsNo account needed

One practical AI workflow in your inbox

Methods, resources and new exercises. Free, unsubscribe at any time.