ML Audience Targeting: From Segments to Probabilities

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 1564 services
ML Audience Targeting: From Segments to Probabilities
Medium
~2-4 weeks
Frequently Asked Questions

AI Development Areas

AI Solution Development Stages

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1351
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1247
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    950
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1186
  • image_logo-advance_0.webp
    B2B Advance company logo design
    642
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    922

ML Audience Targeting in Advertising

Machine learning for targeting translates from "show to all women aged 25-34" to "show to those with a 73%+ probability of conversion within the next 7 days." The efficiency difference is 3-5x with the same budget. We implement such models for advertising campaigns: in a typical project, CTR grows from 0.08% to 0.4%, and the cost per lead drops by 40%. We rely solely on first-party data — the only sustainable path in a world without third-party cookies. For example, in one e-commerce project, CPA dropped from $12 to $7 — a 42% savings. Request a consultation on implementing an ML targeting model — we'll select the optimal solution for your data.

Problems We Solve

Blind demographic targeting. Age and gender do not guarantee interest. A 35-year-old user might be looking for a gift for a child, not for themselves. An ML model evaluates behavioral signals: frequency of viewing product pages, add-to-cart actions, time between sessions. The result is a conversion prediction accuracy >85%.

Bloated audiences with low conversion. Lookalike models based on 50+ seed users expand the audience while preserving the concentration of "hot" leads. We use a supervised classifier (LightGBM) with calibrated probabilities, not simple kNN — this yields an ROC-AUC improvement of 0.08–0.12.

Loss of context after retargeting. When a user navigates to a technology article and is shown credit cards — a context break. Our contextual engine analyzes the URL and page text, determines the IAB category (e.g., IAB19 — Technology) and selects creatives in the same topic. It works without user data, which is important for GDPR.

How Does the ML Model Assess Propensity?

The key is quality features. We take raw events: product_view, add_to_cart, checkout_start, search. We compute recency (hours since last event), session frequency, funnel depth (weighted average number of actions), activity trend (last 7 days vs previous). These features are fed into a LightGBM classifier with tuned parameters: learning_rate=0.01, max_depth=6, colsample_bytree=0.8. We obtain for each user a purchase_probability and tiers: cold (<10%), warm (10-30%), hot (30-60%), ready_to_buy (>60%).

import pandas as pd
import numpy as np
import lightgbm as lgb
from sklearn.cluster import MiniBatchKMeans
from sklearn.preprocessing import LabelEncoder

class PredictiveAudienceBuilder:
    """Creating audiences based on conversion probabilities"""

    def build_intent_features(self, user_events: pd.DataFrame) -> pd.DataFrame:
        """
        Intent features from user events.
        user_events: user_id, event_type, page_url, timestamp, session_id
        """
        df = user_events.copy()
        df['ts'] = pd.to_datetime(df['timestamp'])

        # Recency of last activity
        now = df['ts'].max()
        recency = df.groupby('user_id')['ts'].max().apply(
            lambda t: (now - t).total_seconds() / 3600
        ).rename('hours_since_last_event')

        # Behavioral features
        behavior = df.groupby('user_id').agg(
            total_sessions=('session_id', 'nunique'),
            total_events=('event_type', 'count'),
            product_views=('event_type', lambda x: (x == 'product_view').sum()),
            cart_adds=('event_type', lambda x: (x == 'add_to_cart').sum()),
            checkout_starts=('event_type', lambda x: (x == 'checkout_start').sum()),
            search_queries=('event_type', lambda x: (x == 'search').sum()),
        )

        # Conversion funnel (normalized)
        behavior['funnel_depth'] = (
            behavior['product_views'] * 1 +
            behavior['cart_adds'] * 3 +
            behavior['checkout_starts'] * 7
        ) / behavior['total_sessions'].clip(1)

        # Session activity: trend of last 7 days vs previous 7
        last_7d = df[df['ts'] >= now - pd.Timedelta(days=7)]
        prev_7d = df[df['ts'].between(now - pd.Timedelta(days=14), now - pd.Timedelta(days=7))]

        activity_last = last_7d.groupby('user_id')['event_type'].count().rename('events_last_7d')
        activity_prev = prev_7d.groupby('user_id')['event_type'].count().rename('events_prev_7d')

        result = behavior.join(recency).join(activity_last).join(activity_prev).fillna(0)
        result['activity_trend'] = (
            result['events_last_7d'] - result['events_prev_7d']
        ) / (result['events_prev_7d'] + 1)

        return result

    def score_purchase_propensity(self, features: pd.DataFrame,
                                    model: lgb.LGBMClassifier) -> pd.DataFrame:
        """Estimate purchase probability for each user"""
        scores = model.predict_proba(features)[:, 1]

        result = pd.DataFrame({
            'user_id': features.index,
            'purchase_probability': scores,
            'audience_tier': pd.cut(
                scores,
                bins=[0, 0.1, 0.3, 0.6, 1.0],
                labels=['cold', 'warm', 'hot', 'ready_to_buy']
            )
        })

        return result.sort_values('purchase_probability', ascending=False)


