annotate ml_visualization_ex.py @ 26:0474777be433 draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
author bgruening
date Wed, 11 Mar 2020 13:43:57 -0400
parents a5aed87b2cc0
children 9b017b0da56e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
1 import argparse
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
2 import json
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
3 import matplotlib
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
4 import matplotlib.pyplot as plt
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
5 import numpy as np
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
6 import os
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
7 import pandas as pd
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
8 import plotly
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
9 import plotly.graph_objs as go
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
10 import warnings
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
11
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
12 from keras.models import model_from_json
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
13 from keras.utils import plot_model
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
14 from sklearn.feature_selection.base import SelectorMixin
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
15 from sklearn.metrics import precision_recall_curve, average_precision_score
26
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
16 from sklearn.metrics import roc_curve, auc, confusion_matrix
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
17 from sklearn.pipeline import Pipeline
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
18 from galaxy_ml.utils import load_model, read_columns, SafeEval
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
19
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
21 safe_eval = SafeEval()
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
22
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
23 # plotly default colors
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
24 default_colors = [
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
25 '#1f77b4', # muted blue
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
26 '#ff7f0e', # safety orange
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
27 '#2ca02c', # cooked asparagus green
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
28 '#d62728', # brick red
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
29 '#9467bd', # muted purple
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
30 '#8c564b', # chestnut brown
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
31 '#e377c2', # raspberry yogurt pink
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
32 '#7f7f7f', # middle gray
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
33 '#bcbd22', # curry yellow-green
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
34 '#17becf' # blue-teal
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
35 ]
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
36
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
37
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
38 def visualize_pr_curve_plotly(df1, df2, pos_label, title=None):
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
39 """output pr-curve in html using plotly
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
40
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
41 df1 : pandas.DataFrame
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
42 Containing y_true
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
43 df2 : pandas.DataFrame
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
44 Containing y_score
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
45 pos_label : None
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
46 The label of positive class
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
47 title : str
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
48 Plot title
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
49 """
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
50 data = []
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
51 for idx in range(df1.shape[1]):
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
52 y_true = df1.iloc[:, idx].values
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
53 y_score = df2.iloc[:, idx].values
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
54
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
55 precision, recall, _ = precision_recall_curve(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
56 y_true, y_score, pos_label=pos_label)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
57 ap = average_precision_score(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
58 y_true, y_score, pos_label=pos_label or 1)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
59
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
60 trace = go.Scatter(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
61 x=recall,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
62 y=precision,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
63 mode='lines',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
64 marker=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
65 color=default_colors[idx % len(default_colors)]
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
66 ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
67 name='%s (area = %.3f)' % (idx, ap)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
68 )
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
69 data.append(trace)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
70
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
71 layout = go.Layout(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
72 xaxis=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
73 title='Recall',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
74 linecolor='lightslategray',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
75 linewidth=1
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
76 ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
77 yaxis=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
78 title='Precision',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
79 linecolor='lightslategray',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
80 linewidth=1
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
81 ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
82 title=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
83 text=title or 'Precision-Recall Curve',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
84 x=0.5,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
85 y=0.92,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
86 xanchor='center',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
87 yanchor='top'
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
88 ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
89 font=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
90 family="sans-serif",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
91 size=11
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
92 ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
93 # control backgroud colors
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
94 plot_bgcolor='rgba(255,255,255,0)'
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
95 )
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
96 """
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
97 legend=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
98 x=0.95,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
99 y=0,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
100 traceorder="normal",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
101 font=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
102 family="sans-serif",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
103 size=9,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
104 color="black"
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
105 ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
106 bgcolor="LightSteelBlue",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
107 bordercolor="Black",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
108 borderwidth=2
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
109 ),"""
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
110
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
111 fig = go.Figure(data=data, layout=layout)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
112
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
113 plotly.offline.plot(fig, filename="output.html", auto_open=False)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
114 # to be discovered by `from_work_dir`
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
115 os.rename('output.html', 'output')
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
116
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
117
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
118 def visualize_pr_curve_matplotlib(df1, df2, pos_label, title=None):
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
119 """visualize pr-curve using matplotlib and output svg image
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
120 """
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
121 backend = matplotlib.get_backend()
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
122 if "inline" not in backend:
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
123 matplotlib.use("SVG")
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
124 plt.style.use('seaborn-colorblind')
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
125 plt.figure()
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
126
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
127 for idx in range(df1.shape[1]):
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
128 y_true = df1.iloc[:, idx].values
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
129 y_score = df2.iloc[:, idx].values
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
130
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
131 precision, recall, _ = precision_recall_curve(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
132 y_true, y_score, pos_label=pos_label)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
133 ap = average_precision_score(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
134 y_true, y_score, pos_label=pos_label or 1)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
135
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
136 plt.step(recall, precision, 'r-', color="black", alpha=0.3,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
137 lw=1, where="post", label='%s (area = %.3f)' % (idx, ap))
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
138
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
139 plt.xlim([0.0, 1.0])
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
140 plt.ylim([0.0, 1.05])
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
141 plt.xlabel('Recall')
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
142 plt.ylabel('Precision')
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
143 title = title or 'Precision-Recall Curve'
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
144 plt.title(title)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
145 folder = os.getcwd()
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
146 plt.savefig(os.path.join(folder, "output.svg"), format="svg")
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
147 os.rename(os.path.join(folder, "output.svg"),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
148 os.path.join(folder, "output"))
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
149
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
150
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
151 def visualize_roc_curve_plotly(df1, df2, pos_label,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
152 drop_intermediate=True,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
153 title=None):
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
154 """output roc-curve in html using plotly
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
155
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
156 df1 : pandas.DataFrame
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
157 Containing y_true
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
158 df2 : pandas.DataFrame
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
159 Containing y_score
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
160 pos_label : None
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
161 The label of positive class
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
162 drop_intermediate : bool
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
163 Whether to drop some suboptimal thresholds
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
164 title : str
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
165 Plot title
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
166 """
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
167 data = []
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
168 for idx in range(df1.shape[1]):
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
169 y_true = df1.iloc[:, idx].values
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
170 y_score = df2.iloc[:, idx].values
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
171
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
172 fpr, tpr, _ = roc_curve(y_true, y_score, pos_label=pos_label,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
173 drop_intermediate=drop_intermediate)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
174 roc_auc = auc(fpr, tpr)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
175
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
176 trace = go.Scatter(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
177 x=fpr,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
178 y=tpr,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
179 mode='lines',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
180 marker=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
181 color=default_colors[idx % len(default_colors)]
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
182 ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
183 name='%s (area = %.3f)' % (idx, roc_auc)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
184 )
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
185 data.append(trace)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
186
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
187 layout = go.Layout(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
188 xaxis=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
189 title='False Positive Rate',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
190 linecolor='lightslategray',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
191 linewidth=1
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
192 ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
193 yaxis=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
194 title='True Positive Rate',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
195 linecolor='lightslategray',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
196 linewidth=1
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
197 ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
198 title=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
199 text=title or 'Receiver Operating Characteristic (ROC) Curve',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
200 x=0.5,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
201 y=0.92,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
202 xanchor='center',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
203 yanchor='top'
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
204 ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
205 font=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
206 family="sans-serif",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
207 size=11
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
208 ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
209 # control backgroud colors
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
210 plot_bgcolor='rgba(255,255,255,0)'
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
211 )
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
212 """
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
213 # legend=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
214 # x=0.95,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
215 # y=0,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
216 # traceorder="normal",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
217 # font=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
218 # family="sans-serif",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
219 # size=9,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
220 # color="black"
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
221 # ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
222 # bgcolor="LightSteelBlue",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
223 # bordercolor="Black",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
224 # borderwidth=2
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
225 # ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
226 """
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
227
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
228 fig = go.Figure(data=data, layout=layout)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
229
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
230 plotly.offline.plot(fig, filename="output.html", auto_open=False)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
231 # to be discovered by `from_work_dir`
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
232 os.rename('output.html', 'output')
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
233
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
234
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
235 def visualize_roc_curve_matplotlib(df1, df2, pos_label,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
236 drop_intermediate=True,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
237 title=None):
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
238 """visualize roc-curve using matplotlib and output svg image
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
239 """
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
240 backend = matplotlib.get_backend()
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
241 if "inline" not in backend:
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
242 matplotlib.use("SVG")
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
243 plt.style.use('seaborn-colorblind')
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
244 plt.figure()
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
245
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
246 for idx in range(df1.shape[1]):
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
247 y_true = df1.iloc[:, idx].values
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
248 y_score = df2.iloc[:, idx].values
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
249
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
250 fpr, tpr, _ = roc_curve(y_true, y_score, pos_label=pos_label,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
251 drop_intermediate=drop_intermediate)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
252 roc_auc = auc(fpr, tpr)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
253
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
254 plt.step(fpr, tpr, 'r-', color="black", alpha=0.3, lw=1,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
255 where="post", label='%s (area = %.3f)' % (idx, roc_auc))
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
256
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
257 plt.xlim([0.0, 1.0])
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
258 plt.ylim([0.0, 1.05])
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
259 plt.xlabel('False Positive Rate')
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
260 plt.ylabel('True Positive Rate')
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
261 title = title or 'Receiver Operating Characteristic (ROC) Curve'
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
262 plt.title(title)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
263 folder = os.getcwd()
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
264 plt.savefig(os.path.join(folder, "output.svg"), format="svg")
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
265 os.rename(os.path.join(folder, "output.svg"),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
266 os.path.join(folder, "output"))
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
267
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
268
26
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
269 def get_dataframe(file_path, plot_selection, header_name, column_name):
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
270 header = 'infer' if plot_selection[header_name] else None
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
271 column_option = plot_selection[column_name]["selected_column_selector_option"]
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
272 if column_option in ["by_index_number", "all_but_by_index_number", "by_header_name", "all_but_by_header_name"]:
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
273 col = plot_selection[column_name]["col1"]
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
274 else:
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
275 col = None
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
276 _, input_df = read_columns(file_path, c=col,
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
277 c_option=column_option,
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
278 return_df=True,
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
279 sep='\t', header=header,
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
280 parse_dates=True)
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
281 return input_df
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
282
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
283
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
284 def main(inputs, infile_estimator=None, infile1=None,
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
285 infile2=None, outfile_result=None,
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
286 outfile_object=None, groups=None,
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
287 ref_seq=None, intervals=None,
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
288 targets=None, fasta_path=None,
26
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
289 model_config=None, true_labels=None,
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
290 predicted_labels=None, plot_color=None,
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
291 title=None):
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
292 """
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
293 Parameter
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
294 ---------
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
295 inputs : str
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
296 File path to galaxy tool parameter
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
297
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
298 infile_estimator : str, default is None
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
299 File path to estimator
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
300
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
301 infile1 : str, default is None
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
302 File path to dataset containing features or true labels.
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
303
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
304 infile2 : str, default is None
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
305 File path to dataset containing target values or predicted
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
306 probabilities.
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
307
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
308 outfile_result : str, default is None
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
309 File path to save the results, either cv_results or test result
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
310
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
311 outfile_object : str, default is None
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
312 File path to save searchCV object
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
313
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
314 groups : str, default is None
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
315 File path to dataset containing groups labels
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
316
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
317 ref_seq : str, default is None
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
318 File path to dataset containing genome sequence file
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
319
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
320 intervals : str, default is None
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
321 File path to dataset containing interval file
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
322
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
323 targets : str, default is None
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
324 File path to dataset compressed target bed file
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
325
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
326 fasta_path : str, default is None
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
327 File path to dataset containing fasta file
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
328
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
329 model_config : str, default is None
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
330 File path to dataset containing JSON config for neural networks
26
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
331
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
332 true_labels : str, default is None
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
333 File path to dataset containing true labels
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
334
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
335 predicted_labels : str, default is None
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
336 File path to dataset containing true predicted labels
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
337
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
338 plot_color : str, default is None
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
339 Color of the confusion matrix heatmap
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
340
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
341 title : str, default is None
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
342 Title of the confusion matrix heatmap
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
343 """
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
344 warnings.simplefilter('ignore')
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
345
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
346 with open(inputs, 'r') as param_handler:
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
347 params = json.load(param_handler)
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
348
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
349 title = params['plotting_selection']['title'].strip()
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
350 plot_type = params['plotting_selection']['plot_type']
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
351 plot_format = params['plotting_selection']['plot_format']
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
352
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
353 if plot_type == 'feature_importances':
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
354 with open(infile_estimator, 'rb') as estimator_handler:
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
355 estimator = load_model(estimator_handler)
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
356
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
357 column_option = (params['plotting_selection']
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
358 ['column_selector_options']
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
359 ['selected_column_selector_option'])
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
360 if column_option in ['by_index_number', 'all_but_by_index_number',
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
361 'by_header_name', 'all_but_by_header_name']:
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
362 c = (params['plotting_selection']
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
363 ['column_selector_options']['col1'])
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
364 else:
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
365 c = None
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
366
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
367 _, input_df = read_columns(infile1, c=c,
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
368 c_option=column_option,
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
369 return_df=True,
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
370 sep='\t', header='infer',
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
371 parse_dates=True)
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
372
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
373 feature_names = input_df.columns.values
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
374
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
375 if isinstance(estimator, Pipeline):
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
376 for st in estimator.steps[:-1]:
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
377 if isinstance(st[-1], SelectorMixin):
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
378 mask = st[-1].get_support()
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
379 feature_names = feature_names[mask]
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
380 estimator = estimator.steps[-1][-1]
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
381
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
382 if hasattr(estimator, 'coef_'):
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
383 coefs = estimator.coef_
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
384 else:
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
385 coefs = getattr(estimator, 'feature_importances_', None)
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
386 if coefs is None:
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
387 raise RuntimeError('The classifier does not expose '
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
388 '"coef_" or "feature_importances_" '
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
389 'attributes')
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
390
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
391 threshold = params['plotting_selection']['threshold']
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
392 if threshold is not None:
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
393 mask = (coefs > threshold) | (coefs < -threshold)
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
394 coefs = coefs[mask]
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
395 feature_names = feature_names[mask]
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
396
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
397 # sort
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
398 indices = np.argsort(coefs)[::-1]
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
399
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
400 trace = go.Bar(x=feature_names[indices],
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
401 y=coefs[indices])
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
402 layout = go.Layout(title=title or "Feature Importances")
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
403 fig = go.Figure(data=[trace], layout=layout)
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
404
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
405 plotly.offline.plot(fig, filename="output.html",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
406 auto_open=False)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
407 # to be discovered by `from_work_dir`
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
408 os.rename('output.html', 'output')
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
409
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
410 return 0
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
411
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
412 elif plot_type in ('pr_curve', 'roc_curve'):
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
413 df1 = pd.read_csv(infile1, sep='\t', header='infer')
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
414 df2 = pd.read_csv(infile2, sep='\t', header='infer').astype(np.float32)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
415
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
416 minimum = params['plotting_selection']['report_minimum_n_positives']
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
417 # filter out columns whose n_positives is beblow the threhold
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
418 if minimum:
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
419 mask = df1.sum(axis=0) >= minimum
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
420 df1 = df1.loc[:, mask]
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
421 df2 = df2.loc[:, mask]
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
422
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
423 pos_label = params['plotting_selection']['pos_label'].strip() \
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
424 or None
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
425
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
426 if plot_type == 'pr_curve':
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
427 if plot_format == 'plotly_html':
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
428 visualize_pr_curve_plotly(df1, df2, pos_label, title=title)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
429 else:
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
430 visualize_pr_curve_matplotlib(df1, df2, pos_label, title)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
431 else: # 'roc_curve'
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
432 drop_intermediate = (params['plotting_selection']
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
433 ['drop_intermediate'])
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
434 if plot_format == 'plotly_html':
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
435 visualize_roc_curve_plotly(df1, df2, pos_label,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
436 drop_intermediate=drop_intermediate,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
437 title=title)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
438 else:
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
439 visualize_roc_curve_matplotlib(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
440 df1, df2, pos_label,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
441 drop_intermediate=drop_intermediate,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
442 title=title)
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
443
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
444 return 0
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
445
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
446 elif plot_type == 'rfecv_gridscores':
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
447 input_df = pd.read_csv(infile1, sep='\t', header='infer')
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
448 scores = input_df.iloc[:, 0]
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
449 steps = params['plotting_selection']['steps'].strip()
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
450 steps = safe_eval(steps)
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
451
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
452 data = go.Scatter(
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
453 x=list(range(len(scores))),
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
454 y=scores,
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
455 text=[str(_) for _ in steps] if steps else None,
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
456 mode='lines'
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
457 )
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
458 layout = go.Layout(
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
459 xaxis=dict(title="Number of features selected"),
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
460 yaxis=dict(title="Cross validation score"),
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
461 title=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
462 text=title or None,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
463 x=0.5,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
464 y=0.92,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
465 xanchor='center',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
466 yanchor='top'
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
467 ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
468 font=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
469 family="sans-serif",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
470 size=11
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
471 ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
472 # control backgroud colors
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
473 plot_bgcolor='rgba(255,255,255,0)'
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
474 )
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
475 """
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
476 # legend=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
477 # x=0.95,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
478 # y=0,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
479 # traceorder="normal",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
480 # font=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
481 # family="sans-serif",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
482 # size=9,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
483 # color="black"
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
484 # ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
485 # bgcolor="LightSteelBlue",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
486 # bordercolor="Black",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
487 # borderwidth=2
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
488 # ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
489 """
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
490
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
491 fig = go.Figure(data=[data], layout=layout)
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
492 plotly.offline.plot(fig, filename="output.html",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
493 auto_open=False)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
494 # to be discovered by `from_work_dir`
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
495 os.rename('output.html', 'output')
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
496
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
497 return 0
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
498
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
499 elif plot_type == 'learning_curve':
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
500 input_df = pd.read_csv(infile1, sep='\t', header='infer')
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
501 plot_std_err = params['plotting_selection']['plot_std_err']
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
502 data1 = go.Scatter(
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
503 x=input_df['train_sizes_abs'],
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
504 y=input_df['mean_train_scores'],
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
505 error_y=dict(
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
506 array=input_df['std_train_scores']
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
507 ) if plot_std_err else None,
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
508 mode='lines',
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
509 name="Train Scores",
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
510 )
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
511 data2 = go.Scatter(
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
512 x=input_df['train_sizes_abs'],
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
513 y=input_df['mean_test_scores'],
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
514 error_y=dict(
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
515 array=input_df['std_test_scores']
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
516 ) if plot_std_err else None,
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
517 mode='lines',
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
518 name="Test Scores",
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
519 )
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
520 layout = dict(
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
521 xaxis=dict(
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
522 title='No. of samples'
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
523 ),
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
524 yaxis=dict(
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
525 title='Performance Score'
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
526 ),
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
527 # modify these configurations to customize image
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
528 title=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
529 text=title or 'Learning Curve',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
530 x=0.5,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
531 y=0.92,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
532 xanchor='center',
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
533 yanchor='top'
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
534 ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
535 font=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
536 family="sans-serif",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
537 size=11
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
538 ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
539 # control backgroud colors
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
540 plot_bgcolor='rgba(255,255,255,0)'
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
541 )
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
542 """
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
543 # legend=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
544 # x=0.95,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
545 # y=0,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
546 # traceorder="normal",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
547 # font=dict(
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
548 # family="sans-serif",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
549 # size=9,
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
550 # color="black"
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
551 # ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
552 # bgcolor="LightSteelBlue",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
553 # bordercolor="Black",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
554 # borderwidth=2
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
555 # ),
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
556 """
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
557
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
558 fig = go.Figure(data=[data1, data2], layout=layout)
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
559 plotly.offline.plot(fig, filename="output.html",
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
560 auto_open=False)
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
561 # to be discovered by `from_work_dir`
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
562 os.rename('output.html', 'output')
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
563
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
564 return 0
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
565
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
566 elif plot_type == 'keras_plot_model':
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
567 with open(model_config, 'r') as f:
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
568 model_str = f.read()
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
569 model = model_from_json(model_str)
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
570 plot_model(model, to_file="output.png")
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
571 os.rename('output.png', 'output')
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
572
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
573 return 0
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
574
26
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
575 elif plot_type == 'classification_confusion_matrix':
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
576 plot_selection = params["plotting_selection"]
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
577 input_true = get_dataframe(true_labels, plot_selection, "header_true", "column_selector_options_true")
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
578 header_predicted = 'infer' if plot_selection["header_predicted"] else None
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
579 input_predicted = pd.read_csv(predicted_labels, sep='\t', parse_dates=True, header=header_predicted)
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
580 true_classes = input_true.iloc[:, -1].copy()
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
581 predicted_classes = input_predicted.iloc[:, -1].copy()
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
582 axis_labels = list(set(true_classes))
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
583 c_matrix = confusion_matrix(true_classes, predicted_classes)
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
584 fig, ax = plt.subplots(figsize=(7, 7))
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
585 im = plt.imshow(c_matrix, cmap=plot_color)
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
586 for i in range(len(c_matrix)):
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
587 for j in range(len(c_matrix)):
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
588 ax.text(j, i, c_matrix[i, j], ha="center", va="center", color="k")
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
589 ax.set_ylabel('True class labels')
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
590 ax.set_xlabel('Predicted class labels')
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
591 ax.set_title(title)
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
592 ax.set_xticks(axis_labels)
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
593 ax.set_yticks(axis_labels)
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
594 fig.colorbar(im, ax=ax)
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
595 fig.tight_layout()
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
596 plt.savefig("output.png", dpi=125)
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
597 os.rename('output.png', 'output')
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
598
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
599 return 0
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
600
24
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
601 # save pdf file to disk
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
602 # fig.write_image("image.pdf", format='pdf')
a5aed87b2cc0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 21
diff changeset
603 # fig.write_image("image.pdf", format='pdf', width=340*2, height=226*2)
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
604
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
605
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
606 if __name__ == '__main__':
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
607 aparser = argparse.ArgumentParser()
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
608 aparser.add_argument("-i", "--inputs", dest="inputs", required=True)
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
609 aparser.add_argument("-e", "--estimator", dest="infile_estimator")
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
610 aparser.add_argument("-X", "--infile1", dest="infile1")
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
611 aparser.add_argument("-y", "--infile2", dest="infile2")
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
612 aparser.add_argument("-O", "--outfile_result", dest="outfile_result")
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
613 aparser.add_argument("-o", "--outfile_object", dest="outfile_object")
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
614 aparser.add_argument("-g", "--groups", dest="groups")
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
615 aparser.add_argument("-r", "--ref_seq", dest="ref_seq")
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
616 aparser.add_argument("-b", "--intervals", dest="intervals")
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
617 aparser.add_argument("-t", "--targets", dest="targets")
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
618 aparser.add_argument("-f", "--fasta_path", dest="fasta_path")
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
619 aparser.add_argument("-c", "--model_config", dest="model_config")
26
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
620 aparser.add_argument("-tl", "--true_labels", dest="true_labels")
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
621 aparser.add_argument("-pl", "--predicted_labels", dest="predicted_labels")
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
622 aparser.add_argument("-pc", "--plot_color", dest="plot_color")
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
623 aparser.add_argument("-pt", "--title", dest="title")
20
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
624 args = aparser.parse_args()
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
625
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
626 main(args.inputs, args.infile_estimator, args.infile1, args.infile2,
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
627 args.outfile_result, outfile_object=args.outfile_object,
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
628 groups=args.groups, ref_seq=args.ref_seq, intervals=args.intervals,
5895fe0b8bde "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
629 targets=args.targets, fasta_path=args.fasta_path,
26
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
630 model_config=args.model_config, true_labels=args.true_labels,
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
631 predicted_labels=args.predicted_labels,
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
632 plot_color=args.plot_color,
0474777be433 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9e28f4466084464d38d3f8db2aff07974be4ba69"
bgruening
parents: 24
diff changeset
633 title=args.title)