Build A Fungus Foraging App With Machine Learning

As the 2019 mushroom foraging season approaches it’s timely to combine my thirst for knowledge about low level machine learning (ML) with a popular pastime that we enjoy here where I live. Just for the record, I’m not an expert on ML, and I’m simply inviting readers to follow me back down some rabbit holes that I recently explored.

But mushrooms, I do know a little bit about, so firstly, a bit about health and safety:

  • The app created should be used with extreme caution and results always confirmed by a fungus expert.
  • Always test the fungus by initially only eating a very small piece and waiting for several hours to check there is no ill effect.
  • Always wear gloves¬† – It’s surprisingly easy to absorb toxins through fingers.

Since this is very much an introduction to ML, there won’t be too much terminology and the emphasis will be on having fun rather than going on a deep dive. The system that I stumbled upon is called XGBoost (XGB). One of the XGB demos is for binary classification, and the data was drawn from The Audubon Society Field Guide to North American Mushrooms. Binary means that the app spits out a probability of ‘yes’ or ‘no’ and in this case it tends to give about 95% probability that a common edible mushroom (Agaricus campestris) is actually edible.¬†

The app asks the user 22 questions about their specimen and collates the data inputted as a series of letters separated by commas. At the end of the questionnaire, this data line is written to a file called ‘fungusFile.data’ for further processing.

XGB can not accept letters as data so they have to be mapped into ‘classic LibSVM format’ which looks like this: ‘3:218’, for each letter. Next, this XGB friendly data is split into two parts for training a model and then subsequently testing that model.

Installing XGB is relatively easy compared to higher level deep learning systems and runs well on both Linux Ubuntu 16.04 and on a Raspberry Pi. I wrote the deployment app in bash so there should not be any additional software to install. Before getting any deeper into the ML side of things, I highly advise installing XGB, running the app, and having a bit of a play with it.

Training and testing is carried out by running bash runexp.sh in the terminal and it takes less than one second to process the 8124 lines of fungal data. At the end, bash spits out a set of statistics to represent the accuracy of the training and also attempts to ‘draw’ the decision tree that XGB has devised. If we have a quick look in directory ~/xgboost/demo/binary_classification, there should now be a 0002.model file in it ready for deployment with the questionnaire.

I was interested to explore the decision tree a bit further and look at the way XGB weighted different characteristics of the fungi. I eventually got some rough visualisations working on a Python based Jupyter Notebook script:

 

 

 

 

 

 

 

Obviously this app is not going to win any Kaggle competitions since the various parameters within the software need to be carefully tuned with the help of all the different software tools available. A good place to start is to tweak the maximum depth of the tree and the number or trees used. Depth = 4 and number = 4 seems to work well for this data. Other parameters include the feature importance type, for example: gain, weight, cover, total_gain or total_cover. These can be tuned using tools such as SHAP.

Finally, this app could easily be adapted to other questionnaire based systems such as diagnosing a particular disease, or deciding whether to buy a particular stock or share in the market place.

An even more basic introduction to ML goes into the baseline theory in a bit more detail – well worth a quick look.

A Lecture By A Fun Guy

Many people hear “fungus” and think of mushrooms. This is akin to hearing “trees” and thinking of apples. Fungus makes up 2% of earth’s total biomass or 10% of the non-plant biomass, and ranges from the deadly to the delicious. This lecture by [Justin Atkin] of [The Thought Emporium] is slightly shorter than a college class period but is like a whole semester’s worth of tidbits, and the lab section is about growing something (potentially) edible rather than a mere demonstration. The video can also be found below the break.

Let’s start with the lab where we learn to grow fungus in a mason jar on purpose for a change. The ingredient list is simple.

  • 2 parts vermiculite
  • 1 part brown rice flour
  • 1 part water
  • Spore syringe

Combine, sterilize, cool, inoculate, and wait. We get distracted when cool things are happening so shopping around for these items was definitely hampered by listening to the lecture portion of the video.

Continue reading “A Lecture By A Fun Guy”

Growing Your Own Insulation

The latest craze in revolutionary materials science is no longer some carbon nanotube, a new mysterious alloy, or biodegradeable plastic. It seems as though a lot of new developments are coming out of the biology world, specifically from mycologists who study fungi. While the jury’s still out on whether or not it’s possible to use fungi to build a decent Star Trek series, researchers have in fact been able to use certain kinds of it to build high-performing insulation.

The insulation is made of the part of the fungus called the mycelium, rather than its more familiar-looking fruiting body. The mycelium is a strand-like structure of fungus which grows through materials in order to digest them. This could be mulch, fruit, logs, straw, crude oil, or even live insects, and you might have noticed it because it’s often white and fuzzy-looking. The particular type of mycelium used here is extremely resistant to changes in temperature so is ideal for making insulation. As a bonus, it can be grown, not manufactured, and can use biological waste products as a growing medium. Further, it can grow to fit the space it’s given, and it is much less environmentally harmful than existing forms of insulation.

As far as performance is concerned, a reporter from the BBC tested it in an interesting video involving a frozen chocolate bar and a blowtorch, discovering also that the insulation is relatively flame-retardant. Besides insulation, though, there are many more atypical uses of fungi that have been discovered recently including pest control and ethanol creation. They can also be used to create self-healing concrete.

Thanks to [Michael] for the tip!

Photo of fungal mycelium: Tobi Kellner [CC BY-SA 3.0]