PROJECT 045 · PYTHON SOURCE
Household appliance load profile
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': 45, 'dataset': 'energy', 'title': 'Household appliance load profile', 'question': 'Which hours have the highest typical appliance energy per recorded interval?', 'method': 'Hour-of-day medians, means and sample counts.', 'action': 'Compare actual schedules and occupancy records before proposing load shifting.', '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()
t=df.groupby('hour').appliances.agg(intervals='size',median_wh='median',mean_wh='mean',p90_wh=lambda s:s.quantile(.9)).reset_index()
out=result(t,'hour','mean_wh','Wh per 10-minute interval','These are interval-energy values, not watts. This household may not represent another building.',kind='line')
return out
if __name__ == "__main__":
execute(Path(__file__).parent, META, analyze)