egrace479 commited on
Commit
5260e84
·
1 Parent(s): 31d67c3

v3.3 EDA update (#3)

Browse files

- Need to track pre-webdataset catalog with LFS. (8dca1b6045337337112546548a552e44a0369131)
- Update data files, including pre-webdataset catalog, this is v3.3. (91beb3aab41c0f7af2ddf8459508b06e9231a4ed)
- Updated EDA in notebooks for v3.3, also added analysis of predicted entries prior to webdataset creation, shows 27K more images expectd. (6b5820466dacab211eafad859fb1ba385cc996ae)
- Added explanation of new files. (67e2a4af8580f9d2ac3f1b7a9ea7a0c74cb0ad9b)
- Added count of unique 7-tuples and genus-species pairs. (e00f09d636815a1caaab72cf72cf23482abdd994)

.gitattributes CHANGED
@@ -53,7 +53,9 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
 
56
  data/v1-dev-names.csv filter=lfs diff=lfs merge=lfs -text
57
  notebooks/BioCLIP_taxa_viz_bySource.ipynb filter=lfs diff=lfs merge=lfs -text
58
  statistics.csv filter=lfs diff=lfs merge=lfs -text
59
  data/catalog*.csv filter=lfs diff=lfs merge=lfs -text
 
 
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
56
+ # Large notebooks and data
57
  data/v1-dev-names.csv filter=lfs diff=lfs merge=lfs -text
58
  notebooks/BioCLIP_taxa_viz_bySource.ipynb filter=lfs diff=lfs merge=lfs -text
59
  statistics.csv filter=lfs diff=lfs merge=lfs -text
60
  data/catalog*.csv filter=lfs diff=lfs merge=lfs -text
61
+ data/predicted-catalog.csv filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -13,6 +13,7 @@ The `data` folder contains
13
  - `catalog.csv`: the metadata and identifiers for all images in the dataset. This includes original data source, unique identifier within TreeOfLife10M, and the associated taxa information for the image. This is the file that will be updated, while preserving the `catalog-v1-dev.csv` file for ease of comparison.
14
  - `stats_avg_std_byClass.csv`: average and standard distribution of images given by class in `catalog.csv`. This is for both all
15
  images, and images that have labels.
 
16
 
17
  - `catalog-v1-dev.csv`: the metadata and identifiers for all images in the dataset. This includes original data source, unique identifier within TreeOfLife10M, and the associated taxa information for the image. This file will be maintained for v1 reference, and as such will not be updated.
18
  - `taxa_counts.csv`: count of distinct lower taxa within each higher taxon from `kingdom` down to
@@ -26,6 +27,8 @@ images, and images that have labels.
26
  The `notebooks` folder contains
27
  - `ToL_catalog_EDA.ipynb`: more full EDA of TreeOfLife10M dataset using `catalog.csv`. To be updated as `catalog.csv` is updated, i.e., as the dataset is updated.
28
  - `ToL_catalog_EDA.py`: py file paired to `ToL_catalog_EDA.ipynb` to facilitate diff checking in case of cell text changes in notebook.
 
 
29
 
30
  - `BioCLIP_data_viz.ipynb`: notebook with quick basic stats for `catalog-v1-dev.csv`, generates `taxa_counts.csv`.
31
  - `BioCLIP_taxa_viz_bySource.ipynb`: generates data visualizations, in particular, the generation of visualizations in `visuals` folder and some histograms. The treemaps produced in the notebook are interactive.
@@ -33,7 +36,7 @@ The `notebooks` folder contains
33
  direction of standardization efforts. Maintained for v1 reference, should not be updated.
34
  - `missing_taxa_testGen.ipynb`: generates `tol_hierarchy_test.csv` to test [`check_taxa` script](https://github.com/Imageomics/open_clip/blob/main/scripts/evobio10m/check_taxa.py). Also observes species labeled as `(unidentified)` in EOL data.
35
 
36
- **Note:** run `pip install -r requirements.txt` before starting the visualization notebooks.
37
 
38
  ### Visuals
39
 
 
13
  - `catalog.csv`: the metadata and identifiers for all images in the dataset. This includes original data source, unique identifier within TreeOfLife10M, and the associated taxa information for the image. This is the file that will be updated, while preserving the `catalog-v1-dev.csv` file for ease of comparison.
14
  - `stats_avg_std_byClass.csv`: average and standard distribution of images given by class in `catalog.csv`. This is for both all
15
  images, and images that have labels.
16
+ - `predicted-catalog.csv`: the metadata and identifiers for all entries expected in the dataset, prior to webdataset creation. This includes original data source, unique identifier within TreeOfLife10M, and the associated taxa information. In version 3.3 (first time it was generated), it showed 27K more entries than in the webdataset and they all had full taxonomic rank filled.
17
 
18
  - `catalog-v1-dev.csv`: the metadata and identifiers for all images in the dataset. This includes original data source, unique identifier within TreeOfLife10M, and the associated taxa information for the image. This file will be maintained for v1 reference, and as such will not be updated.
19
  - `taxa_counts.csv`: count of distinct lower taxa within each higher taxon from `kingdom` down to
 
27
  The `notebooks` folder contains
28
  - `ToL_catalog_EDA.ipynb`: more full EDA of TreeOfLife10M dataset using `catalog.csv`. To be updated as `catalog.csv` is updated, i.e., as the dataset is updated.
29
  - `ToL_catalog_EDA.py`: py file paired to `ToL_catalog_EDA.ipynb` to facilitate diff checking in case of cell text changes in notebook.
30
+ - `ToL_predicted-catalog_EDA.ipynb`: more full EDA of TreeOfLife10M dataset using `predicted-catalog.csv`. To be updated as `predicted-catalog.csv` is updated, i.e., as the dataset is updated.
31
+ - `ToL_predicted-catalog_EDA.py`: py file paired to `ToL_predicted-catalog_EDA.ipynb` to facilitate diff checking in case of cell text changes in notebook.
32
 
33
  - `BioCLIP_data_viz.ipynb`: notebook with quick basic stats for `catalog-v1-dev.csv`, generates `taxa_counts.csv`.
34
  - `BioCLIP_taxa_viz_bySource.ipynb`: generates data visualizations, in particular, the generation of visualizations in `visuals` folder and some histograms. The treemaps produced in the notebook are interactive.
 
36
  direction of standardization efforts. Maintained for v1 reference, should not be updated.
37
  - `missing_taxa_testGen.ipynb`: generates `tol_hierarchy_test.csv` to test [`check_taxa` script](https://github.com/Imageomics/open_clip/blob/main/scripts/evobio10m/check_taxa.py). Also observes species labeled as `(unidentified)` in EOL data.
38
 
39
+ **Note:** run `pip install -r requirements.txt` before starting the visualization notebooks. EDA notebooks only require `pandas` and `seaborn`.
40
 
41
  ### Visuals
42
 
data/catalog.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:315576dd390920972ad48accbef002b5f19ca6838a6035cd1f32f09e3ee6d411
3
- size 2018327986
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef5edf6a6e6048c98e74787cc143981095efaa27ba0aa4cebbac8116b24c9735
3
+ size 2024176607
data/missing_taxa_output.txt CHANGED
@@ -70,3 +70,27 @@ Output of taxa check for catalog.csv v3.2 (taxa check now also removes duplicate
70
  [2023-10-26 13:44:14,425] [WARNING] [root] There are 149057 samples for which the species column may have genus and species.
71
 
72
  ------------------------------------------------------------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  [2023-10-26 13:44:14,425] [WARNING] [root] There are 149057 samples for which the species column may have genus and species.
71
 
72
  ------------------------------------------------------------------------------------------------------
73
+
74
+ Output of taxa check for catalog.csv v3.3 (from pr3):
75
+
76
+ [2023-10-30 17:31:38,357] [WARNING] [root] There are 12 kingdoms instead of 3.
77
+ [2023-10-30 17:31:39,420] [WARNING] [root] 39574 entries are missing rank kingdom, but have genus label.
78
+ [2023-10-30 17:31:39,681] [WARNING] [root] 38324 entries are missing rank phylum, but have genus label.
79
+ [2023-10-30 17:31:39,942] [WARNING] [root] 44828 entries are missing rank class, but have genus label.
80
+ [2023-10-30 17:31:40,199] [WARNING] [root] 42771 entries are missing rank order, but have genus label.
81
+ [2023-10-30 17:31:40,456] [WARNING] [root] 40131 entries are missing rank family, but have genus label.
82
+ [2023-10-30 17:31:40,733] [WARNING] [root] 232 entries are missing rank kingdom, but have family label.
83
+ [2023-10-30 17:31:40,759] [WARNING] [root] 223 entries are missing rank phylum, but have family label.
84
+ [2023-10-30 17:31:40,785] [WARNING] [root] 493 entries are missing rank class, but have family label.
85
+ [2023-10-30 17:31:40,812] [WARNING] [root] 345 entries are missing rank order, but have family label.
86
+ [2023-10-30 17:31:40,853] [WARNING] [root] 170 entries are missing rank kingdom, but have order label.
87
+ [2023-10-30 17:31:40,854] [WARNING] [root] 105 entries are missing rank phylum, but have order label.
88
+ [2023-10-30 17:31:40,855] [WARNING] [root] 1263 entries are missing rank class, but have order label.
89
+ [2023-10-30 17:31:40,893] [WARNING] [root] 41 entries have kingdom and species labels but no genus.
90
+ [2023-10-30 17:31:40,897] [WARNING] [root] 41 entries have phylum and species labels but no genus.
91
+ [2023-10-30 17:31:40,901] [WARNING] [root] 41 entries have class and species labels but no genus.
92
+ [2023-10-30 17:31:40,905] [WARNING] [root] 41 entries have order and species labels but no genus.
93
+ [2023-10-30 17:31:40,908] [WARNING] [root] 41 entries have family and species labels but no genus.
94
+ [2023-10-30 17:31:42,311] [WARNING] [root] There are 137661 samples with species label longer than one word.
95
+
96
+ ------------------------------------------------------------------------------------------------------
data/predicted-catalog.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e17a9325927e2dff21bc30bb8b3151a300fd456e4f725a626692e76fca6a0f2b
3
+ size 1847398611
data/stats_avg_std_byClass.csv CHANGED
@@ -1,9 +1,9 @@
1
  class,average_all_imgs,standard_deviation,avg_labeled,std_dev_labeled
2
- kingdom,1490931.5714285714,1221.0370884737988,1383385.142857143,1176.1739424324717
3
- phylum,115961.34444444445,340.53097428052627,107705.3111111111,328.1848733733947
4
- class,36748.31338028169,191.69849603030715,34047.58450704225,184.5198756422794
5
- order,7841.1126972201355,88.55005757886403,7262.970698722765,85.22306435890911
6
- family,1339.3892453798767,36.59766721226746,1236.6025410677619,35.165359959308844
7
- genus,141.30713405635214,11.887267728807664,120.2536794075037,10.966023864988792
8
- species,63.3115005702361,7.9568524285823035,52.917740409114074,7.274458083535438
9
- common,23.458496762142808,4.8433972335688935,22.625316649171822,4.756607682915612
 
1
  class,average_all_imgs,standard_deviation,avg_labeled,std_dev_labeled
2
+ kingdom,869710.0833333334,932.582480713279,817063.9166666666,903.9158791982065
3
+ phylum,96634.45370370371,310.86082690442635,90799.6574074074,301.32981499912586
4
+ class,30076.42939481268,173.4255730704462,28203.440922190202,167.93880112168898
5
+ order,6980.9505016722405,83.55208256933061,6542.110367892977,80.88331328458904
6
+ family,1309.8043423694778,36.19121913350637,1223.4554467871485,34.977927994481725
7
+ genus,141.30713405635214,11.887267728807664,120.25013201186076,10.96586211895174
8
+ species,63.770697250957795,7.9856557182837395,53.29990773385801,7.300678580368952
9
+ common,23.511079121780227,4.848822446922575,22.675425435573036,4.761872051575203
notebooks/ToL_catalog_EDA.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
notebooks/ToL_catalog_EDA.py CHANGED
@@ -39,22 +39,29 @@ df = df.loc[df.split != 'train_small']
39
  df.info(show_counts = True)
40
 
41
  # %% [markdown]
42
- # Original version had 10,436,521 entries; we expected loss of about 84K from the genera with label "unknown", but there's still another ~300K missing for this 10,065,845. Likely due to dropping subspecies, which will now be integrated back in under their species for the next round.
43
  #
44
- # Labeling definitely has far better coverage from original, and even improves over the last version (of course `common` is completely filled, but we also gained almost 50K more taxa labels across the board).
 
 
45
 
46
  # %%
47
  df.nunique()
48
 
49
  # %% [markdown]
50
- # There are 503,595 unique EOL page IDs, suggesting 503,595 unique classes among the 6,250,689 images pulled from EOL (and maintained here). Presumably this would represent the number of species or other lowest rank taxa covered by EOL.
 
 
51
 
52
  # %% [markdown]
53
- # Notice that we have 7 unique kingdoms, which we're sticking with.
54
 
55
  # %%
56
  df['kingdom'].value_counts()
57
 
 
 
 
58
  # %% [markdown]
59
  # `Metazoa` and `Archaeplastida` have been replaced by `Animalia` and `Plantae`, setting them as the dominant kingdoms represented (which we'd expect).
60
  #
@@ -72,39 +79,61 @@ df_all_taxa = df.dropna(subset = taxa)
72
  df_all_taxa[taxa].info(show_counts = True)
73
 
74
  # %% [markdown]
75
- # We have 8,320,837 images with full taxonomic labels.
76
  #
77
- # Notice that we still have gaps in the taxonomic hierarchy (both higher and lower values), as this is less than the number of species labels in the dataset and species had the least non-null values.
78
  #
79
- # We did hit 8M+ entries with full taxonomic labels, so that's really good, especially considering 1,043,863 of the BIOSCAN sourced images don't have species labels.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  # %% [markdown]
82
  # More detail on these missing values from [`check_taxa` script](https://github.com/Imageomics/open_clip/blob/main/scripts/evobio10m/check_taxa.py) are displayed below. Note: full record of taxa check output is in `data/missing_taxa_output.txt`.
83
  #
84
  # ```
85
- # [2023-10-26 13:44:09,780] [WARNING] [root] There are 7 kingdoms instead of 3.
86
- # [2023-10-26 13:44:11,325] [WARNING] [root] 160824 entries are missing rank kingdom, but have genus label.
87
- # [2023-10-26 13:44:11,613] [WARNING] [root] 151405 entries are missing rank phylum, but have genus label.
88
- # [2023-10-26 13:44:11,910] [WARNING] [root] 161871 entries are missing rank class, but have genus label.
89
- # [2023-10-26 13:44:12,199] [WARNING] [root] 156405 entries are missing rank order, but have genus label.
90
- # [2023-10-26 13:44:12,483] [WARNING] [root] 153279 entries are missing rank family, but have genus label.
91
- # [2023-10-26 13:44:12,782] [WARNING] [root] 315 entries are missing rank kingdom, but have family label.
92
- # [2023-10-26 13:44:12,809] [WARNING] [root] 289 entries are missing rank phylum, but have family label.
93
- # [2023-10-26 13:44:12,837] [WARNING] [root] 792 entries are missing rank class, but have family label.
94
- # [2023-10-26 13:44:12,865] [WARNING] [root] 414 entries are missing rank order, but have family label.
95
- # [2023-10-26 13:44:12,905] [WARNING] [root] 170 entries are missing rank kingdom, but have order label.
96
- # [2023-10-26 13:44:12,906] [WARNING] [root] 105 entries are missing rank phylum, but have order label.
97
- # [2023-10-26 13:44:12,908] [WARNING] [root] 1263 entries are missing rank class, but have order label.
98
- # [2023-10-26 13:44:12,949] [WARNING] [root] 41 entries have kingdom and species labels but no genus.
99
- # [2023-10-26 13:44:12,953] [WARNING] [root] 41 entries have phylum and species labels but no genus.
100
- # [2023-10-26 13:44:12,957] [WARNING] [root] 41 entries have class and species labels but no genus.
101
- # [2023-10-26 13:44:12,961] [WARNING] [root] 41 entries have order and species labels but no genus.
102
- # [2023-10-26 13:44:12,965] [WARNING] [root] 41 entries have family and species labels but no genus.
103
- # [2023-10-26 13:44:14,425] [WARNING] [root] There are 149057 samples for which the species column may have genus and species.
104
  # ```
105
 
106
  # %% [markdown]
107
- # Can we get some more information on those 41 entries that are still missing genus?
108
 
109
  # %%
110
  missing_genus = df.dropna(subset = ['kingdom', 'phylum', 'class', 'order', 'family', 'species'])
@@ -120,7 +149,7 @@ for taxon in taxa:
120
  print(taxon, ": ", missing_genus[taxon].unique())
121
 
122
  # %% [markdown]
123
- # "celebensis" is new, but next iteration should resolve these.
124
 
125
  # %% [markdown]
126
  # Let's add a column indicating the original data source so we can also get some stats by datasource.
@@ -138,7 +167,7 @@ missing_genus = missing_genus.loc[missing_genus.genus.isna()]
138
  missing_genus.data_source.unique()
139
 
140
  # %% [markdown]
141
- # Missing genus with all other taxa occurs only in EOL now, so should get fixed.
142
 
143
  # %% [markdown]
144
  # First, check their unique class values (`common`).
@@ -155,9 +184,9 @@ df.loc[df['data_source'] == 'BIOSCAN', 'common'].nunique()
155
  # %% [markdown]
156
  # iNat's number of unique values in `common` is still up by 6 from the original --- probably pulled from ITIS instead and that has more listed?
157
  #
158
- # EOL's went back up a bit, though still about 70-80K less than the original version.
159
  #
160
- # BIOSCAN's counts went down even more...
161
 
162
  # %% [markdown]
163
  # Make `df_taxa` with just taxa columns (+ `common` & `data_source`) so it's smaller to process faster.
@@ -228,6 +257,8 @@ bioscan_df.nunique()
228
 
229
  # %% [markdown]
230
  # We have half as many unique species and 3,000 less unique common names as in the original. Can this be accounted for by the adjustment in genus?
 
 
231
 
232
  # %%
233
  bioscan_df['kingdom'].value_counts()
@@ -320,7 +351,7 @@ bioscan_long_species = bioscan_species_len_df.loc[bioscan_species_len_df["len_sp
320
  bioscan_long_species.info(show_counts = True)
321
 
322
  # %% [markdown]
323
- # Not all species indicated have length greater than 1 now, though this number has actually gone up by 140 since the last iteration.
324
 
325
  # %%
326
  bioscan_species_len_df.len_species.value_counts()
@@ -352,13 +383,16 @@ eol_df.info(show_counts = True)
352
  # %%
353
  eol_df.nunique()
354
 
 
 
 
355
  # %%
356
  eol_df.loc[eol_df.species.isna()].nunique()
357
 
358
  # %% [markdown]
359
- # There are 503,595 unique page IDs from EOL in this dataset, which clearly represent varying levels of taxa.
360
  #
361
- # Unique species + unique common where species is null (39,233) does not reach this number. But we have added SO many more phyla through family!
362
 
363
  # %%
364
  eol_df['kingdom'].value_counts()
@@ -366,7 +400,7 @@ eol_df['kingdom'].value_counts()
366
  # %% [markdown]
367
  # We have much greater kingdom variety here.
368
  #
369
- # We have already observed that not all ranks are filled in at the higher levels, sometimes having just one gap. This has been greatly improved from the first iteration and we'll get one more pass.
370
 
371
  # %%
372
  #number of unique 7-tuples in EOL
@@ -387,7 +421,7 @@ eol_df.loc[eol_df.species.notna()].info(show_counts = True)
387
  # %% [markdown]
388
  # Not all labeled species have higher order taxa, but they do all have `common` (likely because if there is no common name, it pulls scientific name (genus-species)).
389
  #
390
- # This will hopefully be filled with the next iteration.
391
 
392
  # %% [markdown]
393
  # Let's get a quick sample of the `common` column for images both with and without `species` labels.
@@ -445,6 +479,18 @@ eol_long_species.loc[eol_long_species["len_species"] < 7].sample(7)
445
  #
446
  # Ex from earlier: "Adelpha godmani" is a butterfly with species name given by Fruhstorfer in 1913 ([source](https://butterfliesofamerica.com/L/t/Adelpha_godmani_a.htm)), it was listed as "adelpha godmani fruhstorfer".
447
 
 
 
 
 
 
 
 
 
 
 
 
 
448
  # %% [markdown]
449
  # ### Label Overlap Check
450
 
@@ -471,6 +517,8 @@ print(f"There are {len(list(set(gen_overlap) & set(bioscan_genera)))} genera sha
471
 
472
  # %% [markdown]
473
  # BIOSCAN and iNat21's overlap of genera is completely contained in EOL.
 
 
474
 
475
  # %% [markdown]
476
  # ## Overall Stats
 
39
  df.info(show_counts = True)
40
 
41
  # %% [markdown]
42
+ # Original version had 10,436,521 entries; we expected loss of about 84K from the genera with label "unknown", but there's still another ~300K missing for this 10,065,576. It seems subspecies were not integrated back in under their species for this version, as we now have 269 less images than last time.
43
  #
44
+ # Coverage for species also dropped by 269, genus is similar.
45
+ #
46
+ # Labeling definitely has far better coverage from original still.
47
 
48
  # %%
49
  df.nunique()
50
 
51
  # %% [markdown]
52
+ # There are 503,589 unique EOL page IDs, suggesting 503,589 unique classes among the 6,250,420 images pulled from EOL (and maintained here). Presumably this would represent the number of species or other lowest rank taxa covered by EOL.
53
+ #
54
+ # This is only 6 less pages than v3.2, but 269 less images.
55
 
56
  # %% [markdown]
57
+ # Notice that we now have 12 unique kingdoms, instead of the 7 we were sticking with.
58
 
59
  # %%
60
  df['kingdom'].value_counts()
61
 
62
+ # %% [markdown]
63
+ # `Viridiplantae`, `Protista`, `Orthornavirae`, `Bamfordvirae`, and `Shotokuvirae` are all new.
64
+
65
  # %% [markdown]
66
  # `Metazoa` and `Archaeplastida` have been replaced by `Animalia` and `Plantae`, setting them as the dominant kingdoms represented (which we'd expect).
67
  #
 
79
  df_all_taxa[taxa].info(show_counts = True)
80
 
81
  # %% [markdown]
82
+ # We have 8,455,243 images with full taxonomic labels.
83
  #
84
+ # Notice that we still have gaps in the taxonomic hierarchy (both higher and lower values), as this is less than the number of species labels in the dataset and species had the least non-null values, but the gap is closing!
85
  #
86
+ # We're at 8.4M+ entries with full taxonomic labels, so that's really good, especially considering 1,043,863 of the BIOSCAN sourced images don't have species labels.
87
+
88
+ # %% [markdown]
89
+ # How about number of unique 7-tuples?
90
+
91
+ # %%
92
+ #number of unique 7-tuples in full dataset
93
+ df['duplicate'] = df.duplicated(subset = taxa, keep = 'first')
94
+ df_unique_taxa = df.loc[~df['duplicate']]
95
+
96
+ # %%
97
+ df_unique_taxa.info(show_counts = True)
98
+
99
+ # %% [markdown]
100
+ # And number of unique `genus-species` pairs?
101
+
102
+ # %%
103
+ #number of unique genus-species pairs in full dataset
104
+ df['sciName-duplicate'] = df.duplicated(subset = ['genus', 'species'], keep = 'first')
105
+ df_unique_sciName = df.loc[~df['sciName-duplicate']]
106
+
107
+ # %%
108
+ df_unique_sciName.info(show_counts = True)
109
 
110
  # %% [markdown]
111
  # More detail on these missing values from [`check_taxa` script](https://github.com/Imageomics/open_clip/blob/main/scripts/evobio10m/check_taxa.py) are displayed below. Note: full record of taxa check output is in `data/missing_taxa_output.txt`.
112
  #
113
  # ```
114
+ # [2023-10-30 17:31:38,357] [WARNING] [root] There are 12 kingdoms instead of 3.
115
+ # [2023-10-30 17:31:39,420] [WARNING] [root] 39574 entries are missing rank kingdom, but have genus label.
116
+ # [2023-10-30 17:31:39,681] [WARNING] [root] 38324 entries are missing rank phylum, but have genus label.
117
+ # [2023-10-30 17:31:39,942] [WARNING] [root] 44828 entries are missing rank class, but have genus label.
118
+ # [2023-10-30 17:31:40,199] [WARNING] [root] 42771 entries are missing rank order, but have genus label.
119
+ # [2023-10-30 17:31:40,456] [WARNING] [root] 40131 entries are missing rank family, but have genus label.
120
+ # [2023-10-30 17:31:40,733] [WARNING] [root] 232 entries are missing rank kingdom, but have family label.
121
+ # [2023-10-30 17:31:40,759] [WARNING] [root] 223 entries are missing rank phylum, but have family label.
122
+ # [2023-10-30 17:31:40,785] [WARNING] [root] 493 entries are missing rank class, but have family label.
123
+ # [2023-10-30 17:31:40,812] [WARNING] [root] 345 entries are missing rank order, but have family label.
124
+ # [2023-10-30 17:31:40,853] [WARNING] [root] 170 entries are missing rank kingdom, but have order label.
125
+ # [2023-10-30 17:31:40,854] [WARNING] [root] 105 entries are missing rank phylum, but have order label.
126
+ # [2023-10-30 17:31:40,855] [WARNING] [root] 1263 entries are missing rank class, but have order label.
127
+ # [2023-10-30 17:31:40,893] [WARNING] [root] 41 entries have kingdom and species labels but no genus.
128
+ # [2023-10-30 17:31:40,897] [WARNING] [root] 41 entries have phylum and species labels but no genus.
129
+ # [2023-10-30 17:31:40,901] [WARNING] [root] 41 entries have class and species labels but no genus.
130
+ # [2023-10-30 17:31:40,905] [WARNING] [root] 41 entries have order and species labels but no genus.
131
+ # [2023-10-30 17:31:40,908] [WARNING] [root] 41 entries have family and species labels but no genus.
132
+ # [2023-10-30 17:31:42,311] [WARNING] [root] There are 137661 samples with species label longer than one word.
133
  # ```
134
 
135
  # %% [markdown]
136
+ # Can we get some more information on those 41 entries that are still missing genus? (should be same as before)
137
 
138
  # %%
139
  missing_genus = df.dropna(subset = ['kingdom', 'phylum', 'class', 'order', 'family', 'species'])
 
149
  print(taxon, ": ", missing_genus[taxon].unique())
150
 
151
  # %% [markdown]
152
+ # All the same as last time, will stay.
153
 
154
  # %% [markdown]
155
  # Let's add a column indicating the original data source so we can also get some stats by datasource.
 
167
  missing_genus.data_source.unique()
168
 
169
  # %% [markdown]
170
+ # Missing genus with all other taxa occurs only in EOL still. It's what it is for this version.
171
 
172
  # %% [markdown]
173
  # First, check their unique class values (`common`).
 
184
  # %% [markdown]
185
  # iNat's number of unique values in `common` is still up by 6 from the original --- probably pulled from ITIS instead and that has more listed?
186
  #
187
+ # EOL's went back down, it's about 80K less than the original version.
188
  #
189
+ # BIOSCAN's counts stabilized.
190
 
191
  # %% [markdown]
192
  # Make `df_taxa` with just taxa columns (+ `common` & `data_source`) so it's smaller to process faster.
 
257
 
258
  # %% [markdown]
259
  # We have half as many unique species and 3,000 less unique common names as in the original. Can this be accounted for by the adjustment in genus?
260
+ #
261
+ # We now seem to have gained an order over the last iteration--that would be the name resolver I guess.
262
 
263
  # %%
264
  bioscan_df['kingdom'].value_counts()
 
351
  bioscan_long_species.info(show_counts = True)
352
 
353
  # %% [markdown]
354
+ # Not all species indicated have length greater than 1 now, consistent with the last iteration.
355
 
356
  # %%
357
  bioscan_species_len_df.len_species.value_counts()
 
383
  # %%
384
  eol_df.nunique()
385
 
386
+ # %% [markdown]
387
+ # `kingdom` through `family` gained new unique labels and greater coverage, while `genus` lost images, but did not lose representation (still the same number of unique genera). Both the number of `species` and `common` went down along with the number of unique such labels.
388
+
389
  # %%
390
  eol_df.loc[eol_df.species.isna()].nunique()
391
 
392
  # %% [markdown]
393
+ # There are 503,589 unique page IDs from EOL in this dataset, which clearly represent varying levels of taxa.
394
  #
395
+ # Unique species + unique common where species is null (39,232) does not reach this number. But we still added more phyla through family!
396
 
397
  # %%
398
  eol_df['kingdom'].value_counts()
 
400
  # %% [markdown]
401
  # We have much greater kingdom variety here.
402
  #
403
+ # We have already observed that not all ranks are filled in at the higher levels, sometimes having just one gap. This has been greatly improved from the first iteration and again with this last one.
404
 
405
  # %%
406
  #number of unique 7-tuples in EOL
 
421
  # %% [markdown]
422
  # Not all labeled species have higher order taxa, but they do all have `common` (likely because if there is no common name, it pulls scientific name (genus-species)).
423
  #
424
+ # Still a 200-300K difference.
425
 
426
  # %% [markdown]
427
  # Let's get a quick sample of the `common` column for images both with and without `species` labels.
 
479
  #
480
  # Ex from earlier: "Adelpha godmani" is a butterfly with species name given by Fruhstorfer in 1913 ([source](https://butterfliesofamerica.com/L/t/Adelpha_godmani_a.htm)), it was listed as "adelpha godmani fruhstorfer".
481
 
482
+ # %% [markdown]
483
+ # #### Check for webdataset loss
484
+ #
485
+ # Are we potentially losing entries that have a longer number of words in species column? Let's see if any of these have full taxa.
486
+
487
+ # %%
488
+ eol_long_all_taxa = eol_long_species.dropna(subset = taxa)
489
+ eol_long_all_taxa[taxa].info(show_counts = True)
490
+
491
+ # %% [markdown]
492
+ # That's a good number of images, so unlikely to be the cause.
493
+
494
  # %% [markdown]
495
  # ### Label Overlap Check
496
 
 
517
 
518
  # %% [markdown]
519
  # BIOSCAN and iNat21's overlap of genera is completely contained in EOL.
520
+ #
521
+ # No changes here.
522
 
523
  # %% [markdown]
524
  # ## Overall Stats
notebooks/ToL_predicted-catalog_EDA.ipynb ADDED
@@ -0,0 +1,929 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import pandas as pd\n",
10
+ "import seaborn as sns\n",
11
+ "\n",
12
+ "sns.set_style(\"whitegrid\")\n",
13
+ "sns.set(rc = {'figure.figsize': (10,10)})"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 2,
19
+ "metadata": {},
20
+ "outputs": [
21
+ {
22
+ "name": "stderr",
23
+ "output_type": "stream",
24
+ "text": [
25
+ "/var/folders/nv/f0fq1p1n1_3b11x579py_0q80000gq/T/ipykernel_21854/4112647395.py:1: DtypeWarning: Columns (5,6,7,14,15) have mixed types. Specify dtype option on import or set low_memory=False.\n",
26
+ " df = pd.read_csv(\"../data/predicted-catalog.csv\")\n"
27
+ ]
28
+ }
29
+ ],
30
+ "source": [
31
+ "df = pd.read_csv(\"../data/predicted-catalog.csv\")"
32
+ ]
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "execution_count": 3,
37
+ "metadata": {},
38
+ "outputs": [
39
+ {
40
+ "data": {
41
+ "text/html": [
42
+ "<div>\n",
43
+ "<style scoped>\n",
44
+ " .dataframe tbody tr th:only-of-type {\n",
45
+ " vertical-align: middle;\n",
46
+ " }\n",
47
+ "\n",
48
+ " .dataframe tbody tr th {\n",
49
+ " vertical-align: top;\n",
50
+ " }\n",
51
+ "\n",
52
+ " .dataframe thead th {\n",
53
+ " text-align: right;\n",
54
+ " }\n",
55
+ "</style>\n",
56
+ "<table border=\"1\" class=\"dataframe\">\n",
57
+ " <thead>\n",
58
+ " <tr style=\"text-align: right;\">\n",
59
+ " <th></th>\n",
60
+ " <th>split</th>\n",
61
+ " <th>treeoflife_id</th>\n",
62
+ " <th>eol_content_id</th>\n",
63
+ " <th>eol_page_id</th>\n",
64
+ " <th>bioscan_part</th>\n",
65
+ " <th>bioscan_filename</th>\n",
66
+ " <th>inat21_filename</th>\n",
67
+ " <th>inat21_cls_name</th>\n",
68
+ " <th>inat21_cls_num</th>\n",
69
+ " <th>kingdom</th>\n",
70
+ " <th>phylum</th>\n",
71
+ " <th>class</th>\n",
72
+ " <th>order</th>\n",
73
+ " <th>family</th>\n",
74
+ " <th>genus</th>\n",
75
+ " <th>species</th>\n",
76
+ " <th>common</th>\n",
77
+ " </tr>\n",
78
+ " </thead>\n",
79
+ " <tbody>\n",
80
+ " <tr>\n",
81
+ " <th>0</th>\n",
82
+ " <td>train</td>\n",
83
+ " <td>f2f0aa29-e87b-469c-bf5b-51a3611ab001</td>\n",
84
+ " <td>22131926.0</td>\n",
85
+ " <td>269504.0</td>\n",
86
+ " <td>NaN</td>\n",
87
+ " <td>NaN</td>\n",
88
+ " <td>NaN</td>\n",
89
+ " <td>NaN</td>\n",
90
+ " <td>NaN</td>\n",
91
+ " <td>Animalia</td>\n",
92
+ " <td>Arthropoda</td>\n",
93
+ " <td>Insecta</td>\n",
94
+ " <td>Lepidoptera</td>\n",
95
+ " <td>Lycaenidae</td>\n",
96
+ " <td>Orthomiella</td>\n",
97
+ " <td>rantaizana</td>\n",
98
+ " <td>Chinese Straight-wing Blue</td>\n",
99
+ " </tr>\n",
100
+ " <tr>\n",
101
+ " <th>1</th>\n",
102
+ " <td>train</td>\n",
103
+ " <td>5faa4f55-32e9-4872-953d-567e5d232e52</td>\n",
104
+ " <td>22291283.0</td>\n",
105
+ " <td>6101931.0</td>\n",
106
+ " <td>NaN</td>\n",
107
+ " <td>NaN</td>\n",
108
+ " <td>NaN</td>\n",
109
+ " <td>NaN</td>\n",
110
+ " <td>NaN</td>\n",
111
+ " <td>Plantae</td>\n",
112
+ " <td>Tracheophyta</td>\n",
113
+ " <td>Polypodiopsida</td>\n",
114
+ " <td>Polypodiales</td>\n",
115
+ " <td>Woodsiaceae</td>\n",
116
+ " <td>Woodsia</td>\n",
117
+ " <td>subcordata</td>\n",
118
+ " <td>Woodsia subcordata</td>\n",
119
+ " </tr>\n",
120
+ " <tr>\n",
121
+ " <th>2</th>\n",
122
+ " <td>train</td>\n",
123
+ " <td>2282f2bf-2b52-4522-b588-dd6f356d5fd6</td>\n",
124
+ " <td>21802775.0</td>\n",
125
+ " <td>45513632.0</td>\n",
126
+ " <td>NaN</td>\n",
127
+ " <td>NaN</td>\n",
128
+ " <td>NaN</td>\n",
129
+ " <td>NaN</td>\n",
130
+ " <td>NaN</td>\n",
131
+ " <td>Animalia</td>\n",
132
+ " <td>Chordata</td>\n",
133
+ " <td>Aves</td>\n",
134
+ " <td>Passeriformes</td>\n",
135
+ " <td>Laniidae</td>\n",
136
+ " <td>Lanius</td>\n",
137
+ " <td>minor</td>\n",
138
+ " <td>Lesser Grey Shrike</td>\n",
139
+ " </tr>\n",
140
+ " <tr>\n",
141
+ " <th>3</th>\n",
142
+ " <td>train</td>\n",
143
+ " <td>76b57c36-2181-4e6d-a5c4-b40e22a09449</td>\n",
144
+ " <td>12784812.0</td>\n",
145
+ " <td>51655800.0</td>\n",
146
+ " <td>NaN</td>\n",
147
+ " <td>NaN</td>\n",
148
+ " <td>NaN</td>\n",
149
+ " <td>NaN</td>\n",
150
+ " <td>NaN</td>\n",
151
+ " <td>NaN</td>\n",
152
+ " <td>NaN</td>\n",
153
+ " <td>NaN</td>\n",
154
+ " <td>NaN</td>\n",
155
+ " <td>NaN</td>\n",
156
+ " <td>NaN</td>\n",
157
+ " <td>tenuis</td>\n",
158
+ " <td>Tenuis</td>\n",
159
+ " </tr>\n",
160
+ " <tr>\n",
161
+ " <th>4</th>\n",
162
+ " <td>train</td>\n",
163
+ " <td>f57d3ab6-2cf5-484b-a590-e2a3d49a3ca2</td>\n",
164
+ " <td>29713643.0</td>\n",
165
+ " <td>45515896.0</td>\n",
166
+ " <td>NaN</td>\n",
167
+ " <td>NaN</td>\n",
168
+ " <td>NaN</td>\n",
169
+ " <td>NaN</td>\n",
170
+ " <td>NaN</td>\n",
171
+ " <td>Animalia</td>\n",
172
+ " <td>Chordata</td>\n",
173
+ " <td>Aves</td>\n",
174
+ " <td>Casuariiformes</td>\n",
175
+ " <td>Casuariidae</td>\n",
176
+ " <td>Casuarius</td>\n",
177
+ " <td>casuarius</td>\n",
178
+ " <td>Southern Cassowary</td>\n",
179
+ " </tr>\n",
180
+ " </tbody>\n",
181
+ "</table>\n",
182
+ "</div>"
183
+ ],
184
+ "text/plain": [
185
+ " split treeoflife_id eol_content_id eol_page_id \n",
186
+ "0 train f2f0aa29-e87b-469c-bf5b-51a3611ab001 22131926.0 269504.0 \\\n",
187
+ "1 train 5faa4f55-32e9-4872-953d-567e5d232e52 22291283.0 6101931.0 \n",
188
+ "2 train 2282f2bf-2b52-4522-b588-dd6f356d5fd6 21802775.0 45513632.0 \n",
189
+ "3 train 76b57c36-2181-4e6d-a5c4-b40e22a09449 12784812.0 51655800.0 \n",
190
+ "4 train f57d3ab6-2cf5-484b-a590-e2a3d49a3ca2 29713643.0 45515896.0 \n",
191
+ "\n",
192
+ " bioscan_part bioscan_filename inat21_filename inat21_cls_name \n",
193
+ "0 NaN NaN NaN NaN \\\n",
194
+ "1 NaN NaN NaN NaN \n",
195
+ "2 NaN NaN NaN NaN \n",
196
+ "3 NaN NaN NaN NaN \n",
197
+ "4 NaN NaN NaN NaN \n",
198
+ "\n",
199
+ " inat21_cls_num kingdom phylum class order \n",
200
+ "0 NaN Animalia Arthropoda Insecta Lepidoptera \\\n",
201
+ "1 NaN Plantae Tracheophyta Polypodiopsida Polypodiales \n",
202
+ "2 NaN Animalia Chordata Aves Passeriformes \n",
203
+ "3 NaN NaN NaN NaN NaN \n",
204
+ "4 NaN Animalia Chordata Aves Casuariiformes \n",
205
+ "\n",
206
+ " family genus species common \n",
207
+ "0 Lycaenidae Orthomiella rantaizana Chinese Straight-wing Blue \n",
208
+ "1 Woodsiaceae Woodsia subcordata Woodsia subcordata \n",
209
+ "2 Laniidae Lanius minor Lesser Grey Shrike \n",
210
+ "3 NaN NaN tenuis Tenuis \n",
211
+ "4 Casuariidae Casuarius casuarius Southern Cassowary "
212
+ ]
213
+ },
214
+ "execution_count": 3,
215
+ "metadata": {},
216
+ "output_type": "execute_result"
217
+ }
218
+ ],
219
+ "source": [
220
+ "df.head()"
221
+ ]
222
+ },
223
+ {
224
+ "cell_type": "code",
225
+ "execution_count": 4,
226
+ "metadata": {},
227
+ "outputs": [
228
+ {
229
+ "name": "stdout",
230
+ "output_type": "stream",
231
+ "text": [
232
+ "<class 'pandas.core.frame.DataFrame'>\n",
233
+ "RangeIndex: 10092530 entries, 0 to 10092529\n",
234
+ "Data columns (total 17 columns):\n",
235
+ " # Column Non-Null Count Dtype \n",
236
+ "--- ------ -------------- ----- \n",
237
+ " 0 split 10092530 non-null object \n",
238
+ " 1 treeoflife_id 10092530 non-null object \n",
239
+ " 2 eol_content_id 6277374 non-null float64\n",
240
+ " 3 eol_page_id 6277374 non-null float64\n",
241
+ " 4 bioscan_part 1128313 non-null float64\n",
242
+ " 5 bioscan_filename 1128313 non-null object \n",
243
+ " 6 inat21_filename 2686843 non-null object \n",
244
+ " 7 inat21_cls_name 2686843 non-null object \n",
245
+ " 8 inat21_cls_num 2686843 non-null float64\n",
246
+ " 9 kingdom 9831721 non-null object \n",
247
+ " 10 phylum 9833317 non-null object \n",
248
+ " 11 class 9813548 non-null object \n",
249
+ " 12 order 9807409 non-null object \n",
250
+ " 13 family 9775447 non-null object \n",
251
+ " 14 genus 8908268 non-null object \n",
252
+ " 15 species 8749857 non-null object \n",
253
+ " 16 common 10092530 non-null object \n",
254
+ "dtypes: float64(4), object(13)\n",
255
+ "memory usage: 1.3+ GB\n"
256
+ ]
257
+ }
258
+ ],
259
+ "source": [
260
+ "df.info(show_counts = True)"
261
+ ]
262
+ },
263
+ {
264
+ "cell_type": "markdown",
265
+ "metadata": {},
266
+ "source": [
267
+ "The `train_small` is duplicates of `train`, so we will drop those to analyze the full training set plus val."
268
+ ]
269
+ },
270
+ {
271
+ "cell_type": "code",
272
+ "execution_count": 5,
273
+ "metadata": {},
274
+ "outputs": [],
275
+ "source": [
276
+ "df = df.loc[df.split != 'train_small']"
277
+ ]
278
+ },
279
+ {
280
+ "cell_type": "code",
281
+ "execution_count": 6,
282
+ "metadata": {},
283
+ "outputs": [
284
+ {
285
+ "name": "stdout",
286
+ "output_type": "stream",
287
+ "text": [
288
+ "<class 'pandas.core.frame.DataFrame'>\n",
289
+ "Index: 10092530 entries, 0 to 10092529\n",
290
+ "Data columns (total 17 columns):\n",
291
+ " # Column Non-Null Count Dtype \n",
292
+ "--- ------ -------------- ----- \n",
293
+ " 0 split 10092530 non-null object \n",
294
+ " 1 treeoflife_id 10092530 non-null object \n",
295
+ " 2 eol_content_id 6277374 non-null float64\n",
296
+ " 3 eol_page_id 6277374 non-null float64\n",
297
+ " 4 bioscan_part 1128313 non-null float64\n",
298
+ " 5 bioscan_filename 1128313 non-null object \n",
299
+ " 6 inat21_filename 2686843 non-null object \n",
300
+ " 7 inat21_cls_name 2686843 non-null object \n",
301
+ " 8 inat21_cls_num 2686843 non-null float64\n",
302
+ " 9 kingdom 9831721 non-null object \n",
303
+ " 10 phylum 9833317 non-null object \n",
304
+ " 11 class 9813548 non-null object \n",
305
+ " 12 order 9807409 non-null object \n",
306
+ " 13 family 9775447 non-null object \n",
307
+ " 14 genus 8908268 non-null object \n",
308
+ " 15 species 8749857 non-null object \n",
309
+ " 16 common 10092530 non-null object \n",
310
+ "dtypes: float64(4), object(13)\n",
311
+ "memory usage: 1.4+ GB\n"
312
+ ]
313
+ }
314
+ ],
315
+ "source": [
316
+ "df.info(show_counts = True)"
317
+ ]
318
+ },
319
+ {
320
+ "cell_type": "markdown",
321
+ "metadata": {},
322
+ "source": [
323
+ "`predicted-catalog` doesn't have `train_small`, hence, it's a smaller file."
324
+ ]
325
+ },
326
+ {
327
+ "cell_type": "markdown",
328
+ "metadata": {},
329
+ "source": [
330
+ "Original version had 10,436,521 entries; we expected loss of about 84K from the genera with label \"unknown\".\n",
331
+ "We have still lost about 300K images from the original 10,092,530, but the pre-webdataset generation gained about 30K back from v3.2 (adding subspecies back in?).\n",
332
+ "\n",
333
+ ".......\n",
334
+ "\n",
335
+ "after webdataset generation:\n",
336
+ "\n",
337
+ ", but there's still another ~300K missing for this 10,065,576. It seems subspecies were not integrated back in under their species for this version, as we now have 269 less images than last time.\n",
338
+ "\n",
339
+ "Coverage for species and genus has also dropped by 269 and similar, resp."
340
+ ]
341
+ },
342
+ {
343
+ "cell_type": "markdown",
344
+ "metadata": {},
345
+ "source": [
346
+ "### Focus here on the difference between `predicted-catalog` and `catalog`, which is only in EOL data."
347
+ ]
348
+ },
349
+ {
350
+ "cell_type": "code",
351
+ "execution_count": 8,
352
+ "metadata": {},
353
+ "outputs": [
354
+ {
355
+ "data": {
356
+ "text/plain": [
357
+ "split 2\n",
358
+ "treeoflife_id 10092530\n",
359
+ "eol_content_id 6277374\n",
360
+ "eol_page_id 504018\n",
361
+ "bioscan_part 113\n",
362
+ "bioscan_filename 1128313\n",
363
+ "inat21_filename 2686843\n",
364
+ "inat21_cls_name 10000\n",
365
+ "inat21_cls_num 10000\n",
366
+ "kingdom 12\n",
367
+ "phylum 108\n",
368
+ "class 347\n",
369
+ "order 1495\n",
370
+ "family 7973\n",
371
+ "genus 73896\n",
372
+ "species 163741\n",
373
+ "common 444284\n",
374
+ "dtype: int64"
375
+ ]
376
+ },
377
+ "execution_count": 8,
378
+ "metadata": {},
379
+ "output_type": "execute_result"
380
+ }
381
+ ],
382
+ "source": [
383
+ "df.nunique()"
384
+ ]
385
+ },
386
+ {
387
+ "cell_type": "markdown",
388
+ "metadata": {},
389
+ "source": [
390
+ "There are 504,018 unique EOL page IDs (total 6,277,374 entries), compared to the 503,589 in the webdataset (total 6,250,420 images)."
391
+ ]
392
+ },
393
+ {
394
+ "cell_type": "code",
395
+ "execution_count": 12,
396
+ "metadata": {},
397
+ "outputs": [
398
+ {
399
+ "name": "stdout",
400
+ "output_type": "stream",
401
+ "text": [
402
+ "There are 26954 less entries in the webdataset.\n"
403
+ ]
404
+ }
405
+ ],
406
+ "source": [
407
+ "# Number that get dropped in webdataset\n",
408
+ "print(f\"There are {6277374 - 6250420} less entries in the webdataset.\")"
409
+ ]
410
+ },
411
+ {
412
+ "cell_type": "markdown",
413
+ "metadata": {},
414
+ "source": [
415
+ "Notice that we have 12 unique kingdoms, which we're sticking with."
416
+ ]
417
+ },
418
+ {
419
+ "cell_type": "code",
420
+ "execution_count": 9,
421
+ "metadata": {},
422
+ "outputs": [
423
+ {
424
+ "data": {
425
+ "text/plain": [
426
+ "kingdom\n",
427
+ "Animalia 6097759\n",
428
+ "Plantae 3339372\n",
429
+ "Fungi 359553\n",
430
+ "Chromista 15227\n",
431
+ "Protozoa 13755\n",
432
+ "Bacteria 3309\n",
433
+ "Viridiplantae 1960\n",
434
+ "Protista 422\n",
435
+ "Orthornavirae 289\n",
436
+ "Bamfordvirae 41\n",
437
+ "Archaea 25\n",
438
+ "Shotokuvirae 9\n",
439
+ "Name: count, dtype: int64"
440
+ ]
441
+ },
442
+ "execution_count": 9,
443
+ "metadata": {},
444
+ "output_type": "execute_result"
445
+ }
446
+ ],
447
+ "source": [
448
+ "df['kingdom'].value_counts()"
449
+ ]
450
+ },
451
+ {
452
+ "cell_type": "markdown",
453
+ "metadata": {},
454
+ "source": [
455
+ "There is 1 more member of `Plantae` predicted, but 27K more `Animalia`."
456
+ ]
457
+ },
458
+ {
459
+ "cell_type": "code",
460
+ "execution_count": 10,
461
+ "metadata": {},
462
+ "outputs": [
463
+ {
464
+ "data": {
465
+ "text/plain": [
466
+ "['kingdom', 'phylum', 'class', 'order', 'family', 'genus', 'species']"
467
+ ]
468
+ },
469
+ "execution_count": 10,
470
+ "metadata": {},
471
+ "output_type": "execute_result"
472
+ }
473
+ ],
474
+ "source": [
475
+ "taxa = list(df.columns[9:16])\n",
476
+ "taxa"
477
+ ]
478
+ },
479
+ {
480
+ "cell_type": "markdown",
481
+ "metadata": {},
482
+ "source": [
483
+ "Check the number of images with all 7 taxonomic labels."
484
+ ]
485
+ },
486
+ {
487
+ "cell_type": "code",
488
+ "execution_count": 11,
489
+ "metadata": {},
490
+ "outputs": [
491
+ {
492
+ "name": "stdout",
493
+ "output_type": "stream",
494
+ "text": [
495
+ "<class 'pandas.core.frame.DataFrame'>\n",
496
+ "Index: 8482197 entries, 0 to 10092529\n",
497
+ "Data columns (total 7 columns):\n",
498
+ " # Column Non-Null Count Dtype \n",
499
+ "--- ------ -------------- ----- \n",
500
+ " 0 kingdom 8482197 non-null object\n",
501
+ " 1 phylum 8482197 non-null object\n",
502
+ " 2 class 8482197 non-null object\n",
503
+ " 3 order 8482197 non-null object\n",
504
+ " 4 family 8482197 non-null object\n",
505
+ " 5 genus 8482197 non-null object\n",
506
+ " 6 species 8482197 non-null object\n",
507
+ "dtypes: object(7)\n",
508
+ "memory usage: 517.7+ MB\n"
509
+ ]
510
+ }
511
+ ],
512
+ "source": [
513
+ "df_all_taxa = df.dropna(subset = taxa)\n",
514
+ "df_all_taxa[taxa].info(show_counts = True)"
515
+ ]
516
+ },
517
+ {
518
+ "cell_type": "markdown",
519
+ "metadata": {},
520
+ "source": [
521
+ "We have 8,482,197 entries with full taxonomic labels, compared to 8,455,243 in the webdataset, so \n",
522
+ "### _**all**_ of our lost entries have all taxonomic ranks filled."
523
+ ]
524
+ },
525
+ {
526
+ "cell_type": "markdown",
527
+ "metadata": {},
528
+ "source": [
529
+ "Let's add a column indicating the original data source so we can also get some stats by datasource, specifically focusing on EOL now."
530
+ ]
531
+ },
532
+ {
533
+ "cell_type": "code",
534
+ "execution_count": 13,
535
+ "metadata": {},
536
+ "outputs": [],
537
+ "source": [
538
+ "# Add data_source column for easier slicing\n",
539
+ "df.loc[df['inat21_filename'].notna(), 'data_source'] = 'iNat21'\n",
540
+ "df.loc[df['bioscan_filename'].notna(), 'data_source'] = 'BIOSCAN'\n",
541
+ "df.loc[df['eol_content_id'].notna(), 'data_source'] = 'EOL'"
542
+ ]
543
+ },
544
+ {
545
+ "cell_type": "markdown",
546
+ "metadata": {},
547
+ "source": [
548
+ "First, check their unique class values (`common`)."
549
+ ]
550
+ },
551
+ {
552
+ "cell_type": "code",
553
+ "execution_count": 14,
554
+ "metadata": {},
555
+ "outputs": [
556
+ {
557
+ "data": {
558
+ "text/plain": [
559
+ "440296"
560
+ ]
561
+ },
562
+ "execution_count": 14,
563
+ "metadata": {},
564
+ "output_type": "execute_result"
565
+ }
566
+ ],
567
+ "source": [
568
+ "df.loc[df['data_source'] == 'EOL', 'common'].nunique()"
569
+ ]
570
+ },
571
+ {
572
+ "cell_type": "markdown",
573
+ "metadata": {},
574
+ "source": [
575
+ "EOL number of unique classes is 439,910 in the webdataset, so we do lose 386..."
576
+ ]
577
+ },
578
+ {
579
+ "cell_type": "markdown",
580
+ "metadata": {},
581
+ "source": [
582
+ "Make `df_taxa` with just taxa columns (+ `common` & `data_source`) so it's smaller to process faster."
583
+ ]
584
+ },
585
+ {
586
+ "cell_type": "code",
587
+ "execution_count": 15,
588
+ "metadata": {},
589
+ "outputs": [],
590
+ "source": [
591
+ "taxa_com = list(df.columns[9:17]) # taxa + common\n",
592
+ "taxa_com.insert(0, 'data_source')\n",
593
+ "df_taxa = df[taxa_com]"
594
+ ]
595
+ },
596
+ {
597
+ "cell_type": "code",
598
+ "execution_count": 16,
599
+ "metadata": {},
600
+ "outputs": [
601
+ {
602
+ "data": {
603
+ "text/html": [
604
+ "<div>\n",
605
+ "<style scoped>\n",
606
+ " .dataframe tbody tr th:only-of-type {\n",
607
+ " vertical-align: middle;\n",
608
+ " }\n",
609
+ "\n",
610
+ " .dataframe tbody tr th {\n",
611
+ " vertical-align: top;\n",
612
+ " }\n",
613
+ "\n",
614
+ " .dataframe thead th {\n",
615
+ " text-align: right;\n",
616
+ " }\n",
617
+ "</style>\n",
618
+ "<table border=\"1\" class=\"dataframe\">\n",
619
+ " <thead>\n",
620
+ " <tr style=\"text-align: right;\">\n",
621
+ " <th></th>\n",
622
+ " <th>data_source</th>\n",
623
+ " <th>kingdom</th>\n",
624
+ " <th>phylum</th>\n",
625
+ " <th>class</th>\n",
626
+ " <th>order</th>\n",
627
+ " <th>family</th>\n",
628
+ " <th>genus</th>\n",
629
+ " <th>species</th>\n",
630
+ " <th>common</th>\n",
631
+ " </tr>\n",
632
+ " </thead>\n",
633
+ " <tbody>\n",
634
+ " <tr>\n",
635
+ " <th>0</th>\n",
636
+ " <td>EOL</td>\n",
637
+ " <td>Animalia</td>\n",
638
+ " <td>Arthropoda</td>\n",
639
+ " <td>Insecta</td>\n",
640
+ " <td>Lepidoptera</td>\n",
641
+ " <td>Lycaenidae</td>\n",
642
+ " <td>Orthomiella</td>\n",
643
+ " <td>rantaizana</td>\n",
644
+ " <td>Chinese Straight-wing Blue</td>\n",
645
+ " </tr>\n",
646
+ " <tr>\n",
647
+ " <th>1</th>\n",
648
+ " <td>EOL</td>\n",
649
+ " <td>Plantae</td>\n",
650
+ " <td>Tracheophyta</td>\n",
651
+ " <td>Polypodiopsida</td>\n",
652
+ " <td>Polypodiales</td>\n",
653
+ " <td>Woodsiaceae</td>\n",
654
+ " <td>Woodsia</td>\n",
655
+ " <td>subcordata</td>\n",
656
+ " <td>Woodsia subcordata</td>\n",
657
+ " </tr>\n",
658
+ " <tr>\n",
659
+ " <th>2</th>\n",
660
+ " <td>EOL</td>\n",
661
+ " <td>Animalia</td>\n",
662
+ " <td>Chordata</td>\n",
663
+ " <td>Aves</td>\n",
664
+ " <td>Passeriformes</td>\n",
665
+ " <td>Laniidae</td>\n",
666
+ " <td>Lanius</td>\n",
667
+ " <td>minor</td>\n",
668
+ " <td>Lesser Grey Shrike</td>\n",
669
+ " </tr>\n",
670
+ " <tr>\n",
671
+ " <th>3</th>\n",
672
+ " <td>EOL</td>\n",
673
+ " <td>NaN</td>\n",
674
+ " <td>NaN</td>\n",
675
+ " <td>NaN</td>\n",
676
+ " <td>NaN</td>\n",
677
+ " <td>NaN</td>\n",
678
+ " <td>NaN</td>\n",
679
+ " <td>tenuis</td>\n",
680
+ " <td>Tenuis</td>\n",
681
+ " </tr>\n",
682
+ " <tr>\n",
683
+ " <th>4</th>\n",
684
+ " <td>EOL</td>\n",
685
+ " <td>Animalia</td>\n",
686
+ " <td>Chordata</td>\n",
687
+ " <td>Aves</td>\n",
688
+ " <td>Casuariiformes</td>\n",
689
+ " <td>Casuariidae</td>\n",
690
+ " <td>Casuarius</td>\n",
691
+ " <td>casuarius</td>\n",
692
+ " <td>Southern Cassowary</td>\n",
693
+ " </tr>\n",
694
+ " </tbody>\n",
695
+ "</table>\n",
696
+ "</div>"
697
+ ],
698
+ "text/plain": [
699
+ " data_source kingdom phylum class order \n",
700
+ "0 EOL Animalia Arthropoda Insecta Lepidoptera \\\n",
701
+ "1 EOL Plantae Tracheophyta Polypodiopsida Polypodiales \n",
702
+ "2 EOL Animalia Chordata Aves Passeriformes \n",
703
+ "3 EOL NaN NaN NaN NaN \n",
704
+ "4 EOL Animalia Chordata Aves Casuariiformes \n",
705
+ "\n",
706
+ " family genus species common \n",
707
+ "0 Lycaenidae Orthomiella rantaizana Chinese Straight-wing Blue \n",
708
+ "1 Woodsiaceae Woodsia subcordata Woodsia subcordata \n",
709
+ "2 Laniidae Lanius minor Lesser Grey Shrike \n",
710
+ "3 NaN NaN tenuis Tenuis \n",
711
+ "4 Casuariidae Casuarius casuarius Southern Cassowary "
712
+ ]
713
+ },
714
+ "execution_count": 16,
715
+ "metadata": {},
716
+ "output_type": "execute_result"
717
+ }
718
+ ],
719
+ "source": [
720
+ "df_taxa.head()"
721
+ ]
722
+ },
723
+ {
724
+ "cell_type": "markdown",
725
+ "metadata": {},
726
+ "source": [
727
+ "Let's look a little closer at EOL."
728
+ ]
729
+ },
730
+ {
731
+ "cell_type": "code",
732
+ "execution_count": 17,
733
+ "metadata": {},
734
+ "outputs": [],
735
+ "source": [
736
+ "inat21_df = df_taxa.loc[df_taxa.data_source == 'iNat21']\n",
737
+ "bioscan_df = df_taxa.loc[df_taxa.data_source == 'BIOSCAN']\n",
738
+ "eol_df = df_taxa.loc[df_taxa.data_source == 'EOL']"
739
+ ]
740
+ },
741
+ {
742
+ "cell_type": "markdown",
743
+ "metadata": {},
744
+ "source": [
745
+ "### EOL"
746
+ ]
747
+ },
748
+ {
749
+ "cell_type": "code",
750
+ "execution_count": 18,
751
+ "metadata": {},
752
+ "outputs": [
753
+ {
754
+ "name": "stdout",
755
+ "output_type": "stream",
756
+ "text": [
757
+ "<class 'pandas.core.frame.DataFrame'>\n",
758
+ "Index: 6277374 entries, 0 to 6277373\n",
759
+ "Data columns (total 9 columns):\n",
760
+ " # Column Non-Null Count Dtype \n",
761
+ "--- ------ -------------- ----- \n",
762
+ " 0 data_source 6277374 non-null object\n",
763
+ " 1 kingdom 6016565 non-null object\n",
764
+ " 2 phylum 6018161 non-null object\n",
765
+ " 3 class 5998392 non-null object\n",
766
+ " 4 order 5992253 non-null object\n",
767
+ " 5 family 5975682 non-null object\n",
768
+ " 6 genus 5967267 non-null object\n",
769
+ " 7 species 5978567 non-null object\n",
770
+ " 8 common 6277374 non-null object\n",
771
+ "dtypes: object(9)\n",
772
+ "memory usage: 478.9+ MB\n"
773
+ ]
774
+ }
775
+ ],
776
+ "source": [
777
+ "eol_df.info(show_counts = True)"
778
+ ]
779
+ },
780
+ {
781
+ "cell_type": "code",
782
+ "execution_count": 19,
783
+ "metadata": {},
784
+ "outputs": [
785
+ {
786
+ "data": {
787
+ "text/plain": [
788
+ "data_source 1\n",
789
+ "kingdom 12\n",
790
+ "phylum 108\n",
791
+ "class 344\n",
792
+ "order 1489\n",
793
+ "family 7929\n",
794
+ "genus 73104\n",
795
+ "species 162275\n",
796
+ "common 440296\n",
797
+ "dtype: int64"
798
+ ]
799
+ },
800
+ "execution_count": 19,
801
+ "metadata": {},
802
+ "output_type": "execute_result"
803
+ }
804
+ ],
805
+ "source": [
806
+ "eol_df.nunique()"
807
+ ]
808
+ },
809
+ {
810
+ "cell_type": "markdown",
811
+ "metadata": {},
812
+ "source": [
813
+ "It seems the webdataset loses 5 families, 39 genera, and 84 species. As noted above, 386 common labels are lost."
814
+ ]
815
+ },
816
+ {
817
+ "cell_type": "markdown",
818
+ "metadata": {},
819
+ "source": [
820
+ "There are no missing species that get lost, as observed above, all lost entries have all taxonomic labels."
821
+ ]
822
+ },
823
+ {
824
+ "cell_type": "code",
825
+ "execution_count": 22,
826
+ "metadata": {},
827
+ "outputs": [
828
+ {
829
+ "name": "stderr",
830
+ "output_type": "stream",
831
+ "text": [
832
+ "/var/folders/nv/f0fq1p1n1_3b11x579py_0q80000gq/T/ipykernel_21854/52183210.py:2: SettingWithCopyWarning: \n",
833
+ "A value is trying to be set on a copy of a slice from a DataFrame.\n",
834
+ "Try using .loc[row_indexer,col_indexer] = value instead\n",
835
+ "\n",
836
+ "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
837
+ " eol_df['duplicate'] = eol_df.duplicated(subset = taxa, keep = 'first')\n"
838
+ ]
839
+ }
840
+ ],
841
+ "source": [
842
+ "#number of unique 7-tuples in EOL\n",
843
+ "eol_df['duplicate'] = eol_df.duplicated(subset = taxa, keep = 'first')\n",
844
+ "eol_df_unique_taxa = eol_df.loc[~eol_df['duplicate']]"
845
+ ]
846
+ },
847
+ {
848
+ "cell_type": "code",
849
+ "execution_count": 23,
850
+ "metadata": {},
851
+ "outputs": [
852
+ {
853
+ "name": "stdout",
854
+ "output_type": "stream",
855
+ "text": [
856
+ "<class 'pandas.core.frame.DataFrame'>\n",
857
+ "Index: 449310 entries, 0 to 6277357\n",
858
+ "Data columns (total 10 columns):\n",
859
+ " # Column Non-Null Count Dtype \n",
860
+ "--- ------ -------------- ----- \n",
861
+ " 0 data_source 449310 non-null object\n",
862
+ " 1 kingdom 420156 non-null object\n",
863
+ " 2 phylum 420619 non-null object\n",
864
+ " 3 class 419503 non-null object\n",
865
+ " 4 order 419849 non-null object\n",
866
+ " 5 family 419720 non-null object\n",
867
+ " 6 genus 422707 non-null object\n",
868
+ " 7 species 409745 non-null object\n",
869
+ " 8 common 449310 non-null object\n",
870
+ " 9 duplicate 449310 non-null bool \n",
871
+ "dtypes: bool(1), object(9)\n",
872
+ "memory usage: 34.7+ MB\n"
873
+ ]
874
+ }
875
+ ],
876
+ "source": [
877
+ "eol_df_unique_taxa.info(show_counts = True)"
878
+ ]
879
+ },
880
+ {
881
+ "cell_type": "markdown",
882
+ "metadata": {},
883
+ "source": [
884
+ "400 unique taxa are lost."
885
+ ]
886
+ },
887
+ {
888
+ "cell_type": "markdown",
889
+ "metadata": {},
890
+ "source": [
891
+ "Let's check the `species` length in EOL as well, we know there are some that have genus-species. And others with hybrids that get VERY long.\n",
892
+ "\n",
893
+ "Wonder if this is where we lose some?\n",
894
+ "Quick check in the catalog notebook shows there are still plenty with full taxa there."
895
+ ]
896
+ },
897
+ {
898
+ "cell_type": "code",
899
+ "execution_count": null,
900
+ "metadata": {},
901
+ "outputs": [],
902
+ "source": []
903
+ }
904
+ ],
905
+ "metadata": {
906
+ "jupytext": {
907
+ "formats": "ipynb,py:percent"
908
+ },
909
+ "kernelspec": {
910
+ "display_name": "Python 3 (ipykernel)",
911
+ "language": "python",
912
+ "name": "python3"
913
+ },
914
+ "language_info": {
915
+ "codemirror_mode": {
916
+ "name": "ipython",
917
+ "version": 3
918
+ },
919
+ "file_extension": ".py",
920
+ "mimetype": "text/x-python",
921
+ "name": "python",
922
+ "nbconvert_exporter": "python",
923
+ "pygments_lexer": "ipython3",
924
+ "version": "3.11.3"
925
+ }
926
+ },
927
+ "nbformat": 4,
928
+ "nbformat_minor": 2
929
+ }
notebooks/ToL_predicted-catalog_EDA.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ---
2
+ # jupyter:
3
+ # jupytext:
4
+ # formats: ipynb,py:percent
5
+ # text_representation:
6
+ # extension: .py
7
+ # format_name: percent
8
+ # format_version: '1.3'
9
+ # jupytext_version: 1.15.2
10
+ # kernelspec:
11
+ # display_name: Python 3 (ipykernel)
12
+ # language: python
13
+ # name: python3
14
+ # ---
15
+
16
+ # %%
17
+ import pandas as pd
18
+ import seaborn as sns
19
+
20
+ sns.set_style("whitegrid")
21
+ sns.set(rc = {'figure.figsize': (10,10)})
22
+
23
+ # %%
24
+ df = pd.read_csv("../data/predicted-catalog.csv")
25
+
26
+ # %%
27
+ df.head()
28
+
29
+ # %%
30
+ df.info(show_counts = True)
31
+
32
+ # %% [markdown]
33
+ # The `train_small` is duplicates of `train`, so we will drop those to analyze the full training set plus val.
34
+
35
+ # %%
36
+ df = df.loc[df.split != 'train_small']
37
+
38
+ # %%
39
+ df.info(show_counts = True)
40
+
41
+ # %% [markdown]
42
+ # `predicted-catalog` doesn't have `train_small`, hence, it's a smaller file.
43
+
44
+ # %% [markdown]
45
+ # Original version had 10,436,521 entries; we expected loss of about 84K from the genera with label "unknown".
46
+ # We have still lost about 300K images from the original 10,092,530, but the pre-webdataset generation gained about 30K back from v3.2 (adding subspecies back in?).
47
+ #
48
+ # .......
49
+ #
50
+ # after webdataset generation:
51
+ #
52
+ # , but there's still another ~300K missing for this 10,065,576. It seems subspecies were not integrated back in under their species for this version, as we now have 269 less images than last time.
53
+ #
54
+ # Coverage for species and genus has also dropped by 269 and similar, resp.
55
+
56
+ # %% [markdown]
57
+ # ### Focus here on the difference between `predicted-catalog` and `catalog`, which is only in EOL data.
58
+
59
+ # %%
60
+ df.nunique()
61
+
62
+ # %% [markdown]
63
+ # There are 504,018 unique EOL page IDs (total 6,277,374 entries), compared to the 503,589 in the webdataset (total 6,250,420 images).
64
+
65
+ # %%
66
+ # Number that get dropped in webdataset
67
+ print(f"There are {6277374 - 6250420} less entries in the webdataset.")
68
+
69
+ # %% [markdown]
70
+ # Notice that we have 12 unique kingdoms, which we're sticking with.
71
+
72
+ # %%
73
+ df['kingdom'].value_counts()
74
+
75
+ # %% [markdown]
76
+ # There is 1 more member of `Plantae` predicted, but 27K more `Animalia`.
77
+
78
+ # %%
79
+ taxa = list(df.columns[9:16])
80
+ taxa
81
+
82
+ # %% [markdown]
83
+ # Check the number of images with all 7 taxonomic labels.
84
+
85
+ # %%
86
+ df_all_taxa = df.dropna(subset = taxa)
87
+ df_all_taxa[taxa].info(show_counts = True)
88
+
89
+ # %% [markdown]
90
+ # We have 8,482,197 entries with full taxonomic labels, compared to 8,455,243 in the webdataset, so
91
+ # ### _**all**_ of our lost entries have all taxonomic ranks filled.
92
+
93
+ # %% [markdown]
94
+ # Let's add a column indicating the original data source so we can also get some stats by datasource, specifically focusing on EOL now.
95
+
96
+ # %%
97
+ # Add data_source column for easier slicing
98
+ df.loc[df['inat21_filename'].notna(), 'data_source'] = 'iNat21'
99
+ df.loc[df['bioscan_filename'].notna(), 'data_source'] = 'BIOSCAN'
100
+ df.loc[df['eol_content_id'].notna(), 'data_source'] = 'EOL'
101
+
102
+ # %% [markdown]
103
+ # First, check their unique class values (`common`).
104
+
105
+ # %%
106
+ df.loc[df['data_source'] == 'EOL', 'common'].nunique()
107
+
108
+ # %% [markdown]
109
+ # EOL number of unique classes is 439,910 in the webdataset, so we do lose 386...
110
+
111
+ # %% [markdown]
112
+ # Make `df_taxa` with just taxa columns (+ `common` & `data_source`) so it's smaller to process faster.
113
+
114
+ # %%
115
+ taxa_com = list(df.columns[9:17]) # taxa + common
116
+ taxa_com.insert(0, 'data_source')
117
+ df_taxa = df[taxa_com]
118
+
119
+ # %%
120
+ df_taxa.head()
121
+
122
+ # %% [markdown]
123
+ # Let's look a little closer at EOL.
124
+
125
+ # %%
126
+ inat21_df = df_taxa.loc[df_taxa.data_source == 'iNat21']
127
+ bioscan_df = df_taxa.loc[df_taxa.data_source == 'BIOSCAN']
128
+ eol_df = df_taxa.loc[df_taxa.data_source == 'EOL']
129
+
130
+ # %% [markdown]
131
+ # ### EOL
132
+
133
+ # %%
134
+ eol_df.info(show_counts = True)
135
+
136
+ # %%
137
+ eol_df.nunique()
138
+
139
+ # %% [markdown]
140
+ # It seems the webdataset loses 5 families, 39 genera, and 84 species. As noted above, 386 common labels are lost.
141
+
142
+ # %% [markdown]
143
+ # There are no missing species that get lost, as observed above, all lost entries have all taxonomic labels.
144
+
145
+ # %%
146
+ #number of unique 7-tuples in EOL
147
+ eol_df['duplicate'] = eol_df.duplicated(subset = taxa, keep = 'first')
148
+ eol_df_unique_taxa = eol_df.loc[~eol_df['duplicate']]
149
+
150
+ # %%
151
+ eol_df_unique_taxa.info(show_counts = True)
152
+
153
+ # %% [markdown]
154
+ # 400 unique taxa are lost.
155
+
156
+ # %% [markdown]
157
+ # Let's check the `species` length in EOL as well, we know there are some that have genus-species. And others with hybrids that get VERY long.
158
+ #
159
+ # Wonder if this is where we lose some?
160
+ # Quick check in the catalog notebook shows there are still plenty with full taxa there.
161
+
162
+ # %%