Skip to content

Commit f7560e9

Browse files
committed
feat: update of the 1st plot
1 parent 1ed91c3 commit f7560e9

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

public/labelDist.png

-196 Bytes
Loading

public/plot.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/* eslint-disable no-console */
22
/* global Plotly */
3-
import {loadData, orderEntriesByValues, perc, chunk} from './utils.js'
3+
import {loadData, orderEntriesByValues, perc, chunk, groupBy} from './utils.js'
44

55
const labelDistributionPlot = data => {
6-
const orderedData = orderEntriesByValues(data, [
7-
'overall',
8-
'train',
9-
'test',
10-
'validation',
6+
const groups = groupBy(data, 'category')
7+
const orderedData = Object.entries(groups).map(entry => [
8+
entry[0],
9+
entry[1].length,
1110
])
12-
const xVals = orderedData.map(entry => entry[1].overall)
11+
orderedData.sort((a, b) => a[1] - b[1])
12+
const xVals = orderedData.map(entry => entry[1])
1313
const categoryDistPlot = {
1414
y: orderedData.map(entry => entry[0]),
1515
x: xVals,
@@ -37,7 +37,7 @@ const labelDistributionPlot = data => {
3737
type: 'log',
3838
automargin: true,
3939
tick0: 0,
40-
dtick: Math.log10(1), //log10(e**1), 0.30102999566
40+
dtick: Math.log10(1), //log10(2)
4141
},
4242
}
4343

@@ -104,7 +104,6 @@ const facettedPartitionPlot = data => {
104104
['overall', 'train', 'test', 'validation'],
105105
['desc', 'desc', 'desc', 'desc'],
106106
)
107-
console.log('orderd', orderedData)
108107
const chunks = chunk(orderedData, 9)
109108
const parentPlot = document.getElementById('plot2')
110109

@@ -261,10 +260,10 @@ const testedCategories = data => {
261260
}
262261

263262
const build = async () => {
264-
const [data] = await loadData()
263+
const [data, categoryPartitions] = await loadData()
265264
console.log(data)
266-
const entries = Object.entries(data)
267-
labelDistributionPlot(entries)
265+
const entries = Object.entries(categoryPartitions)
266+
labelDistributionPlot(data)
268267
tvtPartitionsPlot(entries)
269268
facettedPartitionPlot(entries)
270269
trainedCategories(entries)

public/utils.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const loadData = async () => {
33
try {
44
const data = await Promise.all([
55
// fetch('../src/categories.json').then(res => res.json(), console.error),
6-
// fetch('../src/labels.json').then(res => res.json(), console.error),
6+
fetch('../src/labels.json').then(res => res.json(), console.error),
77
fetch('../playground/categoryPartitions.json').then(
88
res => res.json(),
99
console.error,
@@ -53,4 +53,12 @@ const chunk = (arr, size) =>
5353
arr.slice(i * size, i * size + size),
5454
)
5555

56-
export {loadData, orderBy, orderEntriesByValues, perc, chunk}
56+
const groupBy = (arr, fn) =>
57+
arr
58+
.map(typeof fn === 'function' ? fn : val => val[fn])
59+
.reduce((acc, val, i) => {
60+
acc[val] = (acc[val] || []).concat(arr[i])
61+
return acc
62+
}, {})
63+
64+
export {loadData, orderBy, orderEntriesByValues, perc, chunk, groupBy}

0 commit comments

Comments
 (0)