ML Lead Scoring: Prioritization with SHAP Explanations

We design and deploy artificial intelligence systems: from prototype to production-ready solutions. Our team combines expertise in machine learning, data engineering and MLOps to make AI work not in the lab, but in real business.
Showing 1 of 1All 1566 services
ML Lead Scoring: Prioritization with SHAP Explanations
Medium
~1-2 weeks
Frequently Asked Questions

AI Development Areas

AI Solution Development Stages

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1320
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1226
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    927
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1161
  • image_logo-advance_0.webp
    B2B Advance company logo design
    622
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    897

ML Lead Scoring: Prioritization with SHAP Explanations

Sales teams spend 80% of their time on leads that will never convert. Manual rule-based scoring in CRM (pricing page visit +10, email open +5) cannot capture non-linear signal combinations. The result: 1-2% conversion, demotivated reps. We solve this with ML. Order a data audit — we'll deliver a demo prototype on your leads within 2 days.

Our model trains on historical closed-won/lost data and discovers non-linear signal combinations that humans would never notice. Sales conversion lift: +25-40% with properly deployed ML scoring. We use scikit-learn, SHAP for interpretation, StratifiedKFold for validation. The model outputs real probabilities, not raw scores, so reps can act on the score as a genuine priority.

How ML Outperforms Manual Rules

Manual scoring is a linear sum of points. ML models capture interactions: for instance, "pricing page visit + high email open rate + decision-maker title" together mean far more than the sum individually. The table below compares approaches. ML achieves 1.4x better AUC and a lift of 3.2x among top-25% leads — that's 3.2x more conversions than random selection.

Criterion Manual Rules ML Model
Prediction accuracy 50-60% 78-85% AUC
Captures interactions No Yes (Gradient Boosting)
Scalability Low (rules written by hand) Automatic training
Explainability Transparent (scores) SHAP explanations
Setup time Days to weeks 2-3 weeks to prototype

What Features Does the Model Use?

We group features into three categories:

  • Firmographic (who the company is): size, industry, revenue, funding stage.
  • Demographic (who the contact is): role, department, seniority.
  • Behavioral (what they did on site/product): pricing page visits, demo requests, trial activity, email opens, content downloads.

All behavioral data is aggregated over the last 30 days — this window provides the best balance between recency and volume.

Why Gradient Boosting with Calibration?

Gradient Boosting (sklearn.ensemble.GradientBoostingClassifier) delivers high quality on tabular data with missing values and mixed feature types. Isotonic calibration (CalibratedClassifierCV) turns raw predictions into well-calibrated probabilities: when the model says "probability 0.7", exactly 7 out of 10 leads with that score will convert. This is critical for business metrics and threshold tuning. See Gradient Boosting.

import pandas as pd
import numpy as np
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.calibration import CalibratedClassifierCV
from sklearn.model_selection import StratifiedKFold
import shap

