PROJECT 046 · PYTHON SOURCE
Weekday and weekend load
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': 46, 'dataset': 'energy', 'title': 'Weekday and weekend load', 'question': 'How do interval energy distributions differ across weekdays?', 'method': 'Calendar-day categories with robust energy summaries.', 'action': 'Use the observed schedule as a hypothesis to compare with occupancy and appliance logs.', '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('weekday').appliances.agg(intervals='size',median_wh='median',mean_wh='mean',p90_wh=lambda s:s.quantile(.9)).reset_index()
out=result(t,'weekday','mean_wh','Wh per 10-minute interval','Weekday 0 is Monday. Changes in weather and household behavior are not controlled.')
return out
if __name__ == "__main__":
execute(Path(__file__).parent, META, analyze)