class BehavioralClusteringAudience:
    """Behavioral segmentation without supervision"""

    def segment_by_behavior(self, user_features: pd.DataFrame,
                              n_clusters: int = 8) -> pd.DataFrame:
        """
        K-Means clustering to identify hidden audience segments.
        """
        from sklearn.preprocessing import StandardScaler

        feature_cols = user_features.select_dtypes(include=[np.number]).columns
        X = user_features[feature_cols].fillna(0)

        scaler = StandardScaler()
        X_scaled = scaler.fit_transform(X)

        kmeans = MiniBatchKMeans(n_clusters=n_clusters, random_state=42, n_init=10)
        clusters = kmeans.fit_predict(X_scaled)

        user_features = user_features.copy()
        user_features['cluster'] = clusters

        # Cluster profiles
        profiles = user_features.groupby('cluster')[feature_cols].mean()

        return user_features, profiles

    def label_clusters(self, cluster_profiles: pd.DataFrame) -> dict:
        """Automatic cluster labeling based on profiles"""
        labels = {}
        for cluster_id, row in cluster_profiles.iterrows():
            # Simplified heuristic labeling
            if row.get('checkout_starts', 0) > 2:
                label = 'high_intent_buyers'
            elif row.get('product_views', 0) > 10 and row.get('cart_adds', 0) == 0:
                label = 'browsers_not_buyers'
            elif row.get('total_sessions', 0) > 20:
                label = 'loyal_visitors'
            elif row.get('hours_since_last_event', 9999) > 720:
                label = 'dormant_users'
            else:
                label = f'segment_{cluster_id}'
            labels[cluster_id] = label
        return labels

How to Set Up Contextual Targeting Without Cookies?

class ContextualTargetingEngine:
    """ML targeting based on page content (cookieless)"""

    def classify_page_context(self, page_text: str,
                               page_url: str) -> dict:
        """
        IAB categorization of a page for contextual targeting.
        Works without user-level data (GDPR-compliant).
        """
        # Key context signals
        url_signals = self._extract_url_signals(page_url)

        # In production: BERT-based classifier trained on IAB taxonomy
        # Here simplified keyword-based version
        iab_keywords = {
            'IAB19': ['technology', 'software', 'programming', 'tech'],
            'IAB13': ['finance', 'investment', 'stock', 'crypto', 'money'],
            'IAB7': ['health', 'fitness', 'medical', 'diet'],
            'IAB9': ['hobby', 'crafts', 'games', 'gaming'],
        }

        text_lower = page_text.lower()
        scores = {}
        for iab_cat, keywords in iab_keywords.items():
            score = sum(text_lower.count(kw) for kw in keywords)
            if score > 0:
                scores[iab_cat] = score

        if not scores:
            return {'categories': ['IAB24'], 'confidence': 0.5}

        primary_cat = max(scores, key=scores.get)
        total = sum(scores.values())

        return {
            'primary_category': primary_cat,
            'all_categories': list(scores.keys()),
            'confidence': round(scores[primary_cat] / total, 2),
            'url_signals': url_signals,
        }

    def _extract_url_signals(self, url: str) -> list:
        signals = []
        if '/news/' in url or '/article/' in url:
            signals.append('editorial_content')
        if '/product/' in url or '/shop/' in url:
            signals.append('ecommerce')
        if '/blog/' in url:
            signals.append('blog_content')
        return signals

Why Predictive Targeting Outperforms Demographic Targeting?

