毕设项目 基于特征熵值分析的网站分类系统实现(源码+论文)


0 项目说明

基于特征熵值分析的网站分类系统实现

提示:适合用于课程设计或毕业设计,工作量达标,源码开放


1 研究目的

本设计对KNN 算法的缺陷产生原因进行详细地分析,并针对缺陷对算法进行了引入属性熵值等一系列的改进,使得改进的 KNN 算法达到高速、高精度的性能,并且基于改进后的新 KNN 算法,搭建一个真正实用性强的网站分类系统。

2 研究方法

采用了语言 Python(Python 2.7.5)来对系统进行全方面设计,系统实现的平台是 Unix 操作系统。基础的爬虫搭建和页面处理涉及的分词技术均非设计重点,且稳定性要求较高, 所以这两者分别采用了目前相对稳定强大的开源工具 Scrapy 和 Jieba 分词。

3 研究结论

最终本系统利用个 3578 个真实网站内容作为测试集对系统进行了性能测试,最终的成绩是分类精度达到 85.05%,平均一个网页的分类速度是 0.88 秒。
在这里插入图片描述

4 各模块介绍

4.1 爬虫模块功能与技术

爬虫模块的功能:简而言之就是依照给出的 URL 去下载对应的 HTML 文档进 而用于下一步分析。从使用者的角度看,用户输入 URL,如果该 URL 尚未被收录, 那么下载对应 HTML 文档;从构建分类器的角度看,训练集的建立需要各个类别 下大量真实的网站,需要对每个类别下的 URL 进行下载 HTML 文档作为训练集的 生成。 涉及的技术实现:这个模块相对简单,需要编写一个高效的爬虫,下载页面内 容存入 HTML 文档即可。但是,由于目前中文网站编码良莠不齐,下载页面内容 存入 HTML 文档时可能遇到网页编码不统一而导致的下载页面乱码问题,我们需 要注意设计的爬虫应该由对各种网页编码的转换处理能力。
在这里插入图片描述

4.2 网页处理模块功能与技术

网页处理模块的功能:为了提取出可以反映、暗示网站类别或者对网站所属类 别有指导性的一些标签内容,需要对网页进行某些标签内容的提取,比如 HTML 文档的标题提取、META 元标签的提取、正文提取等。提取出这些内容组合成一 个短文本并分词后作为网站内容的简写形式,以便特征提取模块进行特征提取。 涉及的技术实现:对于HTML文档中的标题TITLE标签、元数据META标签, 使用正则表达式技术可以高效、无误差地提取;而正文提取不是很容易,需要设 计或者参考一种正文提取方法,在本设计中,最终参考了一种线性时间复杂度的基于行块分布函数的正文提取方法。之后,需要一种分词技术来把短文本切分为 词的集合。
在这里插入图片描述

4.3 特征提取与文本特征表示模块功能与技术

特征提取和模块的功能:对于训练网页集经过页面处理模块生成的短文本词集 合形态,本模块需要根据训练集中所有词在每个类别下的分布情况利用一种特征 提取方法进行特征的提取,找出最能代表和支持类别的那些词作为特征项,然后 用数学的形式将这些训练数据保存,形成最终的训练集用于分类器的训练。而对 于测试页面或者用户输入的未标注类别 URL 经页面处理模块生成的短文本词集合 形态,本模块也需要将其转化为数学表示形式以作为分类器输入。 涉及的技术实现:我们需要在目前成熟的特征提取技术中选取一个最适合的方 法,在目前已有的特征提取方法中,本设计选择了卡方检验(CHI)方法,并且在 分析了这个方法的缺陷产生原因后,提出了一种改进的卡方检验方法。文本特征 的数学化表示方法中,本设计考虑到向量空间模型(VSM)在目前的文本分类中 效果较好,于是采用了 VSM 表示方法。而且为了反映每个特征项的权重,引入了 TF*IDF 方法来计算在每个文本向量中每个维度(即每个特征项)的向量值。

4.4 分类器模块功能与技术

