"
+ ],
+ "text/plain": [
+ " data_source kingdom phylum class order \n",
+ "6904104 BIOSCAN Animalia Arthropoda Insecta Hymenoptera \\\n",
+ "6270138 BIOSCAN Animalia Arthropoda Insecta Diptera \n",
+ "7019868 BIOSCAN Animalia Arthropoda Insecta Diptera \n",
+ "6188618 BIOSCAN Animalia Arthropoda Insecta Diptera \n",
+ "6250382 BIOSCAN Animalia Arthropoda Insecta Diptera \n",
+ "6547010 BIOSCAN Animalia Arthropoda Insecta Diptera \n",
+ "6414135 BIOSCAN Animalia Arthropoda Insecta Diptera \n",
+ "4497850 BIOSCAN Animalia Arthropoda Insecta Diptera \n",
+ "6407419 BIOSCAN Animalia Arthropoda Insecta Hymenoptera \n",
+ "6264034 BIOSCAN Animalia Arthropoda Insecta Diptera \n",
+ "\n",
+ " family genus species \n",
+ "6904104 Figitidae Ganaspis sp. 3 tas-2012 \\\n",
+ "6270138 Empididae Porphyrochroa sp. 6 bkc-2015 \n",
+ "7019868 Sciaridae Cosmosciara sp. saevg morph0042 \n",
+ "6188618 Sciaridae Cosmosciara sp. saevg morph0042 \n",
+ "6250382 Sciaridae Cosmosciara sp. saevg morph0042 \n",
+ "6547010 Sciaridae Cosmosciara sp. saevg morph0042 \n",
+ "6414135 Sciaridae Cosmosciara sp. saevg morph0042 \n",
+ "4497850 Clusiidae Sobarocephala sp. 1 ol-2008 \n",
+ "6407419 Ichneumonidae Chilocyrtus sp. 6 nw-2012 \n",
+ "6264034 Sciaridae Cosmosciara sp. saevg morph0042 \n",
+ "\n",
+ " common duplicate len_species \n",
+ "6904104 Ganaspis sp. 3 tas-2012 True 3 \n",
+ "6270138 Porphyrochroa sp. 6 bkc-2015 True 3 \n",
+ "7019868 Cosmosciara sp. saevg morph0042 True 3 \n",
+ "6188618 Cosmosciara sp. saevg morph0042 True 3 \n",
+ "6250382 Cosmosciara sp. saevg morph0042 True 3 \n",
+ "6547010 Cosmosciara sp. saevg morph0042 True 3 \n",
+ "6414135 Cosmosciara sp. saevg morph0042 True 3 \n",
+ "4497850 Sobarocephala sp. 1 ol-2008 True 3 \n",
+ "6407419 Chilocyrtus sp. 6 nw-2012 True 3 \n",
+ "6264034 Cosmosciara sp. saevg morph0042 True 3 "
+ ]
+ },
+ "execution_count": 50,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "bioscan_long_species.loc[bioscan_long_species['len_species'] > 2].sample(10)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 49,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array(['albipennis', nan, 'trinodulosa', 'satchelli', 'alternata',\n",
+ " 'phalaenoides', 'sp. 11gmk', 'minuta', 'grisescens', 'mycophila',\n",
+ " 'erminea', 'setigera', 'sigma', 'uncinula', 'divaricata',\n",
+ " 'uniformata', 'lativentris', 'lobata', 'gemina', 'cinerea'],\n",
+ " dtype=object)"
+ ]
+ },
+ "execution_count": 49,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "bioscan_df.loc[bioscan_df[\"genus\"] == \"Psychoda\", \"species\"].unique()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can see that the case of \"Psychoda\" was resolved appropriately."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "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."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### EOL"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 51,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Index: 5938235 entries, 0 to 9418548\n",
+ "Data columns (total 9 columns):\n",
+ " # Column Non-Null Count Dtype \n",
+ "--- ------ -------------- ----- \n",
+ " 0 data_source 5938235 non-null object\n",
+ " 1 kingdom 5571648 non-null object\n",
+ " 2 phylum 5580961 non-null object\n",
+ " 3 class 5558232 non-null object\n",
+ " 4 order 5555900 non-null object\n",
+ " 5 family 5540731 non-null object\n",
+ " 6 genus 5502151 non-null object\n",
+ " 7 species 5654408 non-null object\n",
+ " 8 common 5853173 non-null object\n",
+ "dtypes: object(9)\n",
+ "memory usage: 453.1+ MB\n"
+ ]
+ }
+ ],
+ "source": [
+ "eol_df.info(show_counts = True)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 52,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "data_source 1\n",
+ "kingdom 7\n",
+ "phylum 90\n",
+ "class 278\n",
+ "order 1318\n",
+ "family 7705\n",
+ "genus 70564\n",
+ "species 163640\n",
+ "common 433308\n",
+ "dtype: int64"
+ ]
+ },
+ "execution_count": 52,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "eol_df.nunique()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 53,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "data_source 1\n",
+ "kingdom 7\n",
+ "phylum 88\n",
+ "class 258\n",
+ "order 1145\n",
+ "family 5879\n",
+ "genus 33835\n",
+ "species 0\n",
+ "common 33661\n",
+ "dtype: int64"
+ ]
+ },
+ "execution_count": 53,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "eol_df.loc[eol_df.species.isna()].nunique()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "There are 498,053 (training + val 570,515) unique page IDs from EOL in this training set, which clearly represent varying levels of taxa. \n",
+ "\n",
+ "Unique species + unique common where species is null (197,301) does not reach this number."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 54,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "kingdom\n",
+ "Animalia 3238482\n",
+ "Plantae 2061883\n",
+ "Fungi 251689\n",
+ "Protozoa 10418\n",
+ "Chromista 6401\n",
+ "Bacteria 2752\n",
+ "Archaea 23\n",
+ "Name: count, dtype: int64"
+ ]
+ },
+ "execution_count": 54,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "eol_df['kingdom'].value_counts()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We have much greater kingdom variety here.\n",
+ "\n",
+ "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."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 55,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "/var/folders/nv/f0fq1p1n1_3b11x579py_0q80000gq/T/ipykernel_52067/52183210.py:2: SettingWithCopyWarning: \n",
+ "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+ "Try using .loc[row_indexer,col_indexer] = value instead\n",
+ "\n",
+ "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+ " eol_df['duplicate'] = eol_df.duplicated(subset = taxa, keep = 'first')\n"
+ ]
+ }
+ ],
+ "source": [
+ "#number of unique 7-tuples in EOL\n",
+ "eol_df['duplicate'] = eol_df.duplicated(subset = taxa, keep = 'first')\n",
+ "eol_df_unique_taxa = eol_df.loc[~eol_df['duplicate']]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 56,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Index: 446296 entries, 0 to 9418342\n",
+ "Data columns (total 10 columns):\n",
+ " # Column Non-Null Count Dtype \n",
+ "--- ------ -------------- ----- \n",
+ " 0 data_source 446296 non-null object\n",
+ " 1 kingdom 396034 non-null object\n",
+ " 2 phylum 399665 non-null object\n",
+ " 3 class 398234 non-null object\n",
+ " 4 order 399012 non-null object\n",
+ " 5 family 399068 non-null object\n",
+ " 6 genus 396062 non-null object\n",
+ " 7 species 407486 non-null object\n",
+ " 8 common 441470 non-null object\n",
+ " 9 duplicate 446296 non-null bool \n",
+ "dtypes: bool(1), object(9)\n",
+ "memory usage: 34.5+ MB\n"
+ ]
+ }
+ ],
+ "source": [
+ "eol_df_unique_taxa.info(show_counts = True)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The actual number of distinct creatures is likely higher, as evidenced below where we have unique common names listed in `common` but all taxa are null.\n",
+ "\n",
+ "We should be able to fill all in for all values of `species` that also have `genus` indicated. Is `genus` labeled for all entries with `species` labeled? "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 57,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Index: 5654408 entries, 0 to 9418548\n",
+ "Data columns (total 10 columns):\n",
+ " # Column Non-Null Count Dtype \n",
+ "--- ------ -------------- ----- \n",
+ " 0 data_source 5654408 non-null object\n",
+ " 1 kingdom 5290838 non-null object\n",
+ " 2 phylum 5298696 non-null object\n",
+ " 3 class 5289856 non-null object\n",
+ " 4 order 5294233 non-null object\n",
+ " 5 family 5296633 non-null object\n",
+ " 6 genus 5303386 non-null object\n",
+ " 7 species 5654408 non-null object\n",
+ " 8 common 5654408 non-null object\n",
+ " 9 duplicate 5654408 non-null bool \n",
+ "dtypes: bool(1), object(9)\n",
+ "memory usage: 436.8+ MB\n"
+ ]
+ }
+ ],
+ "source": [
+ "eol_df.loc[eol_df.species.notna()].info(show_counts = True)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "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))."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's get a quick sample of the `common` column for images both with and without `species` labels. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 58,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
data_source
\n",
+ "
kingdom
\n",
+ "
phylum
\n",
+ "
class
\n",
+ "
order
\n",
+ "
family
\n",
+ "
genus
\n",
+ "
species
\n",
+ "
common
\n",
+ "
duplicate
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "
\n",
+ "
83610
\n",
+ "
EOL
\n",
+ "
Plantae
\n",
+ "
Tracheophyta
\n",
+ "
Magnoliopsida
\n",
+ "
Geraniales
\n",
+ "
Geraniaceae
\n",
+ "
Geranium
\n",
+ "
potentilloides
\n",
+ "
cinquefoil geranium
\n",
+ "
False
\n",
+ "
\n",
+ "
\n",
+ "
3895894
\n",
+ "
EOL
\n",
+ "
Animalia
\n",
+ "
Chordata
\n",
+ "
Aves
\n",
+ "
Passeriformes
\n",
+ "
Fringillidae
\n",
+ "
Crithagra
\n",
+ "
totta
\n",
+ "
Cape Siskin
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
1225507
\n",
+ "
EOL
\n",
+ "
Animalia
\n",
+ "
Echinodermata
\n",
+ "
Echinoidea
\n",
+ "
Cidaroida
\n",
+ "
Ctenocidaridae
\n",
+ "
Aporocidaris
\n",
+ "
milleri
\n",
+ "
miller's sea urchin
\n",
+ "
False
\n",
+ "
\n",
+ "
\n",
+ "
2893186
\n",
+ "
EOL
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Lepidoptera
\n",
+ "
Tortricidae
\n",
+ "
Oriodryas
\n",
+ "
olbophora
\n",
+ "
Oriodryas olbophora
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
849135
\n",
+ "
EOL
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hymenoptera
\n",
+ "
Apidae
\n",
+ "
Bombus
\n",
+ "
latreille
\n",
+ "
Bombus latreille
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
2800177
\n",
+ "
EOL
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hymenoptera
\n",
+ "
Apidae
\n",
+ "
Bombus
\n",
+ "
balteatus
\n",
+ "
High Country Bumble Bee
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
1568547
\n",
+ "
EOL
\n",
+ "
Plantae
\n",
+ "
Tracheophyta
\n",
+ "
Magnoliopsida
\n",
+ "
Boraginales
\n",
+ "
Boraginaceae
\n",
+ "
Tiquilia
\n",
+ "
palmeri
\n",
+ "
Palmer's coldenia
\n",
+ "
True
\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " data_source kingdom phylum class order \n",
+ "83610 EOL Plantae Tracheophyta Magnoliopsida Geraniales \\\n",
+ "3895894 EOL Animalia Chordata Aves Passeriformes \n",
+ "1225507 EOL Animalia Echinodermata Echinoidea Cidaroida \n",
+ "2893186 EOL Animalia Arthropoda Insecta Lepidoptera \n",
+ "849135 EOL Animalia Arthropoda Insecta Hymenoptera \n",
+ "2800177 EOL Animalia Arthropoda Insecta Hymenoptera \n",
+ "1568547 EOL Plantae Tracheophyta Magnoliopsida Boraginales \n",
+ "\n",
+ " family genus species \n",
+ "83610 Geraniaceae Geranium potentilloides \\\n",
+ "3895894 Fringillidae Crithagra totta \n",
+ "1225507 Ctenocidaridae Aporocidaris milleri \n",
+ "2893186 Tortricidae Oriodryas olbophora \n",
+ "849135 Apidae Bombus latreille \n",
+ "2800177 Apidae Bombus balteatus \n",
+ "1568547 Boraginaceae Tiquilia palmeri \n",
+ "\n",
+ " common duplicate \n",
+ "83610 cinquefoil geranium False \n",
+ "3895894 Cape Siskin True \n",
+ "1225507 miller's sea urchin False \n",
+ "2893186 Oriodryas olbophora True \n",
+ "849135 Bombus latreille True \n",
+ "2800177 High Country Bumble Bee True \n",
+ "1568547 Palmer's coldenia True "
+ ]
+ },
+ "execution_count": 58,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# existing species label\n",
+ "eol_df.loc[eol_df.species.notna()].sample(7)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Good, some of these do have common names. We could check numbers of `common` where it doesn't match the `genus-species` form for a better count, but our random sample is promising."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 59,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
data_source
\n",
+ "
kingdom
\n",
+ "
phylum
\n",
+ "
class
\n",
+ "
order
\n",
+ "
family
\n",
+ "
genus
\n",
+ "
species
\n",
+ "
common
\n",
+ "
duplicate
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "
\n",
+ "
5338130
\n",
+ "
EOL
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hemiptera
\n",
+ "
Nabidae
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
1305998
\n",
+ "
EOL
\n",
+ "
Plantae
\n",
+ "
Rhodophyta
\n",
+ "
Florideophyceae
\n",
+ "
Nemaliales
\n",
+ "
Scinaiaceae
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
False
\n",
+ "
\n",
+ "
\n",
+ "
4262302
\n",
+ "
EOL
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Arachnida
\n",
+ "
Opiliones
\n",
+ "
Triaenonychidae
\n",
+ "
Hendea
\n",
+ "
NaN
\n",
+ "
Hendea
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
1653054
\n",
+ "
EOL
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hymenoptera
\n",
+ "
Formicidae
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
5999708
\n",
+ "
EOL
\n",
+ "
Animalia
\n",
+ "
Chordata
\n",
+ "
Aves
\n",
+ "
Passeriformes
\n",
+ "
Pipridae
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
1034526
\n",
+ "
EOL
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Thysanoptera
\n",
+ "
Phlaeothripidae
\n",
+ "
Elaphrothrips
\n",
+ "
NaN
\n",
+ "
Elaphrothrips
\n",
+ "
False
\n",
+ "
\n",
+ "
\n",
+ "
5917965
\n",
+ "
EOL
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hymenoptera
\n",
+ "
Formicidae
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
True
\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " data_source kingdom phylum class order \n",
+ "5338130 EOL Animalia Arthropoda Insecta Hemiptera \\\n",
+ "1305998 EOL Plantae Rhodophyta Florideophyceae Nemaliales \n",
+ "4262302 EOL Animalia Arthropoda Arachnida Opiliones \n",
+ "1653054 EOL Animalia Arthropoda Insecta Hymenoptera \n",
+ "5999708 EOL Animalia Chordata Aves Passeriformes \n",
+ "1034526 EOL Animalia Arthropoda Insecta Thysanoptera \n",
+ "5917965 EOL Animalia Arthropoda Insecta Hymenoptera \n",
+ "\n",
+ " family genus species common duplicate \n",
+ "5338130 Nabidae NaN NaN NaN True \n",
+ "1305998 Scinaiaceae NaN NaN NaN False \n",
+ "4262302 Triaenonychidae Hendea NaN Hendea True \n",
+ "1653054 Formicidae NaN NaN NaN True \n",
+ "5999708 Pipridae NaN NaN NaN True \n",
+ "1034526 Phlaeothripidae Elaphrothrips NaN Elaphrothrips False \n",
+ "5917965 Formicidae NaN NaN NaN True "
+ ]
+ },
+ "execution_count": 59,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# No species label\n",
+ "eol_df.loc[eol_df.species.isna()].sample(7)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Here are a lot of higher-order taxa missing species...let's check for the details noted below.\n",
+ "\n",
+ "From original check:\n",
+ "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?\n",
+ "\n",
+ "Good example of strange inconsistency: the `American red raspberry` is `Rubus strigosus`, and a quick Google search easily provides the entire taxonomy.\n",
+ "\n",
+ "`Cremastobaeus` seems to be a genus of wasp."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 61,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
"
+ ],
+ "text/plain": [
+ " data_source kingdom phylum class order family \n",
+ "49295 EOL Plantae Tracheophyta Magnoliopsida Rosales Rosaceae \\\n",
+ "4109669 EOL NaN NaN NaN NaN NaN \n",
+ "\n",
+ " genus species common duplicate \n",
+ "49295 Rubus idaeus European red raspberry False \n",
+ "4109669 NaN idaeus Idaeus False "
+ ]
+ },
+ "execution_count": 87,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "eol_df_unique_taxa.loc[eol_df_unique_taxa.species == \"idaeus\"]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Though the question remains, why did we lose the common name?"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's check the `species` length in EOL as well, we know there are some that have genus-species."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 67,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "/var/folders/nv/f0fq1p1n1_3b11x579py_0q80000gq/T/ipykernel_52067/1392676569.py:16: SettingWithCopyWarning: \n",
+ "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+ "Try using .loc[row_indexer,col_indexer] = value instead\n",
+ "\n",
+ "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+ " df[\"len_species\"] = 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Index: 5938235 entries, 0 to 9418548\n",
+ "Data columns (total 11 columns):\n",
+ " # Column Non-Null Count Dtype \n",
+ "--- ------ -------------- ----- \n",
+ " 0 data_source 5938235 non-null object\n",
+ " 1 kingdom 5571648 non-null object\n",
+ " 2 phylum 5580961 non-null object\n",
+ " 3 class 5558232 non-null object\n",
+ " 4 order 5555900 non-null object\n",
+ " 5 family 5540731 non-null object\n",
+ " 6 genus 5502151 non-null object\n",
+ " 7 species 5654408 non-null object\n",
+ " 8 common 5853173 non-null object\n",
+ " 9 duplicate 5938235 non-null bool \n",
+ " 10 len_species 5938235 non-null int64 \n",
+ "dtypes: bool(1), int64(1), object(9)\n",
+ "memory usage: 504.0+ MB\n"
+ ]
+ }
+ ],
+ "source": [
+ "eol_species_len = check_sci_name(eol_df)\n",
+ "eol_species_len.info(show_counts = True)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 68,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Index: 154667 entries, 12 to 9418519\n",
+ "Data columns (total 11 columns):\n",
+ " # Column Non-Null Count Dtype \n",
+ "--- ------ -------------- ----- \n",
+ " 0 data_source 154667 non-null object\n",
+ " 1 kingdom 19 non-null object\n",
+ " 2 phylum 19 non-null object\n",
+ " 3 class 19 non-null object\n",
+ " 4 order 550 non-null object\n",
+ " 5 family 598 non-null object\n",
+ " 6 genus 598 non-null object\n",
+ " 7 species 154667 non-null object\n",
+ " 8 common 154667 non-null object\n",
+ " 9 duplicate 154667 non-null bool \n",
+ " 10 len_species 154667 non-null int64 \n",
+ "dtypes: bool(1), int64(1), object(9)\n",
+ "memory usage: 13.1+ MB\n"
+ ]
+ }
+ ],
+ "source": [
+ "eol_long_species = eol_species_len.loc[eol_species_len[\"len_species\"] > 1]\n",
+ "eol_long_species.info(show_counts = True)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "That's quite a lot with species name longer than 1 word."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 69,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "len_species\n",
+ "3 127298\n",
+ "4 21771\n",
+ "5 4257\n",
+ "8 591\n",
+ "7 354\n",
+ "6 309\n",
+ "10 33\n",
+ "9 24\n",
+ "17 13\n",
+ "11 5\n",
+ "19 4\n",
+ "23 3\n",
+ "18 2\n",
+ "12 1\n",
+ "27 1\n",
+ "16 1\n",
+ "Name: count, dtype: int64"
+ ]
+ },
+ "execution_count": 69,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "eol_long_species.len_species.value_counts()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Observe, we did not wind up with any of length 2, so this issue was partially resolved. \n",
+ "\n",
+ "Why are some more than 10 words long?"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 73,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
data_source
\n",
+ "
kingdom
\n",
+ "
phylum
\n",
+ "
class
\n",
+ "
order
\n",
+ "
family
\n",
+ "
genus
\n",
+ "
species
\n",
+ "
common
\n",
+ "
duplicate
\n",
+ "
len_species
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "
\n",
+ "
5763498
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
tilia platyphyllos x cordata = t. x europaea
\n",
+ "
Tilia platyphyllos x cordata = t. x europaea
\n",
+ "
True
\n",
+ "
8
\n",
+ "
\n",
+ "
\n",
+ "
4764464
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
crataegus monogyna x laevigata = c. x media
\n",
+ "
Crataegus monogyna x laevigata = c. x media
\n",
+ "
True
\n",
+ "
8
\n",
+ "
\n",
+ "
\n",
+ "
5772983
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
tilia platyphyllos x cordata = t. x europaea
\n",
+ "
Tilia platyphyllos x cordata = t. x europaea
\n",
+ "
True
\n",
+ "
8
\n",
+ "
\n",
+ "
\n",
+ "
3485173
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
typha latifolia x angustifolia = t. x glauca
\n",
+ "
Typha latifolia x angustifolia = t. x glauca
\n",
+ "
True
\n",
+ "
8
\n",
+ "
\n",
+ "
\n",
+ "
2434843
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
aster laevis x novi-belgii = a. x versicolor
\n",
+ "
Aster laevis x novi-belgii = a. x versicolor
\n",
+ "
True
\n",
+ "
8
\n",
+ "
\n",
+ "
\n",
+ "
8403779
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
silene latifolia x dioica = s. x hampeana
\n",
+ "
Silene latifolia x dioica = s. x hampeana
\n",
+ "
True
\n",
+ "
8
\n",
+ "
\n",
+ "
\n",
+ "
3782759
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
miliusa montana gardner ex hook. f. & thomson
\n",
+ "
Miliusa montana gardner ex hook. f. & thomson
\n",
+ "
False
\n",
+ "
8
\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " data_source kingdom phylum class order family genus \n",
+ "5763498 EOL NaN NaN NaN NaN NaN NaN \\\n",
+ "4764464 EOL NaN NaN NaN NaN NaN NaN \n",
+ "5772983 EOL NaN NaN NaN NaN NaN NaN \n",
+ "3485173 EOL NaN NaN NaN NaN NaN NaN \n",
+ "2434843 EOL NaN NaN NaN NaN NaN NaN \n",
+ "8403779 EOL NaN NaN NaN NaN NaN NaN \n",
+ "3782759 EOL NaN NaN NaN NaN NaN NaN \n",
+ "\n",
+ " species \n",
+ "5763498 tilia platyphyllos x cordata = t. x europaea \\\n",
+ "4764464 crataegus monogyna x laevigata = c. x media \n",
+ "5772983 tilia platyphyllos x cordata = t. x europaea \n",
+ "3485173 typha latifolia x angustifolia = t. x glauca \n",
+ "2434843 aster laevis x novi-belgii = a. x versicolor \n",
+ "8403779 silene latifolia x dioica = s. x hampeana \n",
+ "3782759 miliusa montana gardner ex hook. f. & thomson \n",
+ "\n",
+ " common duplicate len_species \n",
+ "5763498 Tilia platyphyllos x cordata = t. x europaea True 8 \n",
+ "4764464 Crataegus monogyna x laevigata = c. x media True 8 \n",
+ "5772983 Tilia platyphyllos x cordata = t. x europaea True 8 \n",
+ "3485173 Typha latifolia x angustifolia = t. x glauca True 8 \n",
+ "2434843 Aster laevis x novi-belgii = a. x versicolor True 8 \n",
+ "8403779 Silene latifolia x dioica = s. x hampeana True 8 \n",
+ "3782759 Miliusa montana gardner ex hook. f. & thomson False 8 "
+ ]
+ },
+ "execution_count": 73,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "eol_long_species.loc[eol_long_species[\"len_species\"] > 7].sample(7)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 74,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "data_source 1\n",
+ "kingdom 1\n",
+ "phylum 1\n",
+ "class 1\n",
+ "order 20\n",
+ "family 34\n",
+ "genus 47\n",
+ "species 25161\n",
+ "common 25159\n",
+ "duplicate 2\n",
+ "len_species 16\n",
+ "dtype: int64"
+ ]
+ },
+ "execution_count": 74,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "eol_long_species.nunique()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 76,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
data_source
\n",
+ "
kingdom
\n",
+ "
phylum
\n",
+ "
class
\n",
+ "
order
\n",
+ "
family
\n",
+ "
genus
\n",
+ "
species
\n",
+ "
common
\n",
+ "
duplicate
\n",
+ "
len_species
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "
\n",
+ "
5801145
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
veronica pinnata l.
\n",
+ "
Veronica pinnata l.
\n",
+ "
True
\n",
+ "
3
\n",
+ "
\n",
+ "
\n",
+ "
3106825
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
vanessa gonerilla ida
\n",
+ "
Vanessa gonerilla ida
\n",
+ "
True
\n",
+ "
3
\n",
+ "
\n",
+ "
\n",
+ "
203743
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
adelpha godmani fruhstorfer
\n",
+ "
Adelpha godmani fruhstorfer
\n",
+ "
True
\n",
+ "
3
\n",
+ "
\n",
+ "
\n",
+ "
1210781
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
discophlebia celaena turner
\n",
+ "
Discophlebia celaena turner
\n",
+ "
True
\n",
+ "
3
\n",
+ "
\n",
+ "
\n",
+ "
97965
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
miantonota punctilinea dognin
\n",
+ "
Miantonota punctilinea dognin
\n",
+ "
False
\n",
+ "
3
\n",
+ "
\n",
+ "
\n",
+ "
6129261
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
adelpha paroeca bates
\n",
+ "
Adelpha paroeca bates
\n",
+ "
True
\n",
+ "
3
\n",
+ "
\n",
+ "
\n",
+ "
104169
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
rosa canina group pubescentes
\n",
+ "
Rosa canina group pubescentes
\n",
+ "
False
\n",
+ "
4
\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " data_source kingdom phylum class order family genus \n",
+ "5801145 EOL NaN NaN NaN NaN NaN NaN \\\n",
+ "3106825 EOL NaN NaN NaN NaN NaN NaN \n",
+ "203743 EOL NaN NaN NaN NaN NaN NaN \n",
+ "1210781 EOL NaN NaN NaN NaN NaN NaN \n",
+ "97965 EOL NaN NaN NaN NaN NaN NaN \n",
+ "6129261 EOL NaN NaN NaN NaN NaN NaN \n",
+ "104169 EOL NaN NaN NaN NaN NaN NaN \n",
+ "\n",
+ " species common \n",
+ "5801145 veronica pinnata l. Veronica pinnata l. \\\n",
+ "3106825 vanessa gonerilla ida Vanessa gonerilla ida \n",
+ "203743 adelpha godmani fruhstorfer Adelpha godmani fruhstorfer \n",
+ "1210781 discophlebia celaena turner Discophlebia celaena turner \n",
+ "97965 miantonota punctilinea dognin Miantonota punctilinea dognin \n",
+ "6129261 adelpha paroeca bates Adelpha paroeca bates \n",
+ "104169 rosa canina group pubescentes Rosa canina group pubescentes \n",
+ "\n",
+ " duplicate len_species \n",
+ "5801145 True 3 \n",
+ "3106825 True 3 \n",
+ "203743 True 3 \n",
+ "1210781 True 3 \n",
+ "97965 False 3 \n",
+ "6129261 True 3 \n",
+ "104169 False 4 "
+ ]
+ },
+ "execution_count": 76,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "eol_long_species.loc[eol_long_species[\"len_species\"] < 7].sample(7)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Quick search: \"Adelpha godmani\" is a butterfly with species name given by Fruhstorfer in 1913 ([source](https://butterfliesofamerica.com/L/t/Adelpha_godmani_a.htm))."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Label Overlap Check"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Checking for overlap between the three data sources should give pretty good results, now that most inconsistencies have been addressed.\n",
+ "\n",
+ "For now, let's just take a quick look at genera across the datasets since they are more standardized (and listed more often in BIOSCAN)."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 78,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "there are 70564 genera in EOL\n",
+ "there are 4884 genera in inat21\n",
+ "there are 3407 genera in bioscan\n"
+ ]
+ }
+ ],
+ "source": [
+ "eol_genera = list(eol_df.loc[eol_df['genus'].notna(), 'genus'].unique())\n",
+ "inat21_genera = list(inat21_df.loc[inat21_df['genus'].notna(), 'genus'].unique())\n",
+ "bioscan_genera = list(bioscan_df.loc[bioscan_df['genus'].notna(), 'genus'].unique())\n",
+ "\n",
+ "print(f\"there are {len(eol_genera)} genera in EOL\")\n",
+ "print(f\"there are {len(inat21_genera)} genera in inat21\")\n",
+ "print(f\"there are {len(bioscan_genera)} genera in bioscan\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 79,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "There are 4710 genera shared between EOL and iNat21.\n",
+ "There are 2674 genera shared between EOL and BIOSCAN.\n",
+ "There are 212 genera shared between iNat21 and BIOSCAN.\n",
+ "There are 200 genera shared between all three data sources.\n"
+ ]
+ }
+ ],
+ "source": [
+ "gen_overlap = list(set(eol_genera) & set(inat21_genera))\n",
+ "print(f\"There are {len(gen_overlap)} genera shared between EOL and iNat21.\")\n",
+ "print(f\"There are {len(list(set(eol_genera) & set(bioscan_genera)))} genera shared between EOL and BIOSCAN.\")\n",
+ "print(f\"There are {len(list(set(inat21_genera) & set(bioscan_genera)))} genera shared between iNat21 and BIOSCAN.\")\n",
+ "print(f\"There are {len(list(set(gen_overlap) & set(bioscan_genera)))} genera shared between all three data sources.\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "BIOSCAN and iNat21's overlap of genera is completely contained in EOL."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Overall Stats\n",
+ "\n",
+ "Keep in mind, this is without fixing remaining inconsistencies observed above."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 80,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import numpy as np"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 81,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "avgs_all_images = []\n",
+ "std_all_images = []\n",
+ "avgs_labeled_images = []\n",
+ "std_labeled_images = []\n",
+ "for taxon in taxa_com[1:]: #taxa + common\n",
+ " num_taxon = df[taxon].nunique()\n",
+ " num_img_taxon = len(df.loc[df[taxon].notna()])\n",
+ " avg_all = 10436521/num_taxon\n",
+ " std_all = np.sqrt(10436521/num_taxon)\n",
+ " avg_labeled = num_img_taxon/num_taxon\n",
+ " std_labeled = np.sqrt(num_img_taxon/num_taxon)\n",
+ " avgs_all_images.append(avg_all)\n",
+ " std_all_images.append(std_all)\n",
+ " avgs_labeled_images.append(avg_labeled)\n",
+ " std_labeled_images.append(std_labeled)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 82,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "