smart-buildings / src /energy_prediction /EnergyPredictionNorth.py
levimohle's picture
start on adding energy prediction to main.py
9627b36
raw
history blame
1.67 kB
import numpy as np
import pandas as pd
from tensorflow.keras.models import load_model
class EnergyPredictionNorth:
"""
Class for predicting energy consumption in the north wing of the building.
"""
def __init__(self,
model_path=None):
"""
Initialize the EnergyPredictionNorth object.
Args:
model_path (str): Path to the prediction model file.
"""
if model_path is not None:
self.load_model(model_path)
def load_model(self, model_path):
"""
Load the prediction model.
Args:
model_path (str): Path to the prediction model file.
"""
self.model = load_model(model_path)
def predict(self, data):
"""
Predict energy consumption based on the input data.
Args:
data (pd.DataFrame): Input data for prediction.
Returns:
np.ndarray: Predicted energy consumption values.
"""
return self.model.predict(data, verbose=0)
def inverse_transform(self, scaler, pred, df_trans):
"""
Inverse transform the predicted and actual values.
Args:
scaler (object): Scaler object for inverse transformation.
pred (array): Predicted values.
df_trans (DataFrame): Transformed input data.
Returns:
tuple: A tuple containing the actual and predicted values after inverse transformation.
"""
mean = scaler.mean_[0]
std = scaler.scale_[0]
pred = pred * std + mean
actual = df_trans[:,0] * std + mean
return actual, pred