资源简介
是基于python环境的一个lda算法的推荐模型,里面包括配置文件,文件设置代码,数据集,python脚本,内容很全面。

代码片段和文件信息
#-*- coding:utf-8 -*-
import logging
import logging.config
import ConfigParser
import numpy as np
import random
import codecs
import os
from collections import OrderedDict
#获取当前路径
path = os.getcwd()
#导入日志配置文件
logging.config.fileConfig(“logging.conf“)
#创建日志对象
logger = logging.getLogger()
# loggerInfo = logging.getLogger(“TimeInfoLogger“)
# Consolelogger = logging.getLogger(“ConsoleLogger“)
#导入配置文件
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“)))
#模型初始参数
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 #获取预处理参数
#
#模型参数
#聚类个数K,迭代次数iter_times每个类特征词个数top_words_num超参数α(alpha) β(beta)
#
self.K = K
self.beta = beta
self.alpha = alpha
self.iter_times = iter_times
self.top_words_num = top_words_num
#
#文件变量
#分好词的文件trainfile
#词对应id文件wordidmapfile
#文章-主题分布文件thetafile
#词-主题分布文件phifile
#每个主题topN词文件topNfile
#最后分派结果文件tassginfile
#模型训练选择的参数文件paramfile
#
self.wordidmapfile = wordidmapfile
self.trainfile = trainfile
self.thetafile = thetafile
self.phifile = phifile
self.topNfile = topNfile
self.tassginfile = tassginfile
self.paramfile = paramfile
# p概率向量 double类型,存储采样的临时变量
# nw词word在主题topic上的分布
# nwsum每各topic的词的总数
# nd每个doc中各个topic的词的总数
# ndsum每各doc中词的总数
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“)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-01-31 18:53 python_lda_learning\
文件 2274 2016-08-01 14:50 python_lda_learning\README.md
目录 0 2019-01-29 12:36 python_lda_learning\data\
目录 0 2019-01-29 12:36 python_lda_learning\data\tmp\
文件 104 2016-08-01 14:50 python_lda_learning\data\tmp\model_parameter.dat
文件 10703 2016-08-01 14:50 python_lda_learning\data\tmp\model_phi.dat
文件 1734 2016-08-01 14:50 python_lda_learning\data\tmp\model_tassign.dat
文件 537 2016-08-01 14:50 python_lda_learning\data\tmp\model_theta.dat
文件 1561 2016-08-01 14:50 python_lda_learning\data\tmp\model_twords.dat
文件 2428 2016-08-01 14:50 python_lda_learning\data\tmp\wordidmap.dat
文件 2530 2016-08-01 14:50 python_lda_learning\data\train.dat
文件 9501 2019-01-30 11:18 python_lda_learning\lda.py
目录 0 2019-01-29 12:36 python_lda_learning\log\
文件 10015 2016-08-01 14:50 python_lda_learning\log\info.log
文件 0 2016-08-01 14:50 python_lda_learning\log\info.log.2015-08-06
文件 1136 2016-08-01 14:50 python_lda_learning\logging.conf
文件 385 2016-08-01 14:50 python_lda_learning\setting.conf
- 上一篇:随机森林的代码实现和相应的数据集 python代码
- 下一篇:问卷星爬虫带验证码
相关资源
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
- 量化交易(附python常见函数的使用方
- python 名字用字排行
评论
共有 条评论