def output_error_graph(output_dim_,Y_header,Date_array,Y,Y_pred,name, fsize = [10,8],color = ['r','g','b'],size = 1,\ filetype_s = '.jpg'): fig = plt.figure(figsize=fsize) error = (Y_pred-Y)**2 for i in range(0,output_dim_,1): plt.subplot(output_dim_,1 , i+1) plt.title(Y_header[i]) plt.scatter(Date_array,error[:,i],c = color[i],s = size) plt.tight_layout() export_graphs(name,fig,filetype = filetype_s)
def output_graphs(output_dim_,Y_header,Y_valid,Y_pred,name,filetype_s = '.jpg',\ x_fig = 8,y_fig = 3,color = ['r','g','b'],size = 0.05,\ parity=True,limits=True,\ xlimit = np.array([-0.1,1.1]),ylimit = np.array([-0.1,1.1])): xy_parity = np.linspace(0,1,100) fig = plt.figure(figsize=(x_fig,y_fig)) for i in range(0,output_dim_,1): plt.subplot(1, output_dim_, i+1) plt.title(Y_header[i]) plt.scatter(Y_valid[:,i],Y_pred[:,i],label = Y_header[i],c = color[i],s = size) if parity: plt.plot(xy_parity,xy_parity,'k') if limits: plt.xlim(xlimit[0],xlimit[1]) plt.ylim(ylimit[0],ylimit[1]) plt.tight_layout() export_graphs(name,fig,filetype = filetype_s)
max_error_ppb = np.max(error_ppb) min_error_ppb = np.min(error_ppb) # for i in range(0, len(Sensor_name), 1): sensor_index = indexall(Sensor_List, Sensor_name[i]) #plot datetime vs abs error fig = plt.figure() plt.plot(date[sensor_index],\ error[sensor_index],'-k',linewidth=2.0) plt.xlabel('Date') plt.ylabel('Error') plt.title('Time Series of Sensor:' + Sensor_name[i]) plt.tight_layout(pad=0.1) name = 'Time_Series' + Sensor_name[i] export_graphs(name, fig, filetype='.jpg') #plot datetime vs error in ppm fig = plt.figure() plt.plot(date[sensor_index],\ error_ppb[sensor_index],'-k',linewidth=2.0) plt.xlabel('Date') plt.ylabel('Error ($ppb$)') plt.title('Real Variable Time Series of Sensor:' + Sensor_name[i]) plt.tight_layout(pad=0.1) name = 'Real_Variable_Time_Series' + Sensor_name[i] export_graphs(name, fig, filetype='.jpg') #plot datetime vs Ozone in ppm
Stack_Predict[:, Y_header_list] = Y_pred #Inverse both the predicted and the actual data Data_Array_Actual_invnorm = s.inverse_transform(Stack_Actual) Data_Array_Predict_invnorm = s.inverse_transform(Stack_Predict) #Store Y data Y_pred_ppm = Data_Array_Predict_invnorm[:, Y_Loc] * 1000 Y_act_ppm = Data_Array_Actual_invnorm[:, Y_Loc] * 1000 #plot the parity plot for the normalized validation data fig = plot_parity(Y_valid[:, 0], Y_pred[:, 0], 'Normalized $O_3$ Values', 'Predicted $O_3$ Values', s=0.5) export_graphs('norm_parity_valid', fig, filetype='.jpg') #plot the parity plot for the unnormalized validation data fig = plot_parity(Y_act_ppm, Y_pred_ppm, 'Actual $O_3$ Values($ppb$)', 'Predicted $O_3$ Values($ppb$)', s=0.5, maxset=True) export_graphs('unnorm_parity_valid', fig, filetype='.jpg') #load in the outside dataset df_test = pd.read_csv(outside_data_path) data_array_test = np.array(df_test) X_Other = data_array_test[:, X_header_list] Y_Other = data_array_test[:, Y_header_list]
#read data and parse the data df = pd.read_csv(full_path) header =list(df) header_num = len(header) #get X and Y values Full_List = list(np.arange(0,header_num-1+1e-6,1,dtype=int)) Y_Loc = header.index('O3 Value') Y_header_list = [] Y_header_list.append(Y_Loc) X_header_list = list(set(Full_List)-set(Y_header_list)) #load neural network load_model_path =\ r"E:\PhD project\ozone\Saved_Neural_Networks\082119_nnet_node_mse_40layer_1new.h5" model = load_model(load_model_path,custom_objects={'r2_keras':r2_keras}) model.summary() #call custom function fig_save,plt_name_save,range_save = Parameter_Analysis(model,header,X_header_list) #export figure for i in range(0,len(fig_save)): export_graphs(plt_name_save[i],fig_save[i]) #plot hist #X_header = header.remove('O3 Value') #plt.figure() #plt.bar(range_save,label=X_header)