當前位置: 首頁>>代碼示例>>Python>>正文


Python PE.processEmail方法代碼示例

本文整理匯總了Python中PE.processEmail方法的典型用法代碼示例。如果您正苦於以下問題:Python PE.processEmail方法的具體用法?Python PE.processEmail怎麽用?Python PE.processEmail使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PE的用法示例。


在下文中一共展示了PE.processEmail方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: email

# 需要導入模塊: import PE [as 別名]
# 或者: from PE import processEmail [as 別名]
import PE
import EF
import scipy.io as sio
import STSpam
import numpy as np

#Part One: Email Preprocessing
print 'One: =============Email Preprocessing ...'
fileContent=open('emailSample1.txt','r').read()
wordIndices=PE.processEmail(fileContent)
print wordIndices
print ' '

#Part Two: Feature Extration
print 'Two:==================Extracting features from sample email (emailSample1.txt)...'

features=EF.emailFeatures(wordIndices)
print 'Length of features vector: ',len(features)
print 'Number of non-zero entries: ',sum(features>0)

#Part Three: Train Linear SVM for Spam Classification
print 'Three: ===============Train Linear SVM for Spam Classification...'
data=sio.loadmat('spamTrain') 
X=data['X']
y=data['y']
C=0.1
model=STSpam.svmTrain(X,y,C,'linear')
p=model.predict(X)
print 'Training Accuracy: %6.3f%%' % (np.mean(p == y.flatten())*100)

print ''
開發者ID:kongmo,項目名稱:AssiSiv,代碼行數:33,代碼來源:ex6_spam.py


注:本文中的PE.processEmail方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。