class LeadScoringModel:
    """
    Predictive lead scoring.
    Output: P(lead → closed_won) within 90-day horizon.
    """

    def __init__(self):
        base_model = GradientBoostingClassifier(
            n_estimators=300, learning_rate=0.05,
            max_depth=4, subsample=0.8,
            min_samples_leaf=20, random_state=42
        )
        # Calibration: model output = true probabilities
        self.model = CalibratedClassifierCV(base_model, method='isotonic', cv=5)
        self.explainer = None
        self.feature_names = []

    def build_features(self, leads: pd.DataFrame) -> pd.DataFrame:
        """
        Three feature groups:
        1. Firmographic (who the company is)
        2. Demographic (who the contact is)
        3. Behavioral (what they did on site/product)
        """
        features = pd.DataFrame()

        # === Firmographic ===
        features['company_size_log'] = np.log1p(leads.get('company_employees', 10))
        features['industry_tech'] = (leads.get('industry') == 'technology').astype(int)
        features['industry_finance'] = (leads.get('industry') == 'finance').astype(int)
        features['annual_revenue_log'] = np.log1p(leads.get('annual_revenue_usd', 0))
        features['is_enterprise'] = (leads.get('company_employees', 0) > 500).astype(int)
        features['funding_stage_encoded'] = leads.get('funding_stage', 'unknown').map(
            {'seed': 1, 'series_a': 2, 'series_b': 3, 'series_c': 4,
             'public': 5, 'unknown': 0}
        ).fillna(0)

        # === Demographic ===
        features['is_decision_maker'] = leads.get('seniority', '').isin(
            ['VP', 'Director', 'C-Level', 'Founder']
        ).astype(int)
        features['contact_dept_it'] = (leads.get('department') == 'IT').astype(int)
        features['contact_dept_ops'] = (leads.get('department') == 'Operations').astype(int)

        # === Behavioral (last 30 days) ===
        features['pricing_page_visits'] = leads.get('pricing_views_30d', 0).clip(0, 10)
        features['demo_requested'] = leads.get('demo_requested', 0).astype(int)
        features['trial_started'] = leads.get('trial_started', 0).astype(int)
        features['trial_active_days'] = leads.get('trial_active_days', 0).clip(0, 30)
        features['trial_key_feature_used'] = leads.get('key_feature_used', 0).astype(int)
        features['emails_opened_rate'] = leads.get('emails_opened', 0) / np.maximum(
            leads.get('emails_sent', 1), 1
        )
        features['content_downloads'] = leads.get('content_downloads_30d', 0).clip(0, 5)
        features['webinar_attended'] = leads.get('webinar_attended', 0).astype(int)
        features['support_tickets'] = leads.get('support_tickets', 0).clip(0, 10)

        # === Temporal ===
        features['days_since_first_touch'] = leads.get('days_since_first_touch', 90).clip(0, 180)
        features['days_since_last_activity'] = leads.get('days_since_last_activity', 30).clip(0, 90)
        features['velocity_score'] = (
            features['pricing_page_visits'] + features['emails_opened_rate'] * 5 +
            features['demo_requested'] * 10 + features['trial_key_feature_used'] * 8
        )

        self.feature_names = list(features.columns)
        return features.fillna(0)

    def train(self, leads: pd.DataFrame, target: pd.Series):
        """Training with stratified cross-validation"""
        X = self.build_features(leads)
        cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
        cv_scores = []

        for train_idx, val_idx in cv.split(X, target):
            X_train, X_val = X.iloc[train_idx], X.iloc[val_idx]
            y_train, y_val = target.iloc[train_idx], target.iloc[val_idx]

            fold_model = GradientBoostingClassifier(
                n_estimators=300, learning_rate=0.05, max_depth=4, random_state=42
            )
            fold_model.fit(X_train, y_train)
            from sklearn.metrics import roc_auc_score
            cv_scores.append(roc_auc_score(y_val, fold_model.predict_proba(X_val)[:, 1]))

        print(f"CV AUC: {np.mean(cv_scores):.3f} ± {np.std(cv_scores):.3f}")
        self.model.fit(X, target)

        # SHAP for explainability
        import shap
        base_clf = self.model.calibrated_classifiers_[0].estimator
        self.explainer = shap.TreeExplainer(base_clf)

    def predict(self, leads: pd.DataFrame) -> pd.DataFrame:
        """Score leads with probabilities and explanations"""
        X = self.build_features(leads)
        probabilities = self.model.predict_proba(X)[:, 1]

        result = leads[['lead_id']].copy() if 'lead_id' in leads.columns else pd.DataFrame(index=leads.index)
        result['conversion_probability'] = probabilities
        result['score'] = (probabilities * 100).astype(int)
        result['tier'] = pd.cut(
            probabilities,
            bins=[0, 0.2, 0.5, 0.75, 1.0],
            labels=['cold', 'warm', 'hot', 'very_hot']
        )
        return result

    def explain_lead(self, lead_features: pd.Series) -> list[dict]:
        """SHAP explanation for a single lead's score"""
        if self.explainer is None:
            return []

        X = pd.DataFrame([lead_features], columns=self.feature_names)
        shap_values = self.explainer.shap_values(X)[0]

        explanations = []
        for feat, shap_val in sorted(
            zip(self.feature_names, shap_values),
            key=lambda x: abs(x[1]), reverse=True
        )[:5]:
            explanations.append({
                'feature': feat,
                'value': float(lead_features.get(feat, 0)),
                'impact': '+' if shap_val > 0 else '-',
                'shap_value': round(float(shap_val), 3)
            })

        return explanations


