Building an AI-based botanical medicine indicator

I’ve been exploring artificial intelligence (AI) modules from the Comprehensive Perl Archive Network (CPAN), a great resource for legally stealing very useful tools made by people far smarter than me. One of their featured machine learning modules is also one of the simplest. It’s called the ‘Naive Bayes’ algorithm.

I like simple, so I started from here.

The algorithm earned this name because it is based on a type of probability known as ‘Bayesian,’ named after the Reverend Thomas Bayes, an early math nerd who came up with it while trying to use probability to prove the existence of God.

Bayes’s theorem describes the probability of an event, based on prior knowledge of conditions that might be related to the event. For example, if osteoporosis is related to age, then a person’s age can be used to more accurately assess the probability that they have osteoporosis, compared to an assessment made without knowing the person’s age.

Although it hasn’t proved the existence of God, Bayes’ theorem has proved useful in other ways: from testing new medicines; to weather forecasting, and even helping to improve mobile-phone reception.

The algorithm is ‘naive’ because the events it models are independent; the occurrence of one event does not affect the probability of the occurrence of another.

Thomas Bayes, maybe. Although commonly thought to be his likeness, nobody is actually sure it is him.

The Naive Bayes algorithm is what is known as a ‘classifier’ type algorithm. You’d probably know it best as the mechanism by which your email program decides whether to show you an email or just plunk it in your junk mail folder. It has a memory comprised of ‘training data’ (classes of things, in this case words, that either define spam or not) and based on what criteria it is presented with (in this case the email in question) it calculates a probability (odds) that it is spam. If that number is high enough, off it goes to the junk folder.

A few days ago I was in the Applications directory of my Mac, and saw an icon for an app called Bountiful Herbs that I must have downloaded years ago. Clicking on it I discovered a fairly robust herbal database that had enough information to provide some good training data. The program allowed for the export of data, and after massaging it so much that I could probably get me a certificate from the Swedish Institute, I I was able to feed it into the Perl Naive Bayes module.

I first built what was fundamentally an encyclopedia for the actions of the over 150 medical plants in the database. You can try it here (will open new tab in your browser). When you first run it. it will load an herb randomly. Click on any botanical to learn more about it. Some attributes are also clickable and take you to lists of herbals that share that characteristic.

Herbal Encyclopedia Index

From here on, things get weirdly interesting.

If you click on the link Go to Phytomedicine Pinpointer (machine learning AI) you can select a combination of desired medicinal actions you want to explore and the program will use Reverend Bayes’ algorithm to return a gradated list of botanicals that probability-wise best fit the selected actions. For each selection you can optionally add an indication ‘strength’ (a weighted value of just how important that particular action should factor in the overall classification).

For example, if I select the actions ‘Anodyne’ (pain killer) ‘Accelerates Wound Healing’ and ‘Anti-Fungal’ and give strong weight to ‘Anodyne’, when I press the Pinpoint button, the script returns with the following results.

AI results

Like all machine learning algorithms, what makes the Naive Bayes algorithm so powerful is its ability to gauge the probability for submitted groups of criteria that do not have an exact representation in the training data. That is the big difference between the first, encyclopedia-type, version and the second AI version. The first can only retrieve what it knows, the second can make a pretty good guess about what it doesn’t.

I’m not a big herbal energetics guy, but hey data is data, and these often factor in traditional medical type prescribing, so I added the ability to weave this type of criteria into the AI training knowledge set. You can choose both an ‘energetics’ and a ‘taste’ setting and give it some weight as well.

Herbal energetics classifiers

All in all, I’m pleased and somewhat surprised at just perceptive this little Herbal AI app is. Naive Bayes has numerous applications in medical AI, so future applications are essentially endless, given the appropriate training data.

3 comments on “Building an AI-based botanical medicine indicator”

  1. Peter Borten Reply

    Brilliant! I’m eager to see where this goes, especially as it gets populated with more Chinese herbs (because that’s my area of focus 😉 ). Thanks!

  2. Jim Ronback Reply


    Your exploration into using AI suggested that
    you may be interested in a new book – “The Book of Why – The new science of cause and effect.” by Judea Pearl, Basic Books, New Your, 2018.
    “Pearl’s work enables us to know not just whether one thing causes another: it lets us explore the world that is and the worlds that could have been. It shows us the essence of human thought and key to artificial intelligence. Anyone who wants to understand either needs The Book of Why.”

    It uses Bayes theorem with a Sherlock Holmes eye. It expands statistical analysis with casual graphs to provides algorithms for answering causal and counterfactual queries with scientific rigor.

    In his previous book, “Causal Inference in Statistics” using simple examples and plain language, the book lays out how to define causal parameters; the assumptions necessary to estimate causal parameters in a variety of situations; how to express those assumptions mathematically; whether those assumptions have testable implications; how to predict the effects of interventions; and how to reason counterfactually. These are the foundational tools that any student of statistics needs to acquire in order to use statistical methods to answer causal questions of interest.


    Jim Ronback,
    Tsawwassen, BC

    P.S. Are you doing any blood tests for chronotypes?

    For the Owls and Larks

    A Blood Test for the Body’s Clock

Leave A Reply

Your email address will not be published. Required fields are marked *