PROJECT 020 · PYTHON SOURCE
Pre-call subscription benchmark
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': 20, 'dataset': 'bank', 'title': 'Pre-call subscription benchmark', 'question': 'Can contact context and prior campaign history predict subscription without call duration?', 'method': 'Fixed logistic and forest benchmarks against a prior baseline on the final source-order fifth.', 'action': 'Evaluate ranking and calibration before considering a consent-aware operational pilot.', '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,p,e=classification(df,BANK_FEATURES,'subscribed',split='ordered')
out=result(t,'model','average_precision','Average precision','Duration, demographics and financial account fields are excluded. Row order is a coarse chronological proxy.',extra={'predictions':p},evaluation=e)
return out
if __name__ == "__main__":
execute(Path(__file__).parent, META, analyze)