Machine learning
Machine learning is all about making your computer more intelligent.
Building a spam filter
Spam filters use simple algorithm called the Naive Bayes classifier. First, you train your Naive Bayes classifier on some data.
Suppose you get an email with the subject “Collect your million dollars now!” Is it spam? You can break this sentence into words. Then, for each word, see what the probability is for that word to show up in a spam email. For example, in this very simple model, the word million only appears in spam emails. Naive Bayes figures out the probability that something is likely to be spam. It has applications similar to KNN.
Simple example:
https://gist.github.com/juan-reynoso/4b5fdac8aceff049e55c0f7b6bcc3af3
;;spam
(defparameter *spam* "million")
;; emails
(defparameter *emails* '("Reset your password"
"Happy birthday"
"Collect your million dollars now!"))
;; spam filter
(defun spam-filter (emails spam)
"Filter emails and returns a list with good-emails and spam-emails"
(let ((spam-emails nil)
(good-emails nil))
(dolist (email emails)
(if(search spam email)
;;spam email
(push email spam-emails)
;; good email
(push email good-emails)))
;; finally returns the emails filtered
(list good-emails spam-emails)))
;; run the example
CL-USER> (spam-filter *emails* *spam*)
(("Happy birthday" "Reset your password") ("Collect your million dollars now!"))
