PROJECT 044 · PYTHON SOURCE
Low-strength screening 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': 44, 'dataset': 'concrete', 'title': 'Low-strength screening benchmark', 'question': 'Can mix and age measurements rank specimens below a declared analytical strength threshold?', 'method': 'Binary screening below 30 MPa with composition-grouped evaluation.', 'action': 'Treat the threshold as an example research screen; project-specific engineering requirements must be supplied separately.', '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['below_30mpa']=df.strength.lt(30).astype(int)
t,p,e=classification(df,CONCRETE_FEATURES,'below_30mpa',groups=CONCRETE_FEATURES[:-1])
out=result(t,'model','average_precision','Average precision','30 MPa is a study-defined threshold, not a code requirement or safety certification.',extra={'predictions':p},evaluation=e)
return out
if __name__ == "__main__":
execute(Path(__file__).parent, META, analyze)