Classification is actually according to a certain standard to label objects, and then according to the label, Bayesian classification algorithm based on probability statistics is the most common classification algorithm, is also the most widely used in the field of garbage text recognition algorithm.
Using the Bayesian classification algorithm for the two classification can be broadly divided into the following steps:
- Collect a large amount of garbage content and non-spam corpus, set up the training of garbage corpus and normal content corpus.
- The corpus text is segmented, the independent string is extracted, and the frequency of the occurrence of the string in the text is counted.
- Each training corpus corresponds to a hash table, for example, the garbage corpus is placed in the Hashtable_bad, rather than the garbage corpus in the Hashtable_good, while the Hashtable stores the string extracted by the word and the corresponding frequency.
- Calculates the probability that all hashtable strings appear, that is, the total number of Word/string of the p= string.
- Combining Hashtable_good and Hashtable_bad, it is speculated that when a string of text contains a character, the text is the probability of garbage content, the corresponding mathematical expression is as follows: P (A|ki) = Pbad (ki)/[Pgood (ki) +pbad (ki)], Where event A indicates that the text is spam, k1,k2 ... kn represents the extracted keyword, and P (A|ki) indicates that the text is the probability of spam, Pbad (ki) is the value of TI in Hashtable_bad when the Keyword Ki appears in the text. and Pgood (KI) is the value of Ki in Hashtable_good.
- Establishes a new hashtable_probability storage string Ki to P (a|ki) mapping.
At this point, the Bayesian classification of the training and learning process is completed, the next can be based on hashtable_probability to calculate the possibility of the text as garbage content. Assume that the user submitted text content through word segmentation to get n keyword k1,k2,k3......kn,hashtable_probability corresponding to the value of P1,P2 ... Pn, P (a|k1,k2,k3......kn) indicates that when the keyword K1,K2,K3......KN is present in a user-submitted text, the content is the probability of the spam text, p (a|k1,k2,k3......kn) =p1*p2* ... Pn. When P (A|K1,K2,K3......KN) exceeds the predetermined threshold, it can be judged that the content is spam, and by adjusting the threshold, you can control how harsh the anti-spam system is for content filtering.
Bayesian classification algorithm