← Back to case study

PROJECT 017 · PYTHON SOURCE

Contact channel response

Study-specific code. Shared modules, dependency versions, and reproduction instructions are included in all project files.

Download Python file ↓
from pathlib import Path
import sys
ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT))
import numpy as np
import pandas as pd
from scipy.stats import spearmanr
from sklearn.decomposition import PCA
from sklearn.ensemble import IsolationForest
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import confusion_matrix, precision_score, recall_score
from portfolio.data import load
from portfolio.constants import *
from portfolio.methods import result, sql, rates, associations, distribution, regression, classification, cluster
from portfolio.engine import execute

META = {'id': 17, 'dataset': 'bank', 'title': 'Contact channel response', 'question': 'How do observed subscription rates differ by recorded contact channel?', 'method': 'Group conversion rates with Wilson intervals and sample sizes.', 'action': 'Use the observed differences to design a channel experiment, accounting for who receives each contact.', 'limitations': 'Observational marketing records do not identify campaign uplift. Month and row order are not precise timestamps; repeated-client identifiers are unavailable. Models are research diagnostics, not financial eligibility or automated contact decisions. '}

def analyze():
    df = load('bank').copy()
    t=rates(df,'contact','subscribed')
    out=result(t,'contact','rate','Subscription share','Unknown is retained as its own category. Channel assignment was not randomized.')
    return out

if __name__ == "__main__":
    execute(Path(__file__).parent, META, analyze)