All guides
IntermediateSelf-pacedFree GuideSection 25/27

Implémentation avec IA intégrée

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.8.2 : Implémentation avec IA intégrée

🎯 Objectif pédagogique

Implémenter concrètement les composants IA du RevOps stack : lead scoring, churn prediction, et agents IA connectés aux données.


Sprint 2 : Les modèles ML

Lead scoring en production

# lead_scoring.py — Modèle de scoring complet

import pandas as pd
import numpy as np
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
import joblib

class LeadScoringModel:
    def __init__(self):
        self.pipeline = Pipeline([
            ('scaler', StandardScaler()),
            ('model', GradientBoostingClassifier(
                n_estimators=200,
                max_depth=4,
                learning_rate=0.1,
                min_samples_leaf=20
            ))
        ])

    def prepare_features(self, raw_data):
        """Feature engineering à partir des données CRM"""
        return pd.DataFrame({
            # Firmographiques
            'company_size_log': np.log1p(raw_data['employee_count']),
            'is_target_industry': raw_data['industry'].isin(
                ['SaaS', 'Technology', 'E-commerce', 'FinTech']
            ).astype(int),

            # Comportementaux
            'pages_viewed_7d': raw_data['page_views_7d'],
            'pricing_page_visits': raw_data['pricing_visits'],
            'content_downloads': raw_data['downloads_count'],
            'email_engagement': (
                raw_data['email_opens'] / raw_data['emails_sent'].clip(lower=1)
            ),

            # Temporels
            'days_since_first_touch': raw_data['days_since_first'],
            'recency_score': 1 / (1 + raw_data['days_since_last']),
            'velocity': raw_data['actions_7d'] / raw_data['actions_30d'].clip(lower=1)
        })

    def train(self, training_data, labels):
        features = self.prepare_features(training_data)
        scores = cross_val_score(self.pipeline, features, labels, cv=5, scoring='roc_auc')
        print(f"AUC moyenne : {scores.mean():.3f} (+/- {scores.std():.3f})")
        self.pipeline.fit(features, labels)
        return scores

    def predict(self, lead_data):
        features = self.prepare_features(lead_data)
        probability = self.pipeline.predict_proba(features)[:, 1]
        return (probability * 100).round().astype(int)

    def save(self, path='models/lead_scoring.joblib'):
        joblib.dump(self.pipeline, path)

    def load(self, path='models/lead_scoring.joblib'):
        self.pipeline = joblib.load(path)

Agent IA RevOps

# revops_agent.py — Agent IA connecté aux données

from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain.tools import tool
from langchain.chat_models import ChatOpenAI

# Outils disponibles pour l agent
@tool
def query_pipeline(query: str) -> str:
    """Interroge le pipeline commercial. Exemples : pipeline total, deals par stage, forecast."""
    result = bigquery.query(f"""
        SELECT stage, COUNT(*) as deals, SUM(amount) as total
        FROM deals WHERE status = 'open'
        GROUP BY stage ORDER BY stage
    """)
    return result.to_string()

@tool
def get_lead_score(email: str) -> str:
    """Obtient le score ML d un lead par email."""
    lead = hubspot.get_contact(email)
    score = scoring_model.predict(lead)
    return f"Lead: {email}, Score: {score}/100, Tier: {'Hot' if score > 70 else 'Warm' if score > 30 else 'Cold'}"

@tool
def search_playbooks(query: str) -> str:
    """Cherche dans les playbooks de vente."""
    results = rag_chain.invoke(query)
    return results['result']

@tool
def get_account_health(company: str) -> str:
    """Obtient le health score d un compte client."""
    health = cs_platform.get_health(company)
    return f"Company: {company}, Health: {health['score']}/100, Risk: {health['risk_level']}"

# Créer l agent
llm = ChatOpenAI(model="gpt-4", temperature=0)
tools = [query_pipeline, get_lead_score, search_playbooks, get_account_health]

agent = create_openai_functions_agent(llm, tools, prompt="""
Tu es un assistant RevOps expert pour DataFlow SaaS.
Tu as accès au CRM, au pipeline, aux scores ML, et aux playbooks.
Réponds de manière concise et actionnable.
Cite toujours les données exactes.
""")

executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

Tests des modèles

## Validation des modèles ML

### Lead Scoring
- AUC cible : > 0.80
- Precision@top10% : > 60% des leads hot convertissent
- Test : scorer 100 leads passés, vérifier vs réalité

### Churn Prediction
- AUC cible : > 0.75
- Recall cible : > 70% des churns détectés
- Test : prédire le churn de Q-1, comparer au churn réel

### Forecast
- MAPE (Mean Absolute Percentage Error) cible : < 15%
- Test : forecast de Q-1 vs revenu réel de Q-1
Quick Check

Pourquoi utiliser cross-validation (CV=5) plutôt qu'un simple train/test split pour évaluer le lead scoring ?

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.