Skip to content

Commit d96c51f

Browse files
authored
Merge pull request #51 from NGO-Algorithm-Audit/JFP_edits
Textual edits to tool and changes to notebook
2 parents 0c7ff99 + 617494f commit d96c51f

File tree

3 files changed

+81
-82
lines changed

3 files changed

+81
-82
lines changed

notebooks/CART_LawSchoolAdmissionBar.ipynb

Lines changed: 65 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@
333333
"\n",
334334
"[table]\n",
335335
"\n",
336-
"The CART method is used to generate the synthetic data. CART generally produces higher quality synthetic datasets, but might not run on datasets with categorical variables with 20+ categories. Use Gaussian Copula in those cases.\n",
336+
"The CART method is used to generate the synthetic data. CART generally produces high quality synthetic data, but might not work well on datasets with categorical variables with 20+ categories. Use Gaussian Copula in those cases.\n",
337337
"\n",
338338
"*The original paper can be found [here](https://files.eric.ed.gov/fulltext/ED469370.pdf)."
339339
]
@@ -557,6 +557,19 @@
557557
"### 1. Data types detection"
558558
]
559559
},
560+
{
561+
"cell_type": "markdown",
562+
"metadata": {},
563+
"source": [
564+
"**UI text #2**\n",
565+
"\n",
566+
"The following missing data is detected:\n",
567+
"\n",
568+
"[output]\n",
569+
"\n",
570+
"If the detected data types are incorrect, please change this locally in the source dataset before attaching it to the web app."
571+
]
572+
},
560573
{
561574
"cell_type": "code",
562575
"execution_count": 8,
@@ -578,49 +591,27 @@
578591
"print(\"Column Data Types:\", column_dtypes)"
579592
]
580593
},
581-
{
582-
"cell_type": "markdown",
583-
"metadata": {},
584-
"source": [
585-
"**UI text #2**\n",
586-
"\n",
587-
"If the detected data types are incorrect, please change this locally in the source dataset before attaching it to the app."
588-
]
589-
},
590594
{
591595
"cell_type": "markdown",
592596
"metadata": {},
593597
"source": [
594598
"### 2. Missing data handler"
595599
]
596600
},
597-
{
598-
"cell_type": "code",
599-
"execution_count": 9,
600-
"metadata": {},
601-
"outputs": [
602-
{
603-
"name": "stdout",
604-
"output_type": "stream",
605-
"text": [
606-
"Detected Missingness Type: {'sex': 'MAR', 'race1': 'MAR'}\n"
607-
]
608-
}
609-
],
610-
"source": [
611-
"# Detect missingness\n",
612-
"missingness_dict = md_handler.detect_missingness(df)\n",
613-
"print(\"Detected Missingness Type:\", missingness_dict)"
614-
]
615-
},
616601
{
617602
"cell_type": "markdown",
618603
"metadata": {},
619604
"source": [
620605
"**UI text #3**\n",
621606
"\n",
607+
"The following type of missing data is detected:\n",
608+
"\n",
609+
"[output]\n",
610+
"\n",
622611
"For Missing At Random (MAR) and Missing Not At Random (MNAR) data, we recommend to impute the missing data. For Missing Completely At Random (MCAR), we recommend to remove the missing data. See the info box for more information.\n",
623612
"\n",
613+
"In this demo, the missing data is imputed.\n",
614+
"\n",
624615
"_info box:_\n",
625616
"\n",
626617
"MCAR, MAR, and MNAR are terms used to describe different mechanisms of missing data:\n",
@@ -644,6 +635,25 @@
644635
"- Recommendation: impute missing data."
645636
]
646637
},
638+
{
639+
"cell_type": "code",
640+
"execution_count": 26,
641+
"metadata": {},
642+
"outputs": [
643+
{
644+
"name": "stdout",
645+
"output_type": "stream",
646+
"text": [
647+
"Detected Missingness Type: {'sex': 'MAR', 'race1': 'MAR'}\n"
648+
]
649+
}
650+
],
651+
"source": [
652+
"# Detect missingness\n",
653+
"missingness_dict = md_handler.detect_missingness(df)\n",
654+
"print(\"Detected Missingness Type:\", missingness_dict)"
655+
]
656+
},
647657
{
648658
"cell_type": "code",
649659
"execution_count": 10,
@@ -671,23 +681,7 @@
671681
"cell_type": "markdown",
672682
"metadata": {},
673683
"source": [
674-
"### 3. Pre-processing data"
675-
]
676-
},
677-
{
678-
"cell_type": "markdown",
679-
"metadata": {},
680-
"source": [
681-
"**UI text #4**\n",
682-
"\n",
683-
"In the next step the data is pre-processed. The dataframe is transformed into numerical space. The following steps are performed:\n",
684-
"\n",
685-
"1. Validates the input data;\n",
686-
"2. Stores the original column order;\n",
687-
"3. Encoding and scaling:\n",
688-
"* Encodes categorical columns using LabelEncoder or OneHotEncoder;\n",
689-
"* Scales numerical columns using StandardScaler;\n",
690-
"* Converts boolean columns to integers."
684+
"### [no section] Pre-processing data"
691685
]
692686
},
693687
{
@@ -797,7 +791,7 @@
797791
"cell_type": "markdown",
798792
"metadata": {},
799793
"source": [
800-
"### 4. Synthetic data generation: {CART/GC}"
794+
"### 3. Synthesizer: CART"
801795
]
802796
},
803797
{
@@ -914,18 +908,18 @@
914908
"cell_type": "markdown",
915909
"metadata": {},
916910
"source": [
917-
"**UI text #5**\n",
911+
"**UI text #4**\n",
918912
"\n",
919913
"{n_synth_data} synthetic data points are generated using CART. \n",
920914
"\n",
921-
"The CART (Classification and Regression Trees) method generates synthetic data by learning patterns from real data through a decision tree that splits data into homogeneous groups based on feature values. It predicts averages for numerical data and assigns the most common category for categorical data, using these predictions to create new synthetic points. Then, the the synthetic data back to the original format (postprocessing)."
915+
"The CART (Classification and Regression Trees) method generates synthetic data by learning patterns from real data through a decision tree that splits data into homogeneous groups based on feature values. It predicts averages for numerical data and assigns the most common category for categorical data, using these predictions to create new synthetic points."
922916
]
923917
},
924918
{
925919
"cell_type": "markdown",
926920
"metadata": {},
927921
"source": [
928-
"### 5. Generated synthetic data"
922+
"### [no section] Generated synthetic data"
929923
]
930924
},
931925
{
@@ -1031,7 +1025,7 @@
10311025
"cell_type": "markdown",
10321026
"metadata": {},
10331027
"source": [
1034-
"### 6. Evaluation of generated data"
1028+
"### 4. Evaluation of generated data"
10351029
]
10361030
},
10371031
{
@@ -1214,9 +1208,9 @@
12141208
"cell_type": "markdown",
12151209
"metadata": {},
12161210
"source": [
1217-
"**UI text #6**\n",
1211+
"**UI text #5**\n",
12181212
"\n",
1219-
"{n_synth_data} synthetic data points are generated using CART. The figures below display the differences in value frequency for each variable. The synthetic data is of high quality when all bars are of equal height."
1213+
"{n_synth_data} synthetic data points are generated using CART. The figures below display the value frequency for each variable. The synthetic data is of high quality when the frequencies are approximately the same."
12201214
]
12211215
},
12221216
{
@@ -1294,19 +1288,19 @@
12941288
"source": [
12951289
"**UI text #6**\n",
12961290
"\n",
1297-
"The report computes the following diagnostic results for each column:\n",
1298-
"- For numerical (or datetime) columns:\n",
1299-
" * *Missing value similarity:* Similarity in the proportion of missing values.\n",
1300-
" * *Range coverage:* Proportion of the real data's range covered by the synthetic data.\n",
1301-
" * *Boundary adherence:* Fraction of synthetic values within the real data's min/max.\n",
1302-
" * *Kolmogorov–Smirnov (KS) complement:* Uses the two-sample Kolmogorov–Smirnov test to compare the distributions of the two continuous columns using the empirical CDF. It returns 1 minus the KS Test D statistic, which indicates the maximum distance between the expected CDF and the observed CDF values.\n",
1303-
" * *Statistic similarity:* Similarity of mean, std, and median.\n",
1304-
"- For categorical (or boolean) columns:\n",
1305-
" * *Missing value similarity:* Similarity in the proportion of missing values.\n",
1306-
" * *Total variation (TV) complement:* Compute the complement of the total variation distance of two discrete columns.\n",
1307-
" * *Category coverage:* Proportion of real categories found in synthetic data.\n",
1308-
" * *Category adherence:* Fraction of synthetic values that are valid real categories.\n",
1291+
"For each column, diagnostic results are computed for the quality of the generated synthetic data. The computed metrics depend on the type of data. \n",
13091292
"\n",
1293+
"- For numerical (or datetime) columns the following metrics are computed:\n",
1294+
" * Missing value similarity *Infobox*: Compares whether the synthetic data has the same proportion of missing values as the real data for a given column;\n",
1295+
" * Range coverage *Infobox*: Measures whether a synthetic column covers the full range of values that are present in a real column;\n",
1296+
" * Boundary adherence *Infobox*: Measures whether a synthetic column respects the minimum and maximum values of the real column. It returns the percentage of synthetic rows that adhere to the real boundaries;\n",
1297+
" * Statistic similarity *Infobox*: Measures the similarity between real column and a synthetic column by comparing the mean, standard deviation and median;\n",
1298+
" * Kolmogorov–Smirnov (KS) complement *Infobox*: Computes the similarity of a real and synthetic numerical column in terms of the column shapes, i.e., the marginal distribution or 1D histogram of the column.\n",
1299+
"- For categorical (or boolean) columns the following metrics are computed:\n",
1300+
" * Missing value similarity *Infobox*: Compares whether the synthetic data has the same proportion of missing values as the real data for a given column;\n",
1301+
" * Category coverage *Infobox*: Measures whether a synthetic column covers all the possible categories that are present in a real column;\n",
1302+
" * Category adherence *Infobox*: Measures whether a synthetic column adheres to the same category values as the real data;\n",
1303+
" * Total variation (TV) complement *Infobox*: Computes the similarity of a real and synthetic categorical column in terms of the column shapes, i.e., the marginal distribution or 1D histogram of the column.\n",
13101304
"\n",
13111305
"💯 All values need to be close to 1.0 "
13121306
]
@@ -1793,7 +1787,7 @@
17931787
"cell_type": "markdown",
17941788
"metadata": {},
17951789
"source": [
1796-
"**UI text #7**\n",
1790+
"**UI text #9**\n",
17971791
"\n",
17981792
"Do you want to learn more about synthetic data?\n",
17991793
"- Source code of this tool:\n",
@@ -1805,6 +1799,11 @@
18051799
"- [CART: synthpop resources](https://synthpop.org.uk/resources.html)\n",
18061800
"- [Gaussian Copula - Synthetic Data Vault](https://docs.sdv.dev/sdv)\n"
18071801
]
1802+
},
1803+
{
1804+
"cell_type": "markdown",
1805+
"metadata": {},
1806+
"source": []
18081807
}
18091808
],
18101809
"metadata": {

src/locales/en.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
"syntheticData": {
6363
"demo": {
6464
"heading": "Information about demo dataset",
65-
"description": "A subset of the [Law School Admission Bar](https://www.kaggle.com/datasets/danofer/law-school-admissions-bar-passage)* dataset is used as a demo. Synthetic data will be generated for the following columns:\n \n  \n",
66-
"post.description": "The CART method is used to generate the synthetic data. CART generally produces higher quality synthetic datasets, but might not work well on datasets with categorical variables with 20+ categories. Use Gaussian Copula in those cases.\n \n  \n\n*The original paper can be found [here](https://files.eric.ed.gov/fulltext/ED469370.pdf)\n \n  \n",
65+
"description": "A subset of the [Law School Admission Bar](https://www.kaggle.com/datasets/danofer/law-school-admissions-bar-passage)* dataset is used as a demo. Synthetic data will be generated for the following variables:\n \n  \n",
66+
"post.description": "The CART method is used to generate the synthetic data. CART generally produces high quality synthetic data, but might not work well on datasets with categorical variables with 20+ categories. Use Gaussian Copula in those cases.\n \n  \n\n*The original paper can be found [here](https://files.eric.ed.gov/fulltext/ED469370.pdf)\n \n  \n",
6767
"data.column.Variable_name": "Variable name",
6868
"data.sex": "sex",
6969
"data.race1": "race1",
@@ -94,14 +94,14 @@
9494
"columnsCountError": "File may contain a maximum of 8 columns."
9595
},
9696
"fieldset": {
97-
"sourceDataset": "Source dataset",
97+
"sourceDataset": "Source data",
9898
"sdgMethod": {
9999
"title": "Method",
100100
"cart": "CART",
101101
"gc": "Gaussian Copula",
102-
"tooltip": "The CART method is used to generate the synthetic data.\n \n \n \nCART generally produces higher quality synthetic datasets, but might not work well on datasets with categorical variables with 20+ categories.\n \n \n \nUse Gaussian Copula in those cases."
102+
"tooltip": "By default, the CART method is used to generate synthetic data. CART generally produces higher quality synthetic data, but might not work well on datasets with categorical variables with 20+ categories. Use Gaussian Copula in those cases."
103103
},
104-
"samples": "Number of samples"
104+
"samples": "Number of synthetic datapoints"
105105
},
106106
"actions": {
107107
"tryItOut": "Try it out",
@@ -112,9 +112,9 @@
112112
},
113113
"demoCard": {
114114
"title": "Try it out!",
115-
"description": "Do you not have a dataset at hand? No worries use our demo dataset."
115+
"description": "No dataset at hand? Use our demo dataset."
116116
},
117-
"columnsInDatasetInfo": "If the detected data types are incorrect, please change this locally in the source dataset before attaching it to the app.",
117+
"columnsInDatasetInfo": "If the detected data types are incorrect, please change this locally in the source dataset before attaching it to the web app.",
118118
"univariateCharts": "Univariate distributions",
119119
"bivariateDistributionRealData": "Bivariate distribution",
120120
"univariateDistributionSyntheticData": "Univariate distribution",
@@ -133,7 +133,7 @@
133133
"outputDataTitle": "4. Generated synthetic data",
134134
"diagnosticsTitle": "Diagnostic Results",
135135
"correlationDifference": "Correlation difference: {{correlationDifference}}",
136-
"univariateText": "{{samples}} synthetic data points are generated using CART. The figures below display the differences in value frequency for each variable. The synthetic data is of high quality when all bars are of equal height.",
136+
"univariateText": "{{samples}} synthetic data points are generated using CART. The figures below display the value frequency for each variable. The synthetic data is of high quality when the frequencies are approximately the same.",
137137
"bivariateText": "The figures below display the differences in value frequency for a combination of variables. For comparing two categorical variables, bar charts are plotted. For comparing a numerical and a categorical variables, a so called [violin plot](https://en.wikipedia.org/wiki/Violin_plot) is shown. For comparing two numercial variables, a [LOESS plot](https://en.wikipedia.org/wiki/Local_regression) is created. For all plots holds: the synthetic data is of high quality when the shape of the distributions in the synthetic data equal the distributions in the real data.",
138138
"moreInfo": "  \n \n \n \nDo you want to learn more about synthetic data?\n \n \n \n- [python-synthpop on Github](https://github.com/NGO-Algorithm-Audit/python-synthpop)\n- [local-first web app on Github](https://github.com/NGO-Algorithm-Audit/local-first-web-tool/tree/main)\n- [Synthetic Data: what, why and how?](https://royalsociety.org/-/media/policy/projects/privacy-enhancing-technologies/Synthetic_Data_Survey-24.pdf)\n- [Knowledge Network Synthetic Data](https://online.rijksinnovatiecommunity.nl/groups/399-kennisnetwerk-synthetischedata/welcome) (for Dutch public organizations)\n- [Synthetic data portal of Dutch Executive Agency for Education](https://duo.nl/open_onderwijsdata/footer/synthetische-data.jsp) (DUO)\n- [CART: synthpop resources](https://synthpop.org.uk/resources.html)\n- [Gaussian Copula - Synthetic Data Vault](https://docs.sdv.dev/sdv)"
139139
},

src/locales/nl.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
"syntheticData": {
6262
"demo": {
6363
"heading": "Informatie over demodataset",
64-
"description": "Een subset van de [Law School Admission Bar](https://www.kaggle.com/datasets/danofer/law-school-admissions-bar-passage)* dataset wordt gebruikt als demo. Synthetische data worden gegenereerd voor de volgende kolommen:\n \n  \n\n",
65-
"post.description": "De CART-methode zal worden gebruikt om de verschillen in distributie en correlatie tussen de echte en synthetische gegevens te evalueren.\n \n  \n\n*Het oorspronkelijke artikel is [hier](https://files.eric.ed.gov/fulltext/ED469370.pdf) te vinden.",
64+
"description": "Een subset van de [Law School Admission Bar](https://www.kaggle.com/datasets/danofer/law-school-admissions-bar-passage)* dataset wordt gebruikt als demo. Synthetische data worden gegenereerd voor de volgende variablen:\n \n  \n\n",
65+
"post.description": "De CART-methode wordt gebruikt om synthetische gegevens te genereren.\n CART produceert doorgaan een goede kwaliteit synthetische data, maar werkt minder goed voor data met categorische data met meer dan 20 categorieën. Gebruik in dit geval Gaussian Copula. \n  \n\n*Het oorspronkelijke artikel is [hier](https://files.eric.ed.gov/fulltext/ED469370.pdf) te vinden.",
6666
"data.column.Variable_name": "Variabele name",
6767
"data.sex": "sex",
6868
"data.race1": "race1",
@@ -79,7 +79,7 @@
7979
"data.column.Values": "Waardes",
8080

8181
"data.column.Values.sex": "1 (man), 2 (vrouw)",
82-
"data.column.Values.race": "aziatisch, zwart, hispanic, wit, anders",
82+
"data.column.Values.race": "aziatisch, afrikaans, latino, westers, anders",
8383
"data.column.Values.ugpa": "1-4",
8484
"data.column.Values.bar": "geslaagd 1e keer, geslaagd 2e keer, gezakt, niet-afgestudeerd"
8585
},
@@ -93,26 +93,26 @@
9393
"columnsCountError": "File mag maximaal 8 kolommen bevatten."
9494
},
9595
"fieldset": {
96-
"sourceDataset": "Brondataset",
96+
"sourceDataset": "Brondata",
9797
"sdgMethod": {
9898
"title": "Methode",
9999
"cart": "CART",
100100
"gc": "Gaussian Copula",
101-
"tooltip": "De CART-methode wordt gebruikt om de synthetische gegevens te genereren.\n \n \n \nCART levert over het algemeen synthetische datasets van hogere kwaliteit op, maar werkt mogelijk niet goed bij datasets met categorische variabelen met meer dan 20 categorieën.\n \n \n \nGebruik in die gevallen de Gaussian Copula."
101+
"tooltip": "In principe wordt de CART-methode gebruikt om synthetische data te genereren. CART levert over het algemeen synthetische data van hoge kwaliteit, maar werkt mogelijk niet goed bij datasets met categorische variabelen met meer dan 20 categorieën. Gebruik in die gevallen de Gaussian Copula."
102102
},
103-
"samples": "Aantal samples"
103+
"samples": "Aantal synthetische datapunten"
104104
},
105105
"actions": {
106106
"tryItOut": "Uitproberen",
107107
"runGeneration": "Start synthetische data generatie",
108108
"analyzing": "Analyseren...",
109109
"initializing": "Initialiseren..."
110110
},
111-
"univariateText": "{{samples}} synthetic data punten zijn gegeneert met CART. De grafieken tonen de verschillen in waarde frequentie voor elle variabele. De synthetische data is van hoge kwaliteit als alle balken van gelijke hoogte zijn."
111+
"univariateText": "{{samples}} synthetic datapunten via de CART-methode gegeneerd. De grafieken tonen de frequentie waarmee een variabele een bepaalde waarde aanneemt. De synthetische data is van hoge kwaliteit als de frequenties ongeveer gelijke zijn."
112112
},
113113
"demoCard": {
114114
"title": "Probeer het uit!",
115-
"description": "Heeft u geen dataset bij de hand? Geen zorgen, gebruik onze demodataset."
115+
"description": "Geen dataset bij de hand? Gebruik onze demodata."
116116
},
117117
"columnsInDatasetInfo": "Als de gedetecteerd data types niet correct zijn, pas dit dan lokaal aan in de dataset voordat u deze opnieuw aan de app koppelt.",
118118
"univariateCharts": "Univariate distributies",

0 commit comments

Comments
 (0)