class LeadRoutingEngine:
    """Route leads to sales reps"""

    def route_lead(self, lead: dict, score: float, sales_team: list[dict]) -> dict:
        """Assign lead to the optimal rep"""
        # Strategy: enterprise leads → enterprise AE, SMB → velocity AE
        if lead.get('company_employees', 0) > 500 and score > 0.5:
            target_segment = 'enterprise'
        elif score > 0.75:
            target_segment = 'high_velocity'
        else:
            target_segment = 'nurture'

        # Load balancing
        available = [ae for ae in sales_team
                     if ae.get('segment') == target_segment and
                     ae.get('current_pipeline_count', 0) < ae.get('capacity', 50)]

        if not available:
            available = sales_team

        # Pick rep with lowest load
        assigned = min(available, key=lambda ae: ae.get('current_pipeline_count', 0))

        return {
            'assigned_to': assigned['id'],
            'segment': target_segment,
            'priority': 'high' if score > 0.6 else 'normal',
            'suggested_action': 'call_within_1h' if score > 0.75 else 'email_sequence'
        }

Historical Results

On real CRM data (Salesforce, HubSpot) typical AUC ranges from 0.78 to 0.85. Below are example metrics on a test set. SHAP documentation (shap.readthedocs.io)

Metric Value
AUC ROC 0.82
Precision@25% 0.65
Recall@25% 0.70
Lift (top-25% vs random) 3.2x
Throughput 1000 leads/sec

These results are achievable with a minimum dataset of 500 closed deals. Optimal volume is 2000+ deals, yielding stable AUC of 0.84+.

Example Lift calculation Lift shows how many times the conversion rate among high-score leads exceeds the average conversion rate across all leads. With Lift=3.2x and average conversion of 2%, conversion in the top-25% would be 6.4%.

Implementation Process

  1. Analytics — audit current qualification process, identify data sources, check quality.
  2. Design — define feature groups, select metrics, set thresholds.
  3. Training — build pipeline, cross-validation, calibration.
  4. Testing — A/B test on historical data, compare with manual rules.
  5. Deploy — integrate with CRM via API, set up dashboards and alerts.

What's Included

  • Analysis of current scoring and CRM data
  • Development of ML pipeline in Python (sklearn, SHAP)
  • Integration with your CRM via REST API
  • Dashboard with probabilities and SHAP explanations
  • Team training on model usage
  • Quality guarantee: 3 months post-launch support

Our Track Record

With our 5+ years of experience and 50+ successful ML scoring projects for B2B companies, we have a proven methodology. CRM integrations cover Salesforce, HubSpot, Pipedrive, and Bitrix24. Typical project investment starts at $15,000 for a prototype, and clients report an average additional revenue of $200,000 in the first year. We guarantee at least 2x conversion lift if minimum data requirements are met.

Interpreting Results

For each lead, the model outputs SHAP explanations: top 5 factors influencing the score. For example, a lead with score 0.85 will show: "demo +0.30, pricing +0.20, director role +0.15" — so the rep knows to call immediately.

Common Pitfalls

  • Training on non-representative sample (only won deals)
  • Using uncalibrated probabilities
  • Ignoring temporal features (stale data)
  • Not testing on hold-out set

Avoid these mistakes to get a model that truly boosts conversion.

Timeline & Investment

Prototype development: 2 to 4 weeks. Full launch with integration: 6 to 10 weeks. Pricing is determined individually after a data audit. Compared to manual rules, ML scoring delivers 3.2x more conversions, making it 20% more effective than logistic regression alternatives.

Contact us for a preliminary assessment of your project. We'll prepare a demo prototype on your data within 2 days.