Module 5 · Section 12 of 12
Mini-Project 5: Facility Energy Regression Model
Objective: Build a regression model that predicts monthly facility energy demand from temperature and an activity index. Report RMSE, plot predicted vs actual, and explain which feature matters most.
Brief
Using the demand_df dataset from the top of this notebook, build a regression model
predicting demand_mw from avg_temp_c and activity_index. Evaluate it with a
train/test split (not just training performance), report RMSE, plot predicted vs actual
for the test set, and explain which feature matters most using standardized coefficients.
Starter Code
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
X = demand_df[["avg_temp_c", "activity_index"]].values
y = demand_df["demand_mw"].values
# 75/25 split; random_state fixes which rows go where so results are reproducible
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)
model = LinearRegression().fit(X_train, y_train) # fit on the training rows only
y_pred_test = model.predict(X_test) # evaluate on the unseen test rows
rmse_test = mean_squared_error(y_test, y_pred_test) ** 0.5 # typical prediction error, MW
r2_test = r2_score(y_test, y_pred_test)
print(f"Test RMSE: {rmse_test:.1f} MW")
print(f"Test R^2: {r2_test:.3f}")
print(f"\nCoefficients: temperature={model.coef_[0]:.2f} MW/C, activity_index={model.coef_[1]:.2f} MW/point")
fig, ax = plt.subplots(figsize=(6, 6))
ax.scatter(y_test, y_pred_test, alpha=0.7, color="steelblue")
lims = [min(y_test.min(), y_pred_test.min()), max(y_test.max(), y_pred_test.max())]
ax.plot(lims, lims, "r--", label="Perfect prediction")
ax.set_xlabel("Actual Demand (MW)"); ax.set_ylabel("Predicted Demand (MW)")
ax.set_title(f"Test Set: Predicted vs Actual (RMSE={rmse_test:.1f} MW)"); ax.legend()
plt.tight_layout(); plt.show()
# Standardize each feature to mean 0 / std 1, refit: now the coefficients are on
# the same "per 1 standard deviation" scale, so their sizes are comparable.
X_std = (X - X.mean(axis=0)) / X.std(axis=0)
model_std = LinearRegression().fit(X_std, y)
print("\nStandardized coefficients (comparable scale):")
print(f" temperature: {model_std.coef_[0]:.1f}")
print(f" activity_index: {model_std.coef_[1]:.1f}")
Deliverable Checklist
- Model evaluated on a held-out test set, not just training data
- RMSE and R^2 reported for the test set
- Predicted-vs-actual plot included, with a reference diagonal line
- Standardized coefficients used to compare feature importance fairly
- Written interpretation (2-3 sentences): which feature matters more, and does that match physical intuition about what drives facility energy demand?
Grading Rubric
| Criterion | Points |
|---|---|
| Correct train/test split and evaluation methodology | 30 |
| RMSE and R^2 correctly computed and reported | 20 |
| Predicted-vs-actual plot | 20 |
| Feature importance comparison (standardized coefficients) | 15 |
| Written interpretation | 15 |
| Total | 100 |
# Your Mini-Project 5 submission
55 / 63 sections · Course home · Join the coaching cohort