comparison plot_regression_performance.py @ 0:0800a1b66bbd draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/plotly_regression_performance_plots commit c17efec384ad7438f54675fae1ab0c3a57c22869
author bgruening
date Thu, 08 Nov 2018 13:28:04 -0500
parents
children 389227fa1864
comparison
equal deleted inserted replaced
-1:000000000000 0:0800a1b66bbd
1 import argparse
2 import pandas as pd
3 import plotly
4 import plotly.graph_objs as go
5
6
7 def main(infile_input, infile_output):
8 """
9 Produce an interactive actual vs predicted curves and residual plots
10 Args:
11 infile_input: str, input tabular file with true values
12 infile_output: str, input tabular file with predicted values
13 """
14
15 df_input = pd.read_csv(infile_input, sep='\t', parse_dates=True)
16 df_output = pd.read_csv(infile_output, sep='\t', parse_dates=True)
17 true_values = df_input.iloc[:, -1].copy()
18 predicted_values = df_output.iloc[:, -1].copy()
19 axis_labels = list(range(1, len(true_values)+1))
20
21 # true vs predicted curves
22 trace_true = go.Scatter(
23 x=axis_labels,
24 y=true_values,
25 mode='lines+markers',
26 name='True values'
27 )
28
29 trace_predicted = go.Scatter(
30 x=axis_labels,
31 y=predicted_values,
32 mode='lines+markers',
33 name='Predicted values'
34 )
35
36 layout_tp = go.Layout(
37 title='True vs predicted values',
38 xaxis=dict(title='Number of data points'),
39 yaxis=dict(title='Values')
40 )
41
42 data_tp = [trace_true, trace_predicted]
43 fig_tp = go.Figure(data=data_tp, layout=layout_tp)
44 plotly.offline.plot(fig_tp, filename="output_actual_vs_pred.html", auto_open=False)
45
46 # scatter plot
47 max_tv = int(max(true_values))
48 x_y_values = list(range(0, max_tv))
49
50 trace_x_eq_y = go.Scatter(
51 x=x_y_values,
52 y=x_y_values,
53 mode='lines',
54 name='X = Y curve'
55 )
56
57 trace_true_pred = go.Scatter(
58 x=true_values,
59 y=predicted_values,
60 mode='markers',
61 name='True and predicted values'
62 )
63
64 layout_true_pred = go.Layout(
65 title='True vs predicted values',
66 xaxis=dict(title='True values'),
67 yaxis=dict(title='Predicted values')
68 )
69
70 data_true_pred = [trace_true_pred, trace_x_eq_y]
71 fig_true_pred = go.Figure(data=data_true_pred, layout=layout_true_pred)
72 plotly.offline.plot(fig_true_pred, filename="output_scatter_plot.html", auto_open=False)
73
74 # residual plot
75 residual = predicted_values - true_values
76 trace_residual = go.Scatter(
77 x=predicted_values,
78 y=residual,
79 mode='markers'
80 )
81
82 layout_residual = go.Layout(
83 title='Residual vs predicted values',
84 xaxis=dict(title='Predicted values'),
85 yaxis=dict(title='Residual (Predicted - True)')
86 )
87
88 data_residual = [trace_residual]
89 fig_residual = go.Figure(data=data_residual, layout=layout_residual)
90 plotly.offline.plot(fig_residual, filename="output_residual_plot.html", auto_open=False)
91
92
93 if __name__ == "__main__":
94 aparser = argparse.ArgumentParser()
95 aparser.add_argument("-i", "--input", dest="infile_input", required=True)
96 aparser.add_argument("-j", "--output", dest="infile_output", required=True)
97 args = aparser.parse_args()
98 main(args.infile_input, args.infile_output)