← Back to case study

PROJECT 039 · PYTHON SOURCE

Supplementary binder usage

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': 39, 'dataset': 'concrete', 'title': 'Supplementary binder usage', 'question': 'How do observed supplementary-binder fractions compare in 28-day samples?', 'method': 'Restrict to 28-day tests, then summarize strength by slag-plus-fly-ash share.', 'action': 'Investigate comparable alternatives using additional durability, cost and embodied-carbon evidence.', 'limitations': 'Laboratory observations do not certify a construction mix. Composition and curing conditions are confounded. Models require independent engineering validation and cannot replace strength testing. '}

def analyze():
    df = load('concrete').copy()
    d=df[df.age.eq(28)].copy();d['replacement']=(d.slag+d.fly_ash)/(d.cement+d.slag+d.fly_ash)
    d['fraction_band']=pd.cut(d.replacement,[-.001,0,.2,.4,.6,1.]).astype(str)
    t=d.groupby('fraction_band').strength.agg(samples='size',median_strength='median',p10=lambda s:s.quantile(.1)).reset_index()
    out=result(t,'fraction_band','median_strength','MPa','No emissions or costs are supplied; a replacement fraction cannot establish a sustainability benefit.')
    return out

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