Skip to content

Commit 550ebdc

Browse files
author
Benjamin Hoover
committed
Add histogram return information
1 parent 677c13d commit 550ebdc

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

backend/server/main.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def new_suggestions(
269269
order: SortOrder = "descending",
270270
k: int = 50,
271271
sort_by_abs: bool = True,
272+
histogram_bins:int = 100,
272273
):
273274
f"""Get the comparison between model m1 and m2 on the dataset. Rank the output according to a valid metric
274275
@@ -280,6 +281,7 @@ def new_suggestions(
280281
order (SortOrder, optional): If "ascending", sort in order of least to greatest. Defaults to "descending".
281282
k (int, optional): The number of interesting instances to return. Defaults to 50.
282283
sort_by_abs (bool): Sort by the absolute value. Defaults to True
284+
histogram_bins (int): Number of bins in the returned histogram of all values. Defaults to 100.
283285
284286
Returns:
285287
Object containing information to statically analyze two models.
@@ -289,9 +291,9 @@ def new_suggestions(
289291
ds1 = get_analysis_results(dataset, m1)
290292
ds2 = get_analysis_results(dataset, m2)
291293
compared_results = get_comparison_results(m1, m2, dataset)
294+
results = np.array(compared_results[metric])
292295

293296
if sort_by_abs:
294-
results = np.array(compared_results[metric])
295297
results_sign = np.sign(results)
296298
results_abs = np.abs(results)
297299

@@ -341,6 +343,8 @@ def proc_data_row(x1, x2):
341343
]
342344
]
343345

346+
histogram_values, bin_edges = np.histogram(results, bins=histogram_bins)
347+
344348
return {
345349
"request": {
346350
"m1": m1,
@@ -351,6 +355,10 @@ def proc_data_row(x1, x2):
351355
"k": k,
352356
},
353357
"result": result,
358+
"histogram": deepdict_to_json({
359+
"values": histogram_values,
360+
"bin_edges": bin_edges
361+
}, ndigits=4)
354362
}
355363

356364

environment.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ dependencies:
2626
- datasets==1.6.2
2727
- python-frontmatter==1.0.0
2828
- h5py==3.2.1
29-
- pandas==1.2.4
29+
- pandas==1.2.4
30+
- matplotlib>=3.4.2

0 commit comments

Comments
 (0)