Demographic targeting (age/gender) is a relic. CPM is low, but conversion fluctuates at 0.05-0.1%. Behavioral targeting based on third-party cookies yields CTR of 0.2-0.5%, but will soon disappear. ML models based on first-party data provide CTR of 0.3-0.8% and minimal budget waste on "cold" audiences. In the long term, only the first one is independent of regulatory risks. Predictive targeting is 2-4 times more effective than lookalike models based on kNN, as it uses gradient boosting instead of simple clustering.

Comparison of Targeting Methods

Method CPM CTR Conversion Privacy
Demographic (age/gender) low 0.05-0.1% low safe
Behavioral (3rd party cookies) high 0.2-0.5% medium limited
Predictive (ML propensity) medium 0.3-0.8% high 1st party
Lookalike ML medium 0.2-0.6% medium 1st party
Contextual (cookieless) medium 0.1-0.3% medium safe

Using predictive targeting saves up to 40% of the advertising budget and reduces CPA by 30-50%. As experts note, gradient boosting is the industry standard for binary classification tasks with tabular data.

More about model metrics To evaluate the quality of the propensity model, we use AUPRC (Area Under Precision-Recall Curve) — it is sensitive to class imbalance. The target value is ≥0.75. Additionally, we control the calibration of probabilities using a calibration curve. If the model overestimates the probability for a cold audience, we adjust the threshold.

How to Implement Predictive Targeting: Step-by-Step Plan

  1. Data audit: check the quality of event tracking (Google Tag Manager, Amplitude, custom pipelines).
  2. Feature engineering: Python/Pandas for generating features (activity, funnel, trends).
  3. Model training: LightGBM classifier with probability calibration, time-based cross-validation.
  4. Clustering: MiniBatchKMeans for identifying segments (lazy, hot, abandoners).
  5. Contextual engine: NLP module based on BERT for page classification according to IAB taxonomy (up to 30 categories).
  6. Integration with DSP: API for sending segments to Facebook Ads, Google Ads, Yandex.Direct or a self-serve platform.
  7. A/B testing: launch against baseline targeting for 2 weeks — we guarantee a ROAS increase of 25%+ or free adjustment.

What's Included in the Work

Our experience: over 50 successful projects for e-commerce and fintech.

  • Data audit: assessment of the quality and completeness of event data, tracking setup.
  • Feature development: Python/Pandas scripts for feature generation.
  • Propensity model: LightGBM classifier with probability calibration, AUPRC ≥0.75.
  • Clustering: MiniBatchKMeans for identifying segments.
  • Contextual engine: NLP module based on BERT for page classification according to IAB taxonomy.
  • Integration with DSP: API for sending segments to advertising platforms.
  • Test drive: A/B testing of the model against baseline targeting for 2 weeks — we guarantee a ROAS increase of 25%+ or free adjustment.

Work Process

Stage Duration
Analytics: collection and ETL of tracker 2-3 days
Feature engineering: data mart formation 3-5 days
ML development: model training and validation 5-7 days
Testing: A/B experiment in a real campaign 7-14 days
Deployment: model rollout to production 2-3 days

Timeline and Cost

Estimated timeframes — from 4 to 6 weeks to a working MVP. Cost is calculated individually depending on the volume of data, number of target events, and integrations. Get a consultation — we'll lock in success metrics at the start.

Additional resources: LightGBM, IAB taxonomy.

Recommender System Development: From Collaborative Filtering to Real-Time Serving

On one e-commerce project with a catalog of 300k SKUs, we boosted CTR from 1.8% to 4.4% — a 2.4x increase. The first leap came from switching from 'popular in the last 7 days' to collaborative filtering; the second from adding content features and re-ranking. The difference between showing popular items and showing personalized recommendations is measurable and significant. Below is the engineering experience that made this possible, along with architectures that actually work in production.

Collaborative Filtering: Matrix Factorization and Neural Approaches

Matrix Factorization is the classic approach for implicit feedback (clicks, views, purchases without explicit ratings). ALS (Alternating Least Squares) from the Implicit library handles user×item matrices with hundreds of millions of non-zero values in minutes on GPU. Latent factors 64–256, regularization λ=0.01–0.1 are starting parameters. Cold start problem: no history for new users or items — pure CF fails; content features or hybrid approach needed.

