← Back to case study

PROJECT 049 · PYTHON SOURCE

Indoor conditions and appliance use

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': 49, 'dataset': 'energy', 'title': 'Indoor conditions and appliance use', 'question': 'Which recorded indoor conditions have the strongest rank associations with appliance energy?', 'method': 'Pairwise Spearman correlations for room temperatures and humidity.', 'action': 'Investigate schedules and occupancy before treating indoor conditions as explanatory drivers.', 'limitations': 'Measurements come from one home over a limited period. Energy is Wh per recorded 10-minute interval. This is not a representative household sample; tariffs and occupancy labels are unavailable. '}

def analyze():
    df = load('energy').copy()
    features=[f't{i}' for i in range(1,10)]+[f'rh_{i}' for i in range(1,10)]
    t=associations(df,'appliances',features)
    out=result(t,'feature','spearman_rho','Spearman correlation','Contemporaneous measurements cannot be assumed available in advance. Serial dependence prevents interpreting ordinary correlation as causal evidence.')
    return out

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