PROJECT 038 · PYTHON SOURCE
Water-to-binder ratio analysis
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': 38, 'dataset': 'concrete', 'title': 'Water-to-binder ratio analysis', 'question': 'How does observed water-to-binder ratio relate to strength?', 'method': 'Binder defined as cement plus slag plus fly ash, with fixed ratio bands.', 'action': 'Compare like-for-like curing conditions before drawing formulation conclusions.', '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()
df['binder']=df.cement+df.slag+df.fly_ash
df=df[df.binder>0].copy();df['ratio']=df.water/df.binder
df['ratio_band']=pd.cut(df.ratio,[0,.3,.4,.5,.6,.8,np.inf]).astype(str)
t=df.groupby('ratio_band').strength.agg(samples='size',median_strength='median',mean_strength='mean').reset_index()
out=result(t,'ratio_band','median_strength','MPa','Binder definition is explicit; strength differences also reflect age and other mix variables.')
return out
if __name__ == "__main__":
execute(Path(__file__).parent, META, analyze)