91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 13KB
    文件類(lèi)型: .zip
    金幣: 2
    下載: 1 次
    發(fā)布日期: 2021-06-06
  • 語(yǔ)言: Python
  • 標(biāo)簽: python??LDA??代碼??

資源簡(jiǎn)介

LDA算法的Python實(shí)現(xiàn),請(qǐng)尊重原作者的勞動(dòng)成果,記得引用。

資源截圖

代碼片段和文件信息

#-*-?coding:utf-8?-*-
import?logging
import?logging.config
import?ConfigParser
import?numpy?as?np
import?random
import?codecs
import?os

from?collections?import?OrderedDict
#獲取當(dāng)前路徑
path?=?os.getcwd()
#導(dǎo)入日志配置文件
logging.config.fileConfig(“l(fā)ogging.conf“)
#創(chuàng)建日志對(duì)象
logger?=?logging.getLogger()
#?loggerInfo?=?logging.getLogger(“TimeInfoLogger“)
#?Consolelogger?=?logging.getLogger(“ConsoleLogger“)

#導(dǎo)入配置文件
conf?=?ConfigParser.ConfigParser()
conf.read(“setting.conf“)?
#文件路徑
trainfile?=?os.path.join(pathos.path.normpath(conf.get(“filepath“?“trainfile“)))
wordidmapfile?=?os.path.join(pathos.path.normpath(conf.get(“filepath““wordidmapfile“)))
thetafile?=?os.path.join(pathos.path.normpath(conf.get(“filepath““thetafile“)))
phifile?=?os.path.join(pathos.path.normpath(conf.get(“filepath““phifile“)))
paramfile?=?os.path.join(pathos.path.normpath(conf.get(“filepath““paramfile“)))
topNfile?=?os.path.join(pathos.path.normpath(conf.get(“filepath““topNfile“)))
tassginfile?=?os.path.join(pathos.path.normpath(conf.get(“filepath““tassginfile“)))
#模型初始參數(shù)
K?=?int(conf.get(“model_args““K“))
alpha?=?float(conf.get(“model_args““alpha“))
beta?=?float(conf.get(“model_args““beta“))
iter_times?=?int(conf.get(“model_args““iter_times“))
top_words_num?=?int(conf.get(“model_args““top_words_num“))

class?Document(object):
????def?__init__(self):
????????self.words?=?[]
????????self.length?=?0

class?DataPreProcessing(object):

????def?__init__(self):
????????self.docs_count?=?0
????????self.words_count?=?0
????????self.docs?=?[]
????????self.word2id?=?OrderedDict()

????def?cachewordidmap(self):
????????with?codecs.open(wordidmapfile?‘w‘‘utf-8‘)?as?f:
????????????for?wordid?in?self.word2id.items():
????????????????f.write(word?+“\t“+str(id)+“\n“)

class?LDAModel(object):
????
????def?__init__(selfdpre):

????????self.dpre?=?dpre?#獲取預(yù)處理參數(shù)

????????#
????????#模型參數(shù)
????????#聚類(lèi)個(gè)數(shù)K,迭代次數(shù)iter_times每個(gè)類(lèi)特征詞個(gè)數(shù)top_words_num超參數(shù)α(alpha)?β(beta)
????????#
????????self.K?=?K
????????self.beta?=?beta
????????self.alpha?=?alpha
????????self.iter_times?=?iter_times
????????self.top_words_num?=?top_words_num?
????????#
????????#文件變量
????????#分好詞的文件trainfile
????????#詞對(duì)應(yīng)id文件wordidmapfile
????????#文章-主題分布文件thetafile
????????#詞-主題分布文件phifile
????????#每個(gè)主題topN詞文件topNfile
????????#最后分派結(jié)果文件tassginfile
????????#模型訓(xùn)練選擇的參數(shù)文件paramfile
????????#
????????self.wordidmapfile?=?wordidmapfile
????????self.trainfile?=?trainfile
????????self.thetafile?=?thetafile
????????self.phifile?=?phifile
????????self.topNfile?=?topNfile
????????self.tassginfile?=?tassginfile
????????self.paramfile?=?paramfile
????????#?p概率向量?double類(lèi)型,存儲(chǔ)采樣的臨時(shí)變量
????????#?nw詞word在主題topic上的分布
????????#?nwsum每各topic的詞的總數(shù)
????????#?nd每個(gè)doc中各個(gè)topic的詞的總數(shù)
????????#?ndsum每各doc中詞的總數(shù)
????????self.p?=?np.zeros(self.K)????????
????????self.nw?=?np.zeros((self.dpre.words_countself.K)dtype=“int“)???????
????????self.nwsum?=?np.zeros(self.Kdtype=“int“)????
????????self.nd?=?np.zeros((self.dpre.docs_countself.K)dtype=“int“)???????

?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????目錄???????????0??2016-08-01?06:50??python-LDA-master\
?????文件????????2274??2016-08-01?06:50??python-LDA-master\README.md
?????目錄???????????0??2016-08-01?06:50??python-LDA-master\data\
?????目錄???????????0??2016-08-01?06:50??python-LDA-master\data\tmp\
?????文件?????????104??2016-08-01?06:50??python-LDA-master\data\tmp\model_parameter.dat
?????文件???????10703??2016-08-01?06:50??python-LDA-master\data\tmp\model_phi.dat
?????文件????????1734??2016-08-01?06:50??python-LDA-master\data\tmp\model_tassign.dat
?????文件?????????537??2016-08-01?06:50??python-LDA-master\data\tmp\model_theta.dat
?????文件????????1561??2016-08-01?06:50??python-LDA-master\data\tmp\model_twords.dat
?????文件????????2428??2016-08-01?06:50??python-LDA-master\data\tmp\wordidmap.dat
?????文件????????2530??2016-08-01?06:50??python-LDA-master\data\train.dat
?????文件????????9501??2016-08-01?06:50??python-LDA-master\lda.py
?????目錄???????????0??2016-08-01?06:50??python-LDA-master\log\
?????文件???????10015??2016-08-01?06:50??python-LDA-master\log\info.log
?????文件???????????0??2016-08-01?06:50??python-LDA-master\log\info.log.2015-08-06
?????文件????????1136??2016-08-01?06:50??python-LDA-master\logging.conf
?????文件?????????385??2016-08-01?06:50??python-LDA-master\setting.conf

評(píng)論

共有 條評(píng)論