同步操作将从 zhang_star/NBbook 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import osfrom sklearn.feature_extraction.text import CountVectorizerimport sysimport numpy as npfrom sklearn import cross_validationfrom sklearn.naive_bayes import GaussianNBr_token_pattern=r'\b\w+\b\(|\'\w+\''def load_file(file_path):t=""with open(file_path) as f:for line in f:line=line.strip('\n')t+=linereturn tdef load_files(path):files_list=[]for r, d, files in os.walk(path):for file in files:if file.endswith('.php'):file_path=path+file#print "Load %s" % file_patht=load_file(file_path)files_list.append(t)return files_listif __name__ == '__main__':#bigram_vectorizer = CountVectorizer(ngram_range=(2, 2),token_pattern = r'\b\w+\b', min_df = 1)webshell_bigram_vectorizer = CountVectorizer(ngram_range=(1, 1), decode_error="ignore",token_pattern = r_token_pattern,min_df=1)webshell_files_list=load_files("../data/PHP-WEBSHELL/xiaoma/")x1=webshell_bigram_vectorizer.fit_transform(webshell_files_list).toarray()y1=[1]*len(x1)vocabulary=webshell_bigram_vectorizer.vocabulary_wp_bigram_vectorizer = CountVectorizer(ngram_range=(1, 1), decode_error="ignore",token_pattern = r_token_pattern,min_df=1,vocabulary=vocabulary)wp_files_list=load_files("../data/wordpress/")x2=wp_bigram_vectorizer.transform(wp_files_list).toarray()#print x2y2=[0]*len(x2)x=np.concatenate((x1,x2))y=np.concatenate((y1, y2))clf = GaussianNB()print vocabularyprint cross_validation.cross_val_score(clf, x, y, n_jobs=-1,cv=3)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。