分类器模块功能:顾名思义,分类器就是用来分类的,用户输入的 URL 经过 上述几个模块的处理后生成的文本向量 VSM 作为分类器的输入,分类器进行计算 后输出自己对输入的类别猜测作为该 URL 的最终判定类别。 涉及的技术实现:由于 K 邻近算法(KNN)在文本向量模型下是最好的文本 分类算法之一,本设计中的分类器基于 KNN 算法。在对传统 KNN 算法进行缺陷 研究后,本文罗列出 KNN 算法运行时间慢和分类精度不高的主要原因,在运行时 间上结合 Rocchio 算法、建立倒排索引、建立“位置向量”等思路,同时在分类精 度上结合了属性熵值分析、类别加权、类别平均相似度、共有特征个数等因素改 进分类策略,从而设计出一种新的改进 KNN 算法,这个算法拥有高效、高精度的 特性。
在这里插入图片描述

5 项目源码

#-*- encoding=utf-8 -*-
from __future__ import division
import math
import heapq
from WordClass import WordClass
from Index import Index

class CateFeature(object):
	def __init__(self,name):
		"""docs :all doc in this type,docs=>words
		words :all word in this type,class(WordAttribute)
		feature :we need it as result,word=>weight
		"""
		self.name,self.docs,self.docnum=name,[],0
		self.words={}
		self.words_count={}
		self.feature={}
	def set_docs(self,conn):
		"""get every entry from db table
		entry[0]=id,entry[1]=keyword,entry[2]=description
		"""
		cur=conn.cursor()
		self.docnum=cur.execute('select id,title,keyword,description from %s' % self.name)
		if self.docnum:
			results=cur.fetchall()
			for entry in results:
				doc_id=entry[0]
				self.docs.append(doc_id)
				title=[word for word in entry[1].encode('utf-8').split('+') if word!='uk']
				keywords=[word for word in entry[2].encode('utf-8').split('+') if word!='uk']
				description=[word for word in entry[3].encode('utf-8').split('+') if word!='uk']
				self.words_count[doc_id]=len(title)+len(keywords)+len(description)
				for word in title+keywords+description:
					self.set_words(word,doc_id)
		cur.close()
	def set_words(self,word,doc_id):
		"""get all word (no repo)"""
		if word=='uk' or not word: return
		if word not in self.words:self.words[word]=WordClass(word,doc_id)
		else:self.words[word].updateRf(doc_id)
		self.words[word].setDocnum_in_cate()
	def counter_word_in_me(self,word):
		"""count for the number of document includes the word in this type"""
		return self.words[word].docnum_in_cate if word in self.words else 0
	def counter_word_in_others(self,word,other_cates):
		"""count for the number of document includes the word in one other type"""
		retval=0
		for other_cate in other_cates:
			num_in_other=other_cate.counter_word_in_me(word)
			if num_in_other: self.words[word].updateCatenum()
			retval+=num_in_other
		return retval
	def set_word_chi(self,other_cates,totaltype):
		"""count the for every word in words"""
		if not self.words: return
		for word in self.words:
			self.words[word].docnum_in_others=self.counter_word_in_others(word,other_cates)
			self.words[word].getCHI(totaltype,\
				cate_docsnum=self.docnum,othersdocs_num=self.all_docs_num-self.docnum)
	def feature_topk(self,k=100,thresold=6000):
		"""get top k of word chi,to be features"""
		topk=heapq.nlargest(k,self.words.values(),key=lambda x:x.chi) if self.words else None
		if not topk: return
		topk=[t for t in topk if t.chi>=thresold]
		for item in topk:
			self.feature[item.name]=item.chi
		return topk
	def count_tfidf(self):
		"""count tf*idf for every word"""
		if 'all_docs_num' not in dir(self):
			print 'just set all_docs_num to class attr firstly'
			return
		docsvector={}
		save_idf={}
		for doc_id in self.docs:
			docsvector[doc_id]=[]
			for word in sorted(self.feature):
				tf=0 
				if (doc_id in self.words[word].rf) and (self.words_count[doc_id]): 
					tf=self.words[word].rf[doc_id]
					tf/=self.words_count[doc_id]
				df=self.words[word].docnum_in_cate+self.words[word].docnum_in_others
				idf=math.log(self.all_docs_num/df,10.0)
				save_idf[word]=idf
				tfidf=tf*idf
				docsvector[doc_id].append(tfidf)
		return docsvector,save_idf
	def show(self):
		print 'feature'
		for word in self.feature:
			print word,':',self.feature[word]
	def get_words(self): return self.words
	def get_docs(self): return self.docs
	def get_feature(self): return self.feature
	def doc_to_vector_all(self,filename,feature_filename,all_feature):
		"""use features to make doc to vector"""
		docsvector=self.count_tfidf_all(all_feature)

		with open(feature_filename,'w') as featurefile:
			for word in sorted(self.feature):
				featurefile.write('%s\n' % word)

		my_index=Index(self.name)
		with open(filename,'w') as traintext:
			for doc in self.docs:
				traintext.write('%d:' % doc)
				feature_pos=0
				for tfidf in docsvector[doc]:
					if tfidf:
						my_index.create_Index(feature_pos,doc)
						traintext.write('\t<%d,%f>' % (feature_pos,tfidf))
					feature_pos+=1
				traintext.write('\n')
		my_index.record_Index()
	def count_tfidf_all(self,all_feature):
		"""count tf*idf for every word in every doc"""
		docsvector={}
		for doc_id in self.docs:
			docsvector[doc_id]=[]
			for word in all_feature.keys():
				tf=0
				if word in self.words and doc_id in self.words[word].rf and self.words_count[doc_id]:
					tf=self.words[word].rf[doc_id]
					tf/=self.words_count[doc_id]
				tfidf=tf*all_feature[word]
				docsvector[doc_id].append(tfidf)
		return docsvector

6 论文目录

摘 要
Abstract
第 1 章 绪 论
1.1 课题的研究背景和意义
1.1.1 目前网站分类的研究情况
1.1.2 现有解决方案的优点与不足
1.1.3 基于特征熵值分析的网站分类系统的设计目标
1.2 论文的研究内容与组织结构
1.2.1 论文的研究内容
1.2.2 论文的组织结构
第 2 章 系统模块组成介绍
2.1 系统总体架构
2.2 爬虫模块功能和技术
2.3 网页处理模块功能和技术
2.4 特征提取与文本表示模块功能和技术
2.5 分类器模块功能和技术
2.6 本章小结
第 3 章 爬虫模块和页面处理模块
3.1 爬虫模块详细设计
3.2 页面处理模块详细设计
3.2.1 页面内容价值分析
3.2.2 页面处理方法
3.2.3 一种线性时间的正文提取算法
3.2.4 页面处理关键流程图
3.3 本章小结
第 4 章 特征提取与文本特征表示模块
4.1 特征提取技术介绍
4.1.1 传统的卡方检验方法(CHI)
4.1.2 传统的卡方检验方法的缺陷分析
4.1.3 一种改进的卡方检验方法
4.2 文本特征表示介绍
4.2.1 体现词在文档中权重的关键因素分析
4.2.2 TF*IDF 方法
4.3 本章小结
第 5 章 KNN 分类器模块
5.1 传统 KNN 算法介绍
5.2 传统 KNN 算法的缺陷
5.3 在运行速度上改进 KNN 算法
5.3.1 传统 KNN 算法运行速度低下的原因分析
5.3.2 用 Rocchio 算法进行预选候选类
5.3.3 根据文本的特征集与每类特征交集再次筛选候选类
5.3.4 建立倒排索引
5.3.5 引入位置向量表示法来降低高维向量计算量
5.3.6 快速 KNN 算法的系统流程
5.4 属性熵介绍
5.4.1 熵的定义
5.4.2 属性熵值的意义
5.5 在分类精度上改进 KNN 算法
5.5.1 传统 KNN 算法分类精度低的原因分析
5.5.2 引入共有特征个数改进相似度计算公式
5.5.3 引入属性熵值再次改进相似度计算公式
5.5.4 引入类别平均相似度改进在 K 邻居中各类权重公式
5.5.5 引入类别贡献度再次改进在 K 邻居中各类权重公式
5.5.6 高精度KNN算法的关键流程
5.6 本章小结
第 6 章 实验测试与评价
6.1 分类标准和训练数据
6.2 测试结果
6.3 本章小结
结 论
参考文献
致 谢

7 最后

**项目分享: ** https://gitee.com/asoonis/htw

  • 18
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【资说明】 1、该资包括项目的全部码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+项目说明(计算机毕设).zip 基于Python+Django的博客系统实现码+

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值