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.
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.
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.
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.
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.