Basically it needs to know the difference between ham and spam.
If it falsely flags something as spam, you can flag it as ham and allow it to send the information to the central Akismet service server so that it can be taught to be better at guessing what’s spam.
Akismet uses Bayesian filtering, and then something else.
Maybe it’s possible to find something implemented in PHP, if you don’t want to (or can’t) use the Akismet service.
They do have - of course: since Wordpress is PHP-based and Akismet is by Wordpress - a PHP API for it.