code: Placeholder for storing the data frames dataframes = [] xscaler =…
- User
code:
Placeholder for storing the data frames
data_frames = []
x_scaler = joblib.load('snn_all_1142_x_scaler.sav') x_scaler = joblib.load('snn_all_1142_yhlp1_scaler.sav') x_scaler = joblib.load('snn_all_1142_yhlp2_scaler.sav') x_scaler = joblib.load('snn_all_1142_yhlp3_scaler.sav') x_scaler = joblib.load('snn_all_1142_yhlp5_scaler.sav')
model_y1 = load_model('snn_1142_hlp1_sec_5m_relu_trainloss09_mae17_valloss22_mae22.h5') model_y2 = load_model('snn_1142_hlp2_sec_5m_relu_trainloss07_mae15_valloss36_mae19.h5') model_y3 = load_model('snn_1142_hlp3_sec_5m_relu_trainloss05_mae13_valloss17_mae17.h5') model_y5 = load_model('snn_1142_hlp5_5m_relu_trainloss05_mae12_valloss12_mae14.h5')
Loop over the list of csv files
for csv_file in csv_files: # Read the CSV file unique_part = csv_file.split('_')[-2] file_path = os.path.join(csv_directory, csv_file) df = pd.read_csv(file_path) # Assuming ‘df’ is your DataFrame and ‘Label’ is the target column X = df.drop(['y_High_1d', 'y_Low_1d', 'y_Priority_1d', 'y_High_2d', 'y_Low_2d', 'y_Priority_2d', 'y_High_3d', 'y_Low_3d', 'y_Priority_3d', 'y_High_5d', 'y_Low_5d', 'y_Priority_5d'], axis=1).values Y1_actual = df[['y_High_1d', 'y_Low_1d', 'y_Priority_1d']].values Y2_actual = df[['y_High_2d', 'y_Low_2d', 'y_Priority_2d']].values Y3_actual = df[['y_High_3d', 'y_Low_3d', 'y_Priority_3d']].values Y5_actual = df[['y_High_5d', 'y_Low_5d', 'y_Priority_5d']].values
X_scaled = x_scaler.fit(X) # Make predictions Y1_pred = model_y1.predict(X_scaled) Y2_pred = model_y2.predict(X_scaled) Y3_pred = model_y3.predict(X_scaled) Y5_pred = model_y5.predict(X_scaled) # Note: If your y values were scaled during training, you should inverse transform # the predictions and the actual y values before calculating the MAE Y1_pred_actual = scaler_y1.inverse_transform(Y1_pred) Y2_pred_actual = scaler_y2.inverse_transform(Y2_pred) Y3_pred_actual = scaler_y3.inverse_transform(Y3_pred) Y5_pred_actual = scaler_y5.inverse_transform(Y5_pred)file_results = {'file_name': csv_file} # Calculate MAE for each column and add to the dictionary for i, label in enumerate(labels): file_results[f'Y1_{label}_MAE'] = mean_absolute_error(Y1_actual[:, i], Y1_pred_actual[:, i]) file_results[f'Y2{label}_MAE'] = mean_absolute_error(Y2_actual[:, i], Y2_pred_actual[:, i]) file_results[f'Y3{label}_MAE'] = mean_absolute_error(Y3_actual[:, i], Y3_pred_actual[:, i]) file_results[f'Y5{label}_MAE'] = mean_absolute_error(Y5_actual[:, i], Y5_pred_actual[:, i])
# Append the results of this file to the main results list results.append(file_results)Convert the list of dictionaries to a DataFrame
results_df = pd.DataFrame(results)
Output the DataFrame to a CSV file
results_csv_path = 'mae_results.csv' # Define the output path results_df.to_csv(results_csv_path, index=False) # Export to CSV without the index
error: { "name": "ImportError", "message": "Filepath looks like a hdf5 file but h5py is not available. filepath=snn_1142_hlp1_sec_5m_relu_trainloss09_mae17_valloss22_mae22.h5", "stack": "--------------------------------------------------------------------------- ImportError Traceback (most recent call last) Cell In[9], line 10 7 x_scaler = joblib.load('snn_all_1142_yhlp3_scaler.sav') 8 x_scaler = joblib.load('snn_all_1142_yhlp5_scaler.sav') ---> 10 model_y1 = load_model('snn_1142_hlp1_sec_5m_relu_trainloss09_mae17_valloss22_mae22.h5') 11 model_y2 = load_model('snn_1142_hlp2_sec_5m_relu_trainloss07_mae15_valloss36_mae19.h5') 12 model_y3 = load_model('snn_1142_hlp3_sec_5m_relu_trainloss05_mae13_valloss17_mae17.h5')
- Assistant
The error message indicates that the file you're trying to load with
load_modelfunction appears to be an HDF5 file, but the Python packageh5pyrequired for handling HDF5 files is not installed in your environment.HDF5 is a data model, library, and file format for storing and managing data. The package is a Pythonic interface to the HDF5 binary data format and is required to load Keras models saved in this format.
- User
in my code i want to add Y1_pred_actual Y2_pred_actual Y3_pred_actual Y5_pred_actual to each csv files whit following naming : for i, label in enumerate(labels): file_results[f'Y1_{label}_pred']
- Assistant