-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualize_application_of_model.py
More file actions
119 lines (101 loc) · 3.93 KB
/
visualize_application_of_model.py
File metadata and controls
119 lines (101 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 26 22:06:19 2025
@author: luisfernando
"""
import numpy as np
import pandas as pd
from joblib import load
import matplotlib.pyplot as plt
import time
'''
Start the process below.
'''
START_PROCESS = time.time()
# Constants and fixed features for a colder day
indoor_temp = 22 # Indoor temperature in °C
outdoor_temp_base = -15 # Base outdoor temperature for a colder day
amplitude = 5 # Smaller daily temperature amplitude for a colder day
time_intervals = np.arange(0, 24, 0.25) # 96 intervals (every 15 minutes)
# Generate `Diff` as the difference between indoor and outdoor temperatures
outdoor_temp = outdoor_temp_base + amplitude * (1 - np.cos(2 * np.pi * time_intervals / 24))
Diff = indoor_temp - outdoor_temp
# Generate the dataset for 96 intervals with adjusted feature values
data = pd.DataFrame({
'Diff': Diff,
'sqft': [1500] * 96, # Example fixed value
'representative_income': [50000] * 96, # Example fixed value
'occupants': [4] * 96, # Example fixed value
'usage_level': [1.9] * 96, # Closer to mean (1.9999185)
'rmb_heating_primary': [57.8] * 96, # Closer to mean (57.7726467)
'rmb_heating_backup': [0.0] * 96, # Closer to mean (0.0)
'vintage': [1980] * 96, # Set vintage to 1980
'rmb_window_area': [193] * 96, # Closer to mean (193.216062)
'duct_leakage_and_insulation': [18.4] * 96, # Closer to mean (18.3767955)
'heating_setpoint': [69.2] * 96, # Closer to mean (69.1950475)
'hvac_heating_efficiency': [83.0] * 96 # Closer to mean (83.0066855)
})
# Hard-coded scaler parameters aligned with the feature list
scaler_mean = [
22.1731321, # Diff
2268.69605, # sqft
115660.286, # representative_income
2.78307, # occupants
1.9999185, # usage_level
57.7726467, # rmb_heating_primary
0.0, # rmb_heating_backup
1986.69608, # vintage
193.216062, # rmb_window_area
18.3767955, # duct_leakage_and_insulation
69.1950475, # heating_setpoint
83.0066855 # hvac_heating_efficiency
]
scaler_scale = [
7.56469631, # Diff
1095.20538, # sqft
78494.1249, # representative_income
1.45644786, # occupants
0.704425648, # usage_level
28.8588336, # rmb_heating_primary
1.0, # rmb_heating_backup
12.7390631, # vintage
123.946053, # rmb_window_area
24.5610850, # duct_leakage_and_insulation
2.93397699, # heating_setpoint
7.45687177 # hvac_heating_efficiency
]
# Scale the data
scaled_data = (
(data - scaler_mean) / scaler_scale
).to_numpy()
# Load your model
model_path = "MODELS_PACKED/saved_models_4/Random Forest_Set 4_Main Heat.joblib"
model = load(model_path)
# Predict using the model
predictions = model.predict(scaled_data)
# Add predictions to the dataset
data['Predicted Output'] = predictions
# Plot the predictions and temperature (Diff)
fig, ax1 = plt.subplots(figsize=(12, 6))
# Plot the Predicted Output on the primary y-axis
ax1.plot(time_intervals, predictions, label='Predicted Output', color='tab:blue', marker='o')
ax1.set_xlabel('Time of Day (Hours)', fontsize=14)
ax1.set_ylabel('Predicted Output', color='tab:blue', fontsize=14)
ax1.tick_params(axis='y', labelcolor='tab:blue')
ax1.grid(True, linestyle='--', alpha=0.7)
# Create a secondary y-axis for Diff
ax2 = ax1.twinx()
ax2.plot(time_intervals, Diff, label='Temperature Difference (Diff)', color='tab:red', linestyle='--')
ax2.set_ylabel('Temperature Difference (°C)', color='tab:red', fontsize=14)
ax2.tick_params(axis='y', labelcolor='tab:red')
# Add a legend
fig.legend(loc="upper left", bbox_to_anchor=(0.1, 0.9), fontsize=12)
# Enhance layout
plt.title('Daily Curve Predictions with Temperature Difference', fontsize=16)
plt.xticks(np.arange(0, 25, 2), fontsize=12)
plt.tight_layout()
plt.show()
END_PROCESS = time.time()
TIME_ELAPSED = -START_PROCESS + END_PROCESS
print('\n TIME ELAPSED:')
print(str(TIME_ELAPSED) + ' seconds /', str(TIME_ELAPSED/60) + ' minutes.')