Spaces:
Sleeping
Sleeping
File size: 2,053 Bytes
9627b36 d0f2767 9627b36 d0f2767 9627b36 d0f2767 9627b36 d0f2767 |
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 |
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
|