PROJECT 041 · PYTHON SOURCE
Concrete strength prediction
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': 41, 'dataset': 'concrete', 'title': 'Concrete strength prediction', 'question': 'Can mix measurements predict strength beyond a median baseline on unseen formulations?', 'method': 'Grouped composition split, fixed Ridge and Extra Trees benchmarks, original-unit errors.', 'action': 'Assess external laboratory generalization before any engineering application.', '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()
t,p,e=regression(df,CONCRETE_FEATURES,'strength',groups=CONCRETE_FEATURES[:-1])
out=result(t,'model','mae','MPa MAE','All ages of an identical composition stay in the same split; this prevents repeated-formulation overlap.',extra={'predictions':p},evaluation=e)
return out
if __name__ == "__main__":
execute(Path(__file__).parent, META, analyze)