marketing-attribution-models

raw JSON →
1.0.11 verified Fri May 01 auth: no python

A library for marketing attribution modeling, providing implementations of popular attribution methods such as first-click, last-click, linear, time-decay, position-based, and Markov chain models. Current version 1.0.11, with an active maintenance cadence on GitHub. Requires Python >=3.5.

pip install marketing-attribution-models
error ValueError: method must be one of ['first-click', 'last-click', 'linear', 'time-decay', 'position-based']
cause Using an outdated method name like 'first_click' or 'position_based'
fix
Use the hyphenated form: 'first-click', 'last-click', 'linear', 'time-decay', 'position-based'
error TypeError: attribution() missing 1 required positional argument: 'journeys'
cause Calling attribution() without passing a DataFrame or path
fix
Ensure you pass a DataFrame to the attribution method, e.g., model.attribution(journeys)
error AttributeError: module 'marketing_attribution_models' has no attribute 'AttributionModel'
cause Attempting to import from 'mam' or wrong casing
fix
Use 'from marketing_attribution_models import AttributionModel' (note the underscore after 'marketing')
error KeyError: 'path'
cause Column name in DataFrame is not exactly 'path'
fix
Rename the column to 'path' using df.rename(columns={'old_name': 'path'}, inplace=True)
breaking In v1.0.9, the method 'first_click' was renamed to 'first-click' to conform with other method names. Code using 'first_click' will break.
fix Use 'first-click' instead of 'first_click' as the method argument.
deprecated The 'attribution' method on HeuristicAttribution and MarkovChainAttribution now requires a DataFrame instead of a CSV file path. Passing a file path is deprecated.
fix Read the CSV into a DataFrame with pd.read_csv before calling attribution.
gotcha The 'path' column must use ' > ' (space-greater than-space) as separator. Other delimiters like '>>' or '->' will cause incorrect parsing.
fix Ensure the path column uses ' > ' as the separator between touchpoints.

Create a HeuristicAttribution model with the 'linear' method and fit it to sample journey data.

import pandas as pd
from marketing_attribution_models import HeuristicAttribution

# Sample journey data
journeys = pd.DataFrame({
    'path': ['A > B > C', 'A > C > B'],
    'conversion': [1, 0],
    'revenue': [100, 0]
})

model = HeuristicAttribution(method='linear')
result = model.attribution(journeys)
print(result)