Spaces:
Sleeping
Sleeping
import numpy as np | |
import pandas as pd | |
from tensorflow.keras.models import load_model | |
class EnergyPredictionModel: | |
""" | |
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): | |
""" | |
Inverse transform the predicted and actual values. | |
Args: | |
scaler (object): Scaler object for inverse transformation. | |
pred (array): Predicted values. | |
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 pred | |
def pipeline(self, data, scaler): | |
""" | |
Run the prediction pipeline. | |
Args: | |
df (pd.DataFrame): Input data for prediction. | |
scaler (object): Scaler object for inverse transformation. | |
Returns: | |
tuple: A tuple containing the actual and predicted values after inverse transformation. | |
""" | |
pred = self.predict(data) | |
pred_scaled = self.inverse_transform(scaler, pred) | |
return pred_scaled | |