Пример #1
0
from BayesFilter import BayesFilter

## Example data taken from Stanford AI video class (Unit 5 Machine Learning)
## http://www.ai-class.org

filter = BayesFilter()

## Add some messages we flagged as spam
filter.addDoc("offer is secret", "spam")
filter.addDoc("click secret link", "spam")
filter.addDoc("secret sports link", "spam")

## Add some messages we did not flag
filter.addDoc("play sports today", None)
filter.addDoc("went play sports", None)
filter.addDoc("secret sports event", None)
filter.addDoc("sports is today", None)
filter.addDoc("sports costs money", None)

filter.db.info()

print "Probability of spam, given message 'today is secret' = %s" % filter.predict("spam", "today is secret")

Пример #2
0
import sys
from BayesFilter import BayesFilter
import BayesDB

db = BayesDB.createOrLoad(sys.argv[1])
filter = BayesFilter(db)
print filter.predict(sys.argv[2], sys.argv[3])

Пример #3
0
from BayesFilter import BayesFilter
from BayesDB import BayesDB

## Example data taken from Stanford AI video class (Unit 5 Machine Learning)
## http://www.ai-class.org

db = BayesDB()
filter = BayesFilter(db)

## Add some messages we flagged as spam
db.addDoc("offer is secret", "spam")
db.addDoc("click secret link", "spam")
db.addDoc("secret sports link", "spam")

## Add some messages we did not flag
db.addDoc("play sports today", None)
db.addDoc("went play sports", None)
db.addDoc("secret sports event", None)
db.addDoc("sports is today", None)
db.addDoc("sports costs money", None)

print "Probability of spam, given message 'today is secret' = %s" % filter.predict("spam", "today is secret")