Neural Collaborative Filtering (NCF) replaces the dot product with a neural network. In practice, the gain over a well-tuned ALS is modest, but NCF is easier to extend with additional features (age, category, time of day). Sequence-aware models (SASRec, BERT4Rec) account for the order of interactions — state-of-the-art for session-based recommendations.

How to Choose Recommender System Architecture?

The answer depends on data, load, and cold start requirements. Below are three main approaches with selection criteria.

Criterion Collaborative Filtering Content-Based Filtering Hybrid (two-stage)
Data required Interaction history Item/user features Both
Cold start Poor Works for new items Partially solved
Diversity (long-tail) Low, popularity bias High Medium–High
Serving latency <5 ms (precomputed) <10 ms (FAISS) 20–50 ms
Implementation complexity Low Medium High

Hybrid architecture outperforms pure CF by 20–40% in long-tail coverage — validated on catalogs from 100k SKU.

Content-Based Filtering: When Interaction History is Scarce

Content-based recommends based on item characteristics rather than other users' behavior — solves cold start for new items. Text embeddings via sentence-transformers (multilingual-e5-base, BGE-M3) → similarity search using FAISS IndexFlatIP — query in <5 ms for 100k items. Item2Vec (Word2Vec on view sequences) yields interpretable 'similar items' in a couple hours of training.

Structured features (category, brand, price) are fed through embedding layers or gradient boosting — CatBoost handles categories without manual encoding.

Why Hybrid Models Work Better?

Production systems are almost always two-level. Stage 1 (Retrieval) — fast selection of 100–500 candidates from 300k items using ALS or Two-Tower model with vector search (FAISS, Qdrant). Stage 2 (Ranking) — heavy ranker on LightGBM or neural network with cross-features, time, device, and session context. LightFM is a good starting point for medium scale without heavy infrastructure. Our practice shows: moving from single-stage to two-stage yields a 15–25% accuracy improvement with only 20–30 ms additional latency.

Real-Time Serving: Architecture Under Load

Latency SLA — 50–100 ms at thousands of requests per second. Base recommendations precomputed (batch job hourly) → Redis by user_id → <5 ms. Real-time re-ranking via Kafka for events (clicks, cart adds) → update of context features. Feature serving — Redis with TTL (views in 24 hours, last clicked item). At 10k req/s, we deploy Redis Cluster with replication.

A/B testing is the only reliable way to measure improvements. Offline metrics do not always correlate with online. Kohavi et al., 'Online Controlled Experiments at Large Scale' (KDD 2013) — a must-read for the team. Test on 5–10% of traffic, monitor CTR, conversion, revenue per session. One of our client systems after hybridization increased revenue by 18% over a month of A/B.

Recommender System Development Timeline

The stages and typical time frames are in the table below. Costs are calculated individually based on catalog scale and latency requirements.

Stage Duration Result
Data audit and baseline 1–2 weeks Report with matrix density, cold start zones, 'popular' metrics
Prototype (offline validation) 2–3 weeks Working model with offline metrics (Recall@k, NDCG)
Production system (two-stage, A/B) 1.5–2.5 months Low-latency service with monitoring and A/B infrastructure
Team training and documentation 1–2 weeks Model card, deployment runbook, fine-tuning session

What's Included in Turnkey Development

  1. Data audit — user×item matrix density (typically <0.1%), activity distribution, temporal patterns, cold start statistics.
  2. Baseline — 'popular' as a simple threshold that is often hard to beat.
  3. Iterative improvement — ALS → content features → two-stage → sequence-aware. Each step with A/B.
  4. Serving infrastructure — batch precomputation, Redis, real-time re-ranking, Grafana monitoring.
  5. Documentation — model card with metrics, deployment instructions, feature descriptions.
  6. Team training — session on interpreting results and model fine-tuning.
  7. Support — 1 month post-launch (incident fixes, pipeline tuning).

We are a team with 7+ years of experience in recommender systems, having delivered over 30 projects for e-commerce and media. We guarantee transparent A/B testing and documented metric improvements.

Want to assess the growth potential of your catalog? Contact us for a free data audit. Order recommender system development — first prototype within two weeks.

Example ALS config for implicit feedback
from implicit.als import AlternatingLeastSquares

model = AlternatingLeastSquares(
    factors=64,
    regularization=0.05,
    iterations=15,
    use_gpu=True
)
model.fit(user_item_matrix)

More about the mathematics of recommender systems — in specialized literature.