PROJECT 056 · PYTHON SOURCE
Multisensor cross-sensitivity
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': 56, 'dataset': 'air', 'title': 'Multisensor cross-sensitivity', 'question': 'Which sensor responses are most associated with each available gas reference?', 'method': 'Pairwise-complete rank correlations across five sensor channels and three references.', 'action': 'Investigate cross-sensitivity before assigning a sensor a single-gas interpretation.', 'limitations': 'The -200 sentinel is treated as missing. Reference instruments have incomplete coverage; comparisons use paired observations. Sensor calibration is retrospective, not a health or regulatory compliance assessment. '}
def analyze():
df = load('air').copy()
tables=[]
for target in ['co_gt','nox_gt','no2_gt']:
t=associations(df,target,AIR_SENSORS[:5]);t['reference']=target;tables.append(t)
t=pd.concat(tables);t['pair']=t.reference+' / '+t.feature
out=result(t,'pair','spearman_rho','Spearman correlation','Paired sample sizes differ across references. Common environmental conditions can induce these associations.')
return out
if __name__ == "__main__":
execute(Path(__file__).parent, META, analyze)