public ProbabilityIndex(List <Email> emails, SmoothingStyle style) { Style = style; SpamIndex = new Dictionary <string, double>(); HamIndex = new Dictionary <string, double>(); totalSpamWords = emails.Where(email => email.IsSpam).Sum(email => email.Words.Sum(word => word.Value)); totalHamWords = emails.Where(email => !email.IsSpam).Sum(email => email.Words.Sum(word => word.Value)); BuildIndex(SpamIndex, emails.FindAll(doc => doc.IsSpam)); BuildIndex(HamIndex, emails.FindAll(doc => !doc.IsSpam)); SpamClass = CalcClassProbability(emails, true); HamClass = CalcClassProbability(emails, false); }
public SpamFilter(List <Email> trainingData, SmoothingStyle style) { index = new ProbabilityIndex(trainingData, style); }