Spaces:
Runtime error
Runtime error
File size: 2,328 Bytes
96aeb3b 27f68f7 96aeb3b 3355e89 96aeb3b 3355e89 96aeb3b 3355e89 96aeb3b 3355e89 96aeb3b 27f68f7 3355e89 27f68f7 3355e89 27f68f7 3355e89 27f68f7 3355e89 27f68f7 3355e89 27f68f7 3355e89 27f68f7 3355e89 27f68f7 3355e89 27f68f7 3355e89 27f68f7 3355e89 |
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 |
import os
import tensorflow as tf
from keras.models import load_model
from tensorflow.keras.losses import MeanSquaredError
import pandas as pd
from sklearn.preprocessing import OneHotEncoder, StandardScaler
# Disable GPU if not needed
os.environ["CUDA_VISIBLE_DEVICES"] = "-1" # Disable GPU for CPU-only execution
# Function to load the model and set the loss function explicitly
def load_and_compile_model(model_path):
model = load_model(model_path, custom_objects={'MeanSquaredError': MeanSquaredError})
model.compile(optimizer='adam', loss=MeanSquaredError())
return model
# Load the model
loaded_model = load_and_compile_model('solar_irradiance_model.h5')
# Load the dataset
data = pd.read_csv('Solar_Irradiance.csv')
# Example data preparation (adjust as needed based on your dataset)
data['Latitude'] = data['Latitude'].str.rstrip('°').astype(float)
data['Longitude'] = data['Longitude'].str.rstrip('°').astype(float)
# Define feature columns
features = data[['Month', 'Hour', 'Latitude', 'Longitude', 'Panel_Capacity(W)', 'Panel_Efficiency', 'Wind_Speed(km/h)', 'Cloud_Cover(%)', 'temperature (°f)']]
# One-hot encoding for categorical variables
encoder = OneHotEncoder(sparse_output=False, categories='auto')
categorical_features = features[['Month', 'Hour']]
encoder.fit(categorical_features)
# Scaling numerical features
scaler = StandardScaler()
numerical_features = features[['Latitude', 'Longitude', 'Panel_Capacity(W)', 'Panel_Efficiency', 'Wind_Speed(km/h)', 'Cloud_Cover(%)', 'temperature (°f)']]
scaler.fit(numerical_features)
# Prepare the data by transforming categorical and numerical features
encoded_categorical_features = encoder.transform(categorical_features)
scaled_numerical_features = scaler.transform(numerical_features)
# Combine the transformed features
processed_features = pd.DataFrame(encoded_categorical_features, columns=encoder.get_feature_names_out())
processed_features[numerical_features.columns] = scaled_numerical_features
# Assuming you have a target column, for example 'Solar_Irradiance', adjust as needed
target = data['Solar_Irradiance'] # Make sure to replace this with your actual target column name
# Make predictions using the loaded model
predictions = loaded_model.predict(processed_features)
# Print or save the predictions
print(predictions)
|