Analysis of updated datset.
Browse files- notebooks/ToL_stats_EDA.ipynb +0 -0
- notebooks/ToL_stats_EDA.py +85 -102
notebooks/ToL_stats_EDA.ipynb
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
notebooks/ToL_stats_EDA.py
CHANGED
|
@@ -30,29 +30,38 @@ df.head()
|
|
| 30 |
df.info(show_counts = True)
|
| 31 |
|
| 32 |
# %% [markdown]
|
| 33 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
#
|
| 35 |
-
# Labeling definitely has far better coverage
|
| 36 |
|
| 37 |
# %%
|
| 38 |
df.nunique()
|
| 39 |
|
| 40 |
# %% [markdown]
|
| 41 |
-
# There are
|
| 42 |
|
| 43 |
# %% [markdown]
|
| 44 |
-
# Notice that we have 7 unique kingdoms,
|
| 45 |
|
| 46 |
# %%
|
| 47 |
df['kingdom'].value_counts()
|
| 48 |
|
| 49 |
# %% [markdown]
|
| 50 |
-
# `Metazoa` and `Archaeplastida` have been replaced by `Animalia` and `Plantae`.
|
| 51 |
#
|
| 52 |
# We now have other single-celled organisms for kingdom
|
| 53 |
|
| 54 |
# %%
|
| 55 |
-
taxa = list(df.columns[
|
| 56 |
taxa
|
| 57 |
|
| 58 |
# %% [markdown]
|
|
@@ -63,39 +72,39 @@ df_all_taxa = df.dropna(subset = taxa)
|
|
| 63 |
df_all_taxa[taxa].info(show_counts = True)
|
| 64 |
|
| 65 |
# %% [markdown]
|
| 66 |
-
# We have
|
| 67 |
#
|
| 68 |
-
# Notice that we 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.
|
| 69 |
#
|
| 70 |
-
# We did hit
|
| 71 |
|
| 72 |
# %% [markdown]
|
| 73 |
-
# More detail on these missing values from [`check_taxa` script](https://github.com/Imageomics/open_clip/blob/main/scripts/evobio10m/check_taxa.py)
|
| 74 |
#
|
| 75 |
# ```
|
| 76 |
-
# [2023-10-
|
| 77 |
-
# [2023-10-
|
| 78 |
-
# [2023-10-
|
| 79 |
-
# [2023-10-
|
| 80 |
-
# [2023-10-
|
| 81 |
-
# [2023-10-
|
| 82 |
-
# [2023-10-
|
| 83 |
-
# [2023-10-
|
| 84 |
-
# [2023-10-
|
| 85 |
-
# [2023-10-
|
| 86 |
-
# [2023-10-
|
| 87 |
-
# [2023-10-
|
| 88 |
-
# [2023-10-
|
| 89 |
-
# [2023-10-
|
| 90 |
-
# [2023-10-
|
| 91 |
-
# [2023-10-
|
| 92 |
-
# [2023-10-
|
| 93 |
-
# [2023-10-
|
| 94 |
-
# [2023-10-
|
| 95 |
# ```
|
| 96 |
|
| 97 |
# %% [markdown]
|
| 98 |
-
# Can we get some more information on those
|
| 99 |
|
| 100 |
# %%
|
| 101 |
missing_genus = df.dropna(subset = ['kingdom', 'phylum', 'class', 'order', 'family', 'species'])
|
|
@@ -110,6 +119,9 @@ print("The taxa missing genus are: ")
|
|
| 110 |
for taxon in taxa:
|
| 111 |
print(taxon, ": ", missing_genus[taxon].unique())
|
| 112 |
|
|
|
|
|
|
|
|
|
|
| 113 |
# %% [markdown]
|
| 114 |
# Let's add a column indicating the original data source so we can also get some stats by datasource.
|
| 115 |
|
|
@@ -120,13 +132,13 @@ df.loc[df['bioscan_filename'].notna(), 'data_source'] = 'BIOSCAN'
|
|
| 120 |
df.loc[df['eol_content_id'].notna(), 'data_source'] = 'EOL'
|
| 121 |
|
| 122 |
# %%
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
missing_genus.data_source.unique()
|
| 127 |
|
| 128 |
# %% [markdown]
|
| 129 |
-
# Missing genus with all other taxa occurs in
|
| 130 |
|
| 131 |
# %% [markdown]
|
| 132 |
# First, check their unique class values (`common`).
|
|
@@ -141,15 +153,17 @@ df.loc[df['data_source'] == 'iNat21', 'common'].nunique()
|
|
| 141 |
df.loc[df['data_source'] == 'BIOSCAN', 'common'].nunique()
|
| 142 |
|
| 143 |
# %% [markdown]
|
| 144 |
-
# iNat's number of unique values in `common`
|
|
|
|
|
|
|
| 145 |
#
|
| 146 |
-
# BIOSCAN
|
| 147 |
|
| 148 |
# %% [markdown]
|
| 149 |
# Make `df_taxa` with just taxa columns (+ `common` & `data_source`) so it's smaller to process faster.
|
| 150 |
|
| 151 |
# %%
|
| 152 |
-
taxa_com = list(df.columns[
|
| 153 |
taxa_com.insert(0, 'data_source')
|
| 154 |
df_taxa = df[taxa_com]
|
| 155 |
|
|
@@ -171,7 +185,7 @@ eol_df = df_taxa.loc[df_taxa.data_source == 'EOL']
|
|
| 171 |
inat21_df.info(show_counts = True)
|
| 172 |
|
| 173 |
# %% [markdown]
|
| 174 |
-
# iNat21 isn't missing anything, as expected, and we have 2,
|
| 175 |
#
|
| 176 |
# Quick view of diversity in iNat21.
|
| 177 |
|
|
@@ -205,13 +219,15 @@ inat21_df_unique_taxa.info(show_counts = True)
|
|
| 205 |
bioscan_df.info(show_counts = True)
|
| 206 |
|
| 207 |
# %% [markdown]
|
| 208 |
-
# All images are labeled down to `order`, most (98.6%) are labeled to the `family` level, but we only have 22.5% and 7.5% with `genus` or `species` level designation, respectively.
|
|
|
|
|
|
|
| 209 |
|
| 210 |
# %%
|
| 211 |
bioscan_df.nunique()
|
| 212 |
|
| 213 |
# %% [markdown]
|
| 214 |
-
# We
|
| 215 |
|
| 216 |
# %%
|
| 217 |
bioscan_df['kingdom'].value_counts()
|
|
@@ -235,7 +251,7 @@ bioscan_df.loc[bioscan_df['genus'].notna()].sample(7)
|
|
| 235 |
bioscan_df.loc[bioscan_df['genus'].isna()].sample(7)
|
| 236 |
|
| 237 |
# %% [markdown]
|
| 238 |
-
# When the `genus` is null, we
|
| 239 |
|
| 240 |
# %%
|
| 241 |
#number of unique 7-tuples in BIOSCAN
|
|
@@ -246,23 +262,22 @@ bioscan_df_unique_taxa = bioscan_df.loc[~bioscan_df['duplicate']]
|
|
| 246 |
bioscan_df_unique_taxa.info(show_counts = True)
|
| 247 |
|
| 248 |
# %% [markdown]
|
| 249 |
-
#
|
| 250 |
-
|
| 251 |
-
# %%
|
| 252 |
-
bioscan_df.loc[bioscan_df.species.notna()].info(show_counts = True)
|
| 253 |
|
| 254 |
# %% [markdown]
|
| 255 |
-
#
|
| 256 |
|
| 257 |
# %%
|
| 258 |
-
bioscan_df.loc[
|
| 259 |
|
| 260 |
|
| 261 |
# %% [markdown]
|
| 262 |
-
#
|
| 263 |
|
| 264 |
# %% [markdown]
|
| 265 |
-
# In general, when the species is listed in BIOSCAN it is listed as `genus-species`.
|
|
|
|
|
|
|
| 266 |
#
|
| 267 |
# Let's check those stats again, we did confirm it earlier, but would also like to check EOL as it had a similar issue for some entries.
|
| 268 |
|
|
@@ -305,7 +320,7 @@ bioscan_long_species = bioscan_species_len_df.loc[bioscan_species_len_df["len_sp
|
|
| 305 |
bioscan_long_species.info(show_counts = True)
|
| 306 |
|
| 307 |
# %% [markdown]
|
| 308 |
-
# Not all species indicated have length greater than 1 now.
|
| 309 |
|
| 310 |
# %%
|
| 311 |
bioscan_species_len_df.len_species.value_counts()
|
|
@@ -322,11 +337,8 @@ bioscan_long_species.sample(7)
|
|
| 322 |
# %%
|
| 323 |
bioscan_long_species.loc[bioscan_long_species['len_species'] > 2].sample(10)
|
| 324 |
|
| 325 |
-
# %%
|
| 326 |
-
bioscan_df.loc[bioscan_df["genus"] == "Psychoda", "species"].unique()
|
| 327 |
-
|
| 328 |
# %% [markdown]
|
| 329 |
-
#
|
| 330 |
|
| 331 |
# %% [markdown]
|
| 332 |
# It would seem the "sp. ..." is used to indicate they are likely the same species, though the actual species is not designated (either unnamed or undetermined). This is information we should retain, but the duplicated genus can be removed.
|
|
@@ -344,9 +356,9 @@ eol_df.nunique()
|
|
| 344 |
eol_df.loc[eol_df.species.isna()].nunique()
|
| 345 |
|
| 346 |
# %% [markdown]
|
| 347 |
-
# There are
|
| 348 |
#
|
| 349 |
-
# Unique species + unique common where species is null (
|
| 350 |
|
| 351 |
# %%
|
| 352 |
eol_df['kingdom'].value_counts()
|
|
@@ -354,7 +366,7 @@ eol_df['kingdom'].value_counts()
|
|
| 354 |
# %% [markdown]
|
| 355 |
# We have much greater kingdom variety here.
|
| 356 |
#
|
| 357 |
-
# 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.
|
| 358 |
|
| 359 |
# %%
|
| 360 |
#number of unique 7-tuples in EOL
|
|
@@ -365,15 +377,17 @@ eol_df_unique_taxa = eol_df.loc[~eol_df['duplicate']]
|
|
| 365 |
eol_df_unique_taxa.info(show_counts = True)
|
| 366 |
|
| 367 |
# %% [markdown]
|
| 368 |
-
#
|
| 369 |
#
|
| 370 |
-
#
|
| 371 |
|
| 372 |
# %%
|
| 373 |
eol_df.loc[eol_df.species.notna()].info(show_counts = True)
|
| 374 |
|
| 375 |
# %% [markdown]
|
| 376 |
# 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)).
|
|
|
|
|
|
|
| 377 |
|
| 378 |
# %% [markdown]
|
| 379 |
# Let's get a quick sample of the `common` column for images both with and without `species` labels.
|
|
@@ -390,46 +404,7 @@ eol_df.loc[eol_df.species.notna()].sample(7)
|
|
| 390 |
eol_df.loc[eol_df.species.isna()].sample(7)
|
| 391 |
|
| 392 |
# %% [markdown]
|
| 393 |
-
#
|
| 394 |
-
#
|
| 395 |
-
# From original check:
|
| 396 |
-
# All `common` values are filled in with predominently common names. It seems we could map these back to some level of taxa with the taxon-common matching? Though why would these EOL images have common without any other designation?
|
| 397 |
-
#
|
| 398 |
-
# Good example of strange inconsistency: the `American red raspberry` is `Rubus strigosus`, and a quick Google search easily provides the entire taxonomy.
|
| 399 |
-
#
|
| 400 |
-
# `Cremastobaeus` seems to be a genus of wasp.
|
| 401 |
-
|
| 402 |
-
# %%
|
| 403 |
-
eol_df.loc[eol_df.common == "American red raspberry"]
|
| 404 |
-
|
| 405 |
-
# %%
|
| 406 |
-
eol_df.loc[eol_df.common == "Rubus strigosus"]
|
| 407 |
-
|
| 408 |
-
# %% [markdown]
|
| 409 |
-
# We seem to have lost the raspberry...
|
| 410 |
-
|
| 411 |
-
# %%
|
| 412 |
-
eol_df.loc[eol_df.species == "strigosus"]
|
| 413 |
-
|
| 414 |
-
# %%
|
| 415 |
-
eol_df_unique_taxa.loc[eol_df_unique_taxa.species == "strigosus"]
|
| 416 |
-
|
| 417 |
-
# %% [markdown]
|
| 418 |
-
# It seems likely the row with the null values is our lost raspberry.
|
| 419 |
-
#
|
| 420 |
-
# Also good evidence of the duplication of species names across kingdoms and other taxa.
|
| 421 |
-
|
| 422 |
-
# %% [markdown]
|
| 423 |
-
# Rubus strigosus is apparently a subspecies of "Rubus idaeus", and we are not looking at the subspecies level.
|
| 424 |
-
|
| 425 |
-
# %%
|
| 426 |
-
eol_df_unique_taxa.loc[eol_df_unique_taxa.species == "idaeus"]
|
| 427 |
-
|
| 428 |
-
# %% [markdown]
|
| 429 |
-
# Though the question remains, why did we lose the common name?
|
| 430 |
-
|
| 431 |
-
# %% [markdown]
|
| 432 |
-
# Let's check the `species` length in EOL as well, we know there are some that have genus-species.
|
| 433 |
|
| 434 |
# %%
|
| 435 |
eol_species_len = check_sci_name(eol_df)
|
|
@@ -446,9 +421,11 @@ eol_long_species.info(show_counts = True)
|
|
| 446 |
eol_long_species.len_species.value_counts()
|
| 447 |
|
| 448 |
# %% [markdown]
|
| 449 |
-
#
|
| 450 |
#
|
| 451 |
# Why are some more than 10 words long?
|
|
|
|
|
|
|
| 452 |
|
| 453 |
# %%
|
| 454 |
eol_long_species.loc[eol_long_species["len_species"] > 7].sample(7)
|
|
@@ -456,11 +433,17 @@ eol_long_species.loc[eol_long_species["len_species"] > 7].sample(7)
|
|
| 456 |
# %%
|
| 457 |
eol_long_species.nunique()
|
| 458 |
|
|
|
|
|
|
|
|
|
|
| 459 |
# %%
|
| 460 |
eol_long_species.loc[eol_long_species["len_species"] < 7].sample(7)
|
| 461 |
|
| 462 |
# %% [markdown]
|
| 463 |
-
#
|
|
|
|
|
|
|
|
|
|
| 464 |
|
| 465 |
# %% [markdown]
|
| 466 |
# ### Label Overlap Check
|
|
@@ -523,7 +506,7 @@ avg_std
|
|
| 523 |
avg_std.to_csv("../data/stats_avg_std_byClass.csv", index = False)
|
| 524 |
|
| 525 |
# %% [markdown]
|
| 526 |
-
# Observe that the Plant and Animal `kingdom`s are actually much more heavily represented than Fungi.
|
| 527 |
|
| 528 |
# %%
|
| 529 |
sns.set(rc = {'figure.figsize': (10,6)})
|
|
|
|
| 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 |
+
# 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 |
#
|
| 61 |
# We now have other single-celled organisms for kingdom
|
| 62 |
|
| 63 |
# %%
|
| 64 |
+
taxa = list(df.columns[9:16])
|
| 65 |
taxa
|
| 66 |
|
| 67 |
# %% [markdown]
|
|
|
|
| 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'])
|
|
|
|
| 119 |
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.
|
| 127 |
|
|
|
|
| 132 |
df.loc[df['eol_content_id'].notna(), 'data_source'] = 'EOL'
|
| 133 |
|
| 134 |
# %%
|
| 135 |
+
# re-do missing genus with the data source to check if it's just EOL or Bioscan too
|
| 136 |
+
missing_genus = df.dropna(subset = ['kingdom', 'phylum', 'class', 'order', 'family', 'species'])
|
| 137 |
+
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`).
|
|
|
|
| 153 |
df.loc[df['data_source'] == 'BIOSCAN', 'common'].nunique()
|
| 154 |
|
| 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.
|
| 164 |
|
| 165 |
# %%
|
| 166 |
+
taxa_com = list(df.columns[9:17]) # taxa + common
|
| 167 |
taxa_com.insert(0, 'data_source')
|
| 168 |
df_taxa = df[taxa_com]
|
| 169 |
|
|
|
|
| 185 |
inat21_df.info(show_counts = True)
|
| 186 |
|
| 187 |
# %% [markdown]
|
| 188 |
+
# iNat21 isn't missing anything, as expected, and we have 2,686,843 images.
|
| 189 |
#
|
| 190 |
# Quick view of diversity in iNat21.
|
| 191 |
|
|
|
|
| 219 |
bioscan_df.info(show_counts = True)
|
| 220 |
|
| 221 |
# %% [markdown]
|
| 222 |
+
# All images are labeled down to `order`, most (98.6%) are labeled to the `family` level, but we only have 22.5% and 7.5% with `genus` or `species` level designation, respectively.
|
| 223 |
+
#
|
| 224 |
+
# There seems to be 1 less genus from the original and 3 less species...
|
| 225 |
|
| 226 |
# %%
|
| 227 |
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()
|
|
|
|
| 251 |
bioscan_df.loc[bioscan_df['genus'].isna()].sample(7)
|
| 252 |
|
| 253 |
# %% [markdown]
|
| 254 |
+
# When the `genus` is null, we again have `common` as a list of all higher order taxa available.
|
| 255 |
|
| 256 |
# %%
|
| 257 |
#number of unique 7-tuples in BIOSCAN
|
|
|
|
| 262 |
bioscan_df_unique_taxa.info(show_counts = True)
|
| 263 |
|
| 264 |
# %% [markdown]
|
| 265 |
+
# 7,831 unique.
|
|
|
|
|
|
|
|
|
|
| 266 |
|
| 267 |
# %% [markdown]
|
| 268 |
+
# We should be able to fill all in for all values of `species` that also have `genus` indicated since they are all in `Animalia`. Is `genus` labeled for all entries with `species` labeled?
|
| 269 |
|
| 270 |
# %%
|
| 271 |
+
bioscan_df.loc[bioscan_df.species.notna()].info(show_counts = True)
|
| 272 |
|
| 273 |
|
| 274 |
# %% [markdown]
|
| 275 |
+
# All resolved now.
|
| 276 |
|
| 277 |
# %% [markdown]
|
| 278 |
+
# In general, when the species is listed in BIOSCAN it is listed as `genus-species`.
|
| 279 |
+
#
|
| 280 |
+
# This should have been resolved.
|
| 281 |
#
|
| 282 |
# Let's check those stats again, we did confirm it earlier, but would also like to check EOL as it had a similar issue for some entries.
|
| 283 |
|
|
|
|
| 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()
|
|
|
|
| 337 |
# %%
|
| 338 |
bioscan_long_species.loc[bioscan_long_species['len_species'] > 2].sample(10)
|
| 339 |
|
|
|
|
|
|
|
|
|
|
| 340 |
# %% [markdown]
|
| 341 |
+
# This looks like about what we expected.
|
| 342 |
|
| 343 |
# %% [markdown]
|
| 344 |
# It would seem the "sp. ..." is used to indicate they are likely the same species, though the actual species is not designated (either unnamed or undetermined). This is information we should retain, but the duplicated genus can be removed.
|
|
|
|
| 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 |
# %% [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
|
|
|
|
| 377 |
eol_df_unique_taxa.info(show_counts = True)
|
| 378 |
|
| 379 |
# %% [markdown]
|
| 380 |
+
# This is quite a good number of unqiue taxa.
|
| 381 |
#
|
| 382 |
+
# Is `genus` labeled for all entries with `species` labeled?
|
| 383 |
|
| 384 |
# %%
|
| 385 |
eol_df.loc[eol_df.species.notna()].info(show_counts = True)
|
| 386 |
|
| 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.
|
|
|
|
| 404 |
eol_df.loc[eol_df.species.isna()].sample(7)
|
| 405 |
|
| 406 |
# %% [markdown]
|
| 407 |
+
# 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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
|
| 409 |
# %%
|
| 410 |
eol_species_len = check_sci_name(eol_df)
|
|
|
|
| 421 |
eol_long_species.len_species.value_counts()
|
| 422 |
|
| 423 |
# %% [markdown]
|
| 424 |
+
# We have length 2 all the way to 26.
|
| 425 |
#
|
| 426 |
# Why are some more than 10 words long?
|
| 427 |
+
# - Seem to be hybrids, getting genus added now
|
| 428 |
+
# - We have one that says "Bee"... it was "bee bees ntomology apoidea extrememarco insects..."
|
| 429 |
|
| 430 |
# %%
|
| 431 |
eol_long_species.loc[eol_long_species["len_species"] > 7].sample(7)
|
|
|
|
| 433 |
# %%
|
| 434 |
eol_long_species.nunique()
|
| 435 |
|
| 436 |
+
# %% [markdown]
|
| 437 |
+
# Genus was filled out much more from the last iteration (from only 47 to 8,587 unique instances), also doesn't have any nulls now (pulling that first word from species column).
|
| 438 |
+
|
| 439 |
# %%
|
| 440 |
eol_long_species.loc[eol_long_species["len_species"] < 7].sample(7)
|
| 441 |
|
| 442 |
# %% [markdown]
|
| 443 |
+
# There are inconsistencies we likely can't resolve, some have names following the species (in the scientific name standard format of genus-species-namer-year) while others have "sp. __ " which is often used to indicate unknown species (pronounced "spa"), but the following bit may be used to indicate multiple images with unknown species are likely of the same species.
|
| 444 |
+
#
|
| 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
|
|
|
|
| 506 |
avg_std.to_csv("../data/stats_avg_std_byClass.csv", index = False)
|
| 507 |
|
| 508 |
# %% [markdown]
|
| 509 |
+
# Observe that the Plant and Animal `kingdom`s are actually much more heavily represented than Fungi (it didn't look this way before we standardized the kingdoms).
|
| 510 |
|
| 511 |
# %%
|
| 512 |
sns.set(rc = {'figure.figsize': (10,6)})
|