資源簡介
主要用于文本的量化處理,非常適合計算文本的相似度以及文本分類,相比于tf-idf更優。
代碼片段和文件信息
import?jieba
import?pandas?as?pd
import?gensim
import?re
jieba.load_userdict(‘d:/data/stocks/數據/平安銀行字典.txt‘)#加載結巴分詞的詞典(還需要把各股票的名字導入進去,今天進行)
jieba.load_userdict(‘d:/data/stocks/數據/股票名稱.txt‘)
def?cut_word(text):
????‘‘‘
????分詞操作,返回一個文章的所有單詞列表
????‘‘‘
????#text=process_txt(str(text))
????#text=‘?‘.join(text)
????text_list=re.split(u‘[^\u4e00-\u9fa50-9a-zA-Z]+‘?str(text))
????word_list=[]
????for?sent?in?text_list:
????????word_list1=jieba.cut(sent)
????????for?word?in?word_list1:
????????????word_list.append(word)
????return?word_list
#print(df)#打印df
#df[‘index‘]=0:(len(df)-1)#給文章一個訓練id號
##訓練Doc2vec模型
import?gensim
#import?multiprocessing
#import?logging
LabeledSentence?=?gensim.models.doc2vec.LabeledSentence
#先把所有文檔的路徑存進一個?array?中,docLabels:
from?os?import?listdir
- 上一篇:arcgis python腳本,自動發布服務
- 下一篇:卷積LSTM代碼
評論
共有 條評論