Skip to content

Commit 885628c

Browse files
authored
Merge pull request #91 from NGO-Algorithm-Audit/feature/feature-7-finetuning
Feature/feature 7 finetuning
2 parents 0392aa9 + ff42a84 commit 885628c

File tree

9 files changed

+64
-14
lines changed

9 files changed

+64
-14
lines changed

src/assets/bias-detection-python-code.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ from js import targetColumn
2727
from js import dataType
2828
from js import higherIsBetter
2929
from js import isDemo
30+
from js import dataTypeText
3031
3132
def t_test_on_cluster(test_df, bias_score, cluster_label):
3233
@@ -64,6 +65,7 @@ def t_test_on_cluster(test_df, bias_score, cluster_label):
6465
6566
# if significant differences were found, print the variables with their differences
6667
for var, res in t_test_results.items():
68+
6769
if res['p_val'] < 0.05:
6870
direction = res['direction']
6971
if direction == "higher":
@@ -139,7 +141,19 @@ def chi2_test_on_cluster(decoded_X_test, bias_score, cluster_label):
139141
print(f"91mNo statistically significant differences in means found.")
140142
141143
# if significant differences were found, print the variables with their differences
144+
current_column = ""
145+
142146
for var, res in chi2_results.items():
147+
if (current_column != var[0]):
148+
current_column = var[0]
149+
if res['p_val'] < 0.05:
150+
comparisons.append({
151+
'key': 'biasAnalysis.biasedCluster.differenceCategorical.feature',
152+
'params': {
153+
'feature': var[0],
154+
}
155+
})
156+
143157
if res['p_val'] < 0.05:
144158
direction = res['direction']
145159
if direction == "higher":
@@ -318,7 +332,7 @@ def run():
318332
'iterations': localIterations,
319333
'minClusterSize': localClusterSize,
320334
'performanceMetric': bias_score,
321-
'dataType': localDataType
335+
'dataType': dataTypeText
322336
}
323337
}))
324338
setResult(json.dumps({
@@ -597,7 +611,8 @@ def run():
597611
setResult(json.dumps({
598612
'type': 'accordion',
599613
'titleKey': 'biasAnalysis.biasedCluster.accordionTitle',
600-
'comparisons': comparisons
614+
'comparisons': comparisons,
615+
'className': 'biasAnalysis-biasedClusterAccordion'
601616
}))
602617
603618

src/components/BiasSettings.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ export default function BiasSettings({
162162
form.getValues().whichPerformanceMetricValueIsBetter ===
163163
'higher',
164164
isDemo: true,
165+
dataTypeText: t(`biasSettings.dataType.categorical`),
165166
}
166167
);
167168
};
@@ -224,6 +225,9 @@ export default function BiasSettings({
224225
higherIsBetter:
225226
formData.whichPerformanceMetricValueIsBetter === 'higher',
226227
isDemo: false,
228+
dataTypeText: t(
229+
`biasSettings.dataType.${formData.selectedDataType}`
230+
),
227231
});
228232
};
229233

src/components/bias-detection-interfaces/BiasDetectionParameters.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export interface BiasDetectionParameters {
55
dataType: string;
66
higherIsBetter: boolean;
77
isDemo: boolean;
8+
dataTypeText: string;
89
}

src/components/componentMapper.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export default function ComponentMapper({
108108
key={index}
109109
title={t(resultItem.titleKey || '')}
110110
content={content}
111+
className={resultItem?.className ?? ''}
111112
/>
112113
);
113114
}

src/components/ui/accordion.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ AccordionContent.displayName = AccordionPrimitive.Content.displayName;
5959
export interface AccordionProps {
6060
title: string;
6161
content: React.ReactNode;
62+
className?: string;
6263
}
6364

6465
export const Accordion = (props: AccordionProps) => (
6566
<>
66-
<div className="hideonprint">
67+
<div className={`hideonprint ${props.className ?? ''}`}>
6768
<AccordionPrimitive.Root type="single" collapsible>
6869
<AccordionItem value="item-1">
6970
<AccordionTrigger>{props.title}</AccordionTrigger>
@@ -79,7 +80,7 @@ export const Accordion = (props: AccordionProps) => (
7980
</AccordionItem>
8081
</AccordionPrimitive.Root>
8182
</div>
82-
<div className="hidden showonprint">
83+
<div className={`hidden showonprint ${props.className ?? ''}`}>
8384
{typeof props.content === 'string' ? (
8485
<MarkdownWithTooltips className="text-gray-800 markdown">
8586
{props.content}

src/index.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@
4343
}
4444
}
4545

46+
.biasAnalysis-biasedClusterAccordion {
47+
.content-list,
48+
.markdown {
49+
ul li {
50+
line-height: 1;
51+
}
52+
53+
ul {
54+
@apply mb-0;
55+
}
56+
span:has(> ul) {
57+
@apply block;
58+
}
59+
}
60+
}
61+
4662
.tooltip-content {
4763
@apply p-4;
4864
}

src/locales/en.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export const en = {
2121
'Loading core packages. On average this takes 10-15 seconds.',
2222
installingPackages: 'Installing additional packages...',
2323
biasSettings: {
24+
dataType: {
25+
numeric: 'Numeric',
26+
categorical: 'Categorical',
27+
},
2428
exportToPDF: 'Download bias analysis report as pdf',
2529
exportToJSON: 'Export clusters as json',
2630
form: {
@@ -263,8 +267,9 @@ we recommend to impute the missing data. For {tooltip:syntheticData.missingDataM
263267
264268
A two-sided t-test is performed to accept or reject <i class="font-serif">H</i><sub>0</sub>:.
265269
266-
p_value : {{p_val}}
270+
{tooltip:biasAnalysis.p_valueTooltip}p_value{/tooltip} : {{p_val}}
267271
`,
272+
p_valueTooltip: `p_value tooltip`,
268273
dataSetPreview: {
269274
heading: '1. Preview of data',
270275
},
@@ -329,10 +334,9 @@ In this example, we analyze which group is most adversely affected by the risk p
329334
`,
330335
},
331336
differenceCategorical: {
332-
deviatingMoreOften: `**{{feature}}: {{value}}** in the most deviating cluster occurs **more** often than in the rest of the dataset.
333-
`,
334-
deviatingLessOften: `**{{feature}}: {{value}}** in the most deviating cluster occurs **less** often than in the rest of the dataset.
335-
`,
337+
feature: '- {{feature}}',
338+
deviatingMoreOften: ` - **{{value}}** in the most deviating cluster occurs **more** often than in the rest of the dataset.`,
339+
deviatingLessOften: ` - **{{value}}** in the most deviating cluster occurs **less** often than in the rest of the dataset.`,
336340
},
337341
},
338342
nodifference: {
@@ -341,8 +345,7 @@ In this example, we analyze which group is most adversely affected by the risk p
341345
},
342346
distribution: {
343347
mainHeading: '6. Cluster differences wrt. features',
344-
heading:
345-
'"{{variable}}" distribution per cluster:',
348+
heading: '"{{variable}}" distribution per cluster:',
346349
},
347350
splittingDataset: {
348351
heading: '3. Splitting dataset',

src/locales/nl.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export const nl = {
1818
loadingPackages: 'Laden van packages. Dit duurt gemiddeld 10-15 seconden.',
1919
installingPackages: 'Aanvullende packages laden',
2020
biasSettings: {
21+
dataType: {
22+
numeric: 'Numeriek',
23+
categorical: 'Categorisch',
24+
},
2125
exportToPDF: 'Download bias analyse rapport als pdf',
2226
exportToJSON: 'Export clusters als json',
2327

@@ -191,6 +195,9 @@ export const nl = {
191195
'&nbsp;&nbsp;\n \n \n \nWil je meer weten over synthetische data?\n \n \n \n- [python-synthpop op Github](https://github.com/NGO-Algorithm-Audit/python-synthpop)\n- [local-first web app op Github](https://github.com/NGO-Algorithm-Audit/local-first-web-tool/tree/main)\n- [Synthetische Data: wat, waarom en hoe?](https://royalsociety.org/-/media/policy/projects/privacy-enhancing-technologies/Synthetic_Data_Survey-24.pdf)\n- [Kennis Netwerk Synthetische Data](https://online.rijksinnovatiecommunity.nl/groups/399-kennisnetwerk-synthetischedata/welcome) (for Dutch public organizations)\n- [Synthetische data portaal van DUO](https://duo.nl/open_onderwijsdata/footer/synthetische-data.jsp)\n- [CART: synthpop resources](https://synthpop.org.uk/resources.html)\n- [Gaussian Copula - Synthetic Data Vault](https://docs.sdv.dev/sdv)',
192196
},
193197
biasAnalysis: {
198+
dataSetPreview: {
199+
heading: '1. Preview van de data',
200+
},
194201
demo: {
195202
heading: 'Informatie over de demodataset',
196203
description: `Als voorbeeld wordt de [COMPAS (Correctional Offender Management Profiling for Alternative Sanctions) dataset](https://github.com/propublica/compas-analysis/tree/master) gebruikt. De dataset bevat kenmerken van criminele verdachten en hun risico op recidive, zoals voorspeld door het COMPAS-algoritme. De dataset bevat demografische gegevens zoals leeftijd, geslacht en ras, evenals strafblad, details over de aanklacht en het voorspelde risicolabel. Deze dataset wordt gebruikt als benchmark voor onderzoek naar eerlijke algoritmes. Een beschrijving van alle variabelen is te vinden in onderstaande tabel.
@@ -219,8 +226,9 @@ In dit voorbeeld analyseren welke groepen het COMPAS risicotaxatie-algoritme afw
219226
220227
Er wordt een tweezijdige t-toets uitgevoerd om <i class="font-serif">H</i><sub>0</sub> te aanvaarden of te verwerpen.
221228
222-
p-waarde : {{p_val}}
229+
{tooltip:biasAnalysis.p_valueTooltip}p-waarde{/tooltip} : {{p_val}}
223230
`,
231+
p_valueTooltip: `p-waarde tooltip`,
224232
parameters: {
225233
heading: '2. Geselecteerde parameters',
226234
iterations: 'Aantal iteraties: {{value}}',
@@ -236,8 +244,7 @@ p-waarde : {{p_val}}
236244
`,
237245
},
238246
distribution: {
239-
mainHeading:
240-
'6. Verschil clusters mbt. eigenschappen',
247+
mainHeading: '6. Verschil clusters mbt. eigenschappen',
241248
heading: '"{{variable}}" verdeling per cluster:',
242249
},
243250
splittingDataset: {

src/routes/BiasDetection.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export default function BiasDetection() {
8181
dataType: 'numeric',
8282
higherIsBetter: false,
8383
isDemo: false,
84+
dataTypeText: t(`biasSettings.dataType.numeric`),
8485
});
8586
const onFileLoad: (
8687
data: Record<string, string>[],
@@ -127,6 +128,7 @@ export default function BiasDetection() {
127128
dataType: params.dataType,
128129
higherIsBetter: params.higherIsBetter,
129130
isDemo: params.isDemo,
131+
dataTypeText: params.dataTypeText,
130132
},
131133
},
132134
});

0 commit comments

Comments
 (0)