1. 程式人生 > >垃圾郵件分類器的原理(1)

垃圾郵件分類器的原理(1)

學習完了斯坦福大學《機器學習》第7周課程,做完程式設計作業垃圾郵件分類器,準備分享下實現原理和實現方法,對自己也是起到總結作用,對博友是個參考,估計得寫好幾篇才能講完,這是第一篇。

先看執行結果:

訓練樣本有4000個,測試樣本有1000個,結果顯示判斷準確率都在98%以上

Preprocessing sample email (emailSample1.txt)


==== Processed Email ====


anyon know how much it cost to host a web portal well it depend on how mani
visitor you re expect thi can be anywher from less than number buck a month
to a coupl of dollarnumb you should checkout httpaddr or perhap amazon ecnumb
if your run someth big to unsubscrib yourself from thi mail list send an
email to emailaddr


=========================
Word Indices:
 86 916 794 1077 883 370 1699 790 1822 1831 883 431 1171 794 1002 1893 1364 592 1676 238 162 89 688 945 1663 1120 1062 169
9 375 1162 479 1893 1510 799 1182 1237 810 1895 1440 1547 181 1699 1758 1896 688 1676 992 961 1477 71 530 1699 531


Program paused. Press enter to continue.


Extracting features from sample email (emailSample1.txt)


==== Processed Email ====


anyon know how much it cost to host a web portal well it depend on how mani
visitor you re expect thi can be anywher from less than number buck a month
to a coupl of dollarnumb you should checkout httpaddr or perhap amazon ecnumb
if your run someth big to unsubscrib yourself from thi mail list send an
email to emailaddr


=========================
Length of feature vector: 1899
Number of non-zero entries: 45
Program paused. Press enter to continue.


Training Linear SVM (Spam Classification)
(this may take 1 to 2 minutes) ...


Training ......................................................................
...............................................................................
...............................................................................
............................................................. Done!


Training Accuracy: 99.875000


Evaluating the trained Linear SVM on a test set ...
Test Accuracy: 98.700000


Top predictors of spam:
 our             (0.503462)
 click           (0.468912)
 remov           (0.419352)
 guarante        (0.385077)
 visit           (0.365506)
 basenumb        (0.353562)
 dollar          (0.330829)
 will            (0.266236)
 price           (0.265347)
 pleas           (0.262004)
 most            (0.261452)
 lo              (0.254036)
 nbsp            (0.252983)
 al              (0.239734)
 dollarnumb      (0.238813)






Program paused. Press enter to continue.


==== Processed Email ====


do you want to make dollarnumb or more per week if you ar a motiv and qualifi
individu i will person demonstr to you a system that will make you dollarnumb
number per week or more thi is not mlm call our number hour pre record number
to get the detail number number number i need peopl who want to make seriou

monei make the call and get the fact invest number minut in yourself now
number number number look forward to your call and i will introduc you to
peopl like yourself who ar current make dollarnumb number plu per week number
number number numberljgvnumb numberleannumberlrmsnumb
numberwxhonumberqiytnumb numberrjuvnumberhqcfnumb numbereidbnumberdmtvlnumb


=========================


Processed spamSample1.txt


Spam Classification: 1
(1 indicates spam, 0 indicates not spam)