def make_deliverable_table(**kwargs): # from ipy_table import * import ipy_table lst = [["", "Max overhead", "Mean overhead", "Median overhead", "300-deliverable", "300/1000-usable"]] for name, data in kwargs.iteritems(): lst.append([name] + compute_deliverable(data)) tbl = ipy_table.make_table(map(list, zip(*lst))) ipy_table.apply_theme('basic_both') return tbl
def make_deliverable_table(**kwargs): # from ipy_table import * import ipy_table lst = [[ "", "Max overhead", "Mean overhead", "Median overhead", "300-deliverable", "300/1000-usable" ]] for name, data in kwargs.iteritems(): lst.append([name] + compute_deliverable(data)) tbl = ipy_table.make_table(map(list, zip(*lst))) ipy_table.apply_theme('basic_both') return tbl
def SvenssonTable(tabledata): Sdata = ordinalData(tabledata) n = len(tabledata) make_table(Sdata) apply_theme('basic_both') set_cell_style(0, 0, thick_border='left,top') #set_cell_style(0, 0, color='lightblack') set_column_style(0, color='lightgray') for i in range(1, n + 1): set_cell_style(i, n + 1 - i, thick_border='all', color="lightbrown") return set_cell_style(0, 0, color='orange')
def smt_ipy_table(records, fields, parameters=[]): from ipy_table import make_table import ipy_table table = [[field.title() for field in fields]] for record in records: record_list = [] for field in fields: attr = getattr(record, field) if field == 'timestamp': s = attr.strftime('%Y-%m-%d %H:%M') elif field == 'repository': s = '{0}'.format(attr.upstream) elif field == 'parameters' and parameters: s = '' d = attr.as_dict() for p in parameters: s += ' {0}: {1},'.format(p, d[p]) s = s[1:-1] elif field == 'tags': s = '' for tag in attr: s += ' {0},'.format(tag) s = s[1:-1] elif field == 'version': s = attr[:12] elif field == 'duration': s = human_readable_duration(attr) elif field == 'label': s = attr[:8] else: s = str(attr) c = cgi.escape(s) # if field in ('label', 'timestamp', 'repository', 'parameters', 'tags', 'version', 'duration'): # # c = "<code>" + c + "</code>" if field in ('label', 'repository', 'version', 'parameters'): c = "<code>" + c + "</code>" record_list.append(c) table.append(record_list) t = make_table(table) ipy_table.apply_theme('basic') ipy_table.set_global_style(wrap=True) return HTML(t._repr_html_())
def _repr_html_(self): table_data = [['n_nodes',self.get_n_nodes(),"number of nodes recorded"], ['n_samples',self.n_samples,"total number of samples"], ['n_accepted',self.n_accepted,"number of samples accepted"], ['n_rejected',self.n_rejected,"number of samples rejected"], ['rejection_ratio',self.rejection_ratio,"n_rejected / n_samples"], ['last_accepted',self.last_accepted,"indicates if the last sample was accepted"], ] table = ipy_table.make_table(table_data) table = ipy_table.apply_theme('basic_left') table = ipy_table.set_global_style(float_format="%3.3f") return table._repr_html_()
def _repr_html_(self): table_data = [['n_nodes', self.get_n_nodes(), "number of nodes recorded"], ['n_samples', self.n_samples, "total number of samples"], ['n_accepted', self.n_accepted, "number of samples accepted"], ['n_rejected', self.n_rejected, "number of samples rejected"], ['rejection_ratio', self.rejection_ratio, "n_rejected / n_samples"], ['last_accepted', self.last_accepted, "indicates if the last sample was accepted"], ] table = ipy_table.make_table(table_data) table = ipy_table.apply_theme('basic_left') table = ipy_table.set_global_style(float_format="%3.3f") return table._repr_html_()
def show(headers, data_dict, header_names=None, display_table=True): data_cols = tuple() if header_names == None: header_names = headers for i in range(len(headers)): data_cols = data_cols + tuple([[data_dict[headers[i]]]]) table_data = np.concatenate(data_cols, axis=0).T ipy_table.make_table([header_names] + table_data.tolist()) ipy_table.apply_theme('basic') table_rendered = ipy_table.render() if display: display.display(table_rendered) return table_rendered
def _repr_html_(self): table_data = [['node_name',self.node_name,"name of the node"], ['last_method',self.last_method,"sampling method used to obtain the last sample"], ['n_samples',self.n_samples,"total number of samples"], ['n_accepted',self.n_accepted,"number of samples accepted"], ['n_rejected',self.n_rejected,"number of samples rejected"], ['rejection_ratio',self.rejection_ratio,"n_rejected / n_samples"], ['last_accepted',self.last_accepted,"indicates if the last sample was accepted"], ['sample_ratio',self.sample_ratio,"n_samples of the node / n_samples of the graph"], ['last_threshold',self.last_threshold,"threshold value (Metropolis Hastings) for the last sample"], ['last_random_number',self.last_random_number,"random number for the last sample"], ['last_seed',self.last_seed,"seed for the last sample"], ] for param in self.last_parameters.keys(): table_data += [ [param,self.last_parameters[param],"parameter of the last sampling method"] ] table = ipy_table.make_table(table_data) table = ipy_table.apply_theme('basic_left') table = ipy_table.set_global_style(float_format="%3.3f") return table._repr_html_()
def _repr_html_(self): table_data = [['node_name', self.node_name, "name of the node"], ['last_method', self.last_method, "sampling method used to obtain the last sample"], ['n_samples', self.n_samples, "total number of samples"], ['n_accepted', self.n_accepted, "number of samples accepted"], ['n_rejected', self.n_rejected, "number of samples rejected"], ['rejection_ratio', self.rejection_ratio, "n_rejected / n_samples"], ['last_accepted', self.last_accepted, "indicates if the last sample was accepted"], ['sample_ratio', self.sample_ratio, "n_samples of the node / n_samples of the graph"], ['last_threshold', self.last_threshold, "threshold value (Metropolis Hastings) for the last sample"], ['last_random_number', self.last_random_number, "random number for the last sample"], ['last_seed', self.last_seed, "seed for the last sample"], ] for param in self.last_parameters.keys(): table_data += [[param, self.last_parameters[param], "parameter of the last sampling method"]] table = ipy_table.make_table(table_data) table = ipy_table.apply_theme('basic_left') table = ipy_table.set_global_style(float_format="%3.3f") return table._repr_html_()
def conf_mat(y_true, y_pred, reverse=True): """ :param y_true: True labels (0 or 1) :param y_pred: Predicted probabilities (0 to 1) :return: HTML table (ipy_table) which will be displayed in Jupyter Needs `pip install ipy_table` Usage: >>> conf_mat(y_true, y_pred) """ from ipy_table import make_table, set_cell_style, apply_theme df = pd.DataFrame({"pred": y_pred, "true": y_true}) cm = (pd.pivot_table(df, index="true", columns="pred", aggfunc=len).fillna(0).astype(int)) classes = sorted(cm.index | cm.columns, reverse=reverse) cm = cm.reindex(classes, classes, fill_value=0) precs = pd.Series([cm.ix[c, c] / cm.ix[c, :].sum() for c in classes], index=classes) recall = pd.Series([cm.ix[c, c] / cm.ix[:, c].sum() for c in classes], index=classes) accuracy = sum(cm.ix[c, c] for c in classes) / cm.sum().sum() tot_true = cm.sum(axis=0) tot_pred = cm.sum(axis=1) table_data = [["Pred ->"] + classes + ["Total", "Recall"]] total = cm.sum().sum() for class_j, field_type_j in [(c, "class") for c in classes] + [ (None, "total"), (None, "precision"), ]: table_row = [] for class_i, field_type_i in ([(None, "name")] + [(c, "class") for c in classes] + [(None, "total"), (None, "recall")]): val = { ("name", "class"): class_j, ("name", "precision"): "Precision", ("name", "total"): "Total", ("class", "class"): cm.ix[class_i, class_j], ("precision", "class"): "{:.1%}".format(precs[class_i]), ("precision", "total"): "", ("precision", "recall"): "{:.1%}".format(accuracy), ("recall", "class"): "{:.1%}".format(recall[class_j]), ("recall", "total"): "", ("total", "class"): tot_true[class_j], ("class", "total"): tot_pred[class_i], ("total", "total"): total, }[field_type_i, field_type_j] table_row.append(val) table_data.append(table_row) tab = make_table(table_data) apply_theme("basic_both") num_classes = len(classes) set_cell_style(1, 1, thick_border="left, top") set_cell_style(1, num_classes, thick_border="top,right") set_cell_style(num_classes, 1, thick_border="left,bottom") set_cell_style(num_classes, num_classes, thick_border="bottom,right") for i in range(2, num_classes): set_cell_style(i, 1, thick_border="left") set_cell_style(i, num_classes, thick_border="right") set_cell_style(1, i, thick_border="top") set_cell_style(num_classes, i, thick_border="bottom") return tab
def setcompare(iter1, iter2): cntr1 = Counter(iter1) cntr2 = Counter(iter2) only1 = cntr1.keys() - cntr2.keys() only2 = cntr2.keys() - cntr1.keys() both = cntr1.keys() & cntr2.keys() cnt1 = sum(cntr1[key] for key in only1) cnt2 = sum(cntr2[key] for key in only2) cnt12a = sum(cntr1[key] for key in both) cnt12b = sum(cntr2[key] for key in both) distinct1 = len(only1) distinct2 = len(only2) distinct12 = len(both) cnt_perct = "{} ({:.0%})".format if hasattr(iter1, "name"): name1 = f"1 {iter1.name}" else: name1 = "1" if hasattr(iter2, "name"): name2 = f"2 {iter2.name}" else: name2 = "2" display_data = [ ["", f"Set {name1} only", "Intersect.", f"Set {name2} only"], [ "Count", cnt_perct(cnt1, cnt1 / (cnt1 + cnt12a)), "{} | {}".format(cnt12a, cnt12b), cnt_perct(cnt2, cnt2 / (cnt2 + cnt12b)), ], [ "Distinct count", cnt_perct(distinct1, distinct1 / (distinct1 + distinct12)), distinct12, cnt_perct(distinct2, distinct2 / (distinct2 + distinct12)), ], [ "Examples", format_tuples( pluck( 0, Counter({key: cntr1[key] for key in only1}).most_common(5)), cntr1, ), format_tuples( pluck( 0, Counter({key: cntr1[key] + cntr2[key] for key in both}).most_common(5), ), cntr1, cntr2, ), format_tuples( pluck( 0, Counter({key: cntr2[key] for key in only2}).most_common(5)), cntr2, ), ], ] make_table(display_data) table = apply_theme("basic_both") for x, y in product([0, 1, 2], [1, 2, 3]): set_cell_style(x, y, align="center") return table