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)