基于文本分类的金融舆情感知系统
目录
一、 系统的需求规格说明书 2
1.1概述 2
1.1.1编写目的 2
1.1.2参考资料 2
1.1.3运行环境 2
1.2 功能性需求 2
1.2.1获取数据 2
1.2.2数据预处 2
1.2.3构建文本分类模型 3
1.2.4进行评估 3
1.2.5可视化指数 3
1.3 非功能性需求 3
1.3.1可靠性需求 3
1.3.2易用性需求 3
1.3.3安全性需求 4
1.3.4可维护性需求 4
1.3.5可扩充性需求 4
1.3.6性能需求 4
二、 概要设计 4
三、 详细设计 5
4.1向量空间模型(VSM) 5
4.2 LDA 5
4.2.1LDA的生成过程 6
4.2.2LDA的整体流程 6
4.2.3LDA的学习过程 6
4.3短文本分类算法的具体实现 7
4.3.1:数据的爬取和预处理 7
4.3.2:文本分词 8
4.3.3 特征选取 8
4.3.7 SVM模型训练 11
四、 系统的开发环境配置 12
五、 系统的安装和使用说明书 12
六、 分类效果和舆情指数对比展示 14
七、 系统的先进性说明 16
随着科技的发展,时代的进步,手机、平板电脑等移动设备越来越受人们的欢迎,同时随着移动互联网的快速发展,手机短信、微博、即时聊天信息、邮件和用户评论等以中文短文本形式表示的信息呈现出爆炸式的增长。研究者越来越关注如何在数量庞大的文本中挖掘出有用的信息,特别是对短文本的研究。我们设计的系统是针对股吧股民评论的金融舆情感知系统,股民在股吧中发布一些自己对于当前股情的看法,比如看好或看跌,我们负责采集股民发布的信息,然后对其进行必要的文本分类处理,从而判断股民的舆论倾向,这有助于我们对当前股票形式有一个大致的掌握,也能更好地揣测出当前的经济形势。
我们系统采用的文本处理方式是短文本处理,我们系统主要是通过股吧评论的标题进行判断是否看好当前股市。就目前而言,对于较长文本的信息处理,我们可以采用传统的长文本分类算法,比如Bayes、SVM、KNN、决策树等。然而这些方法在短文本处理时会存在一些问题。同样的,目前文本表示最常用的模型是向量空间模型(VSM),但是VSM是一种适合于大规模语料的文本表示模型,本文转载自http://www.biyezuopin.vip/onews.asp?id=14948故效果也不是很理想。所以,我们重新考虑了一种方式,我们首先使用传统的VSM模型表示短文本,其中的特征选择是使用卡方检验完成的,同时使用LDA模型预测短文本隶属的“主题”,把主题特征加入到短文本中去,从而对短文本进行拓展,最后使用SVM分类器进行分类。
2.1.3运行环境
Windows操作系统,JDK1.8及以上,Eclipse。
2.2 功能性需求
2.2.1获取数据
从股吧中爬取了大量股民对于股市的帖子的数据,从已经获取的数据中挑选出一定数量的样本数据,并人工进行类别标注(正向,中立,负向),建立训练样本集。
2.2.2数据预处
对挑选出的训练样本集进行数据预处理,将每个文本转换为词项的集合。
2.2.3构建文本分类模型
选用合适的文本表示模型完成训练样本集的文本表示,基于训练样本集来学习构建文本分类模型。本系统采用的是svm模型。
package TrainAndCategorization;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import CorpusSpiderAndPreProcess.InputOutput;
import CorpusSpiderAndPreProcess.PreProcess;
import SVMNecessaryPart.SVMPredict;
import SVMNecessaryPart.SVMScale;
import TermPresentAndLdaExtend.TermRepresent;
public class TextCategorizationMain {
private static double unhappy=0;
private static double happy=0;
private static double indiffient=0;
public static void main(String[] args) throws IOException{
ArrayList<Integer> list =new ArrayList<Integer>();
//1读入待分类文本集文件
String dir="10crossStockData/10crossStockData1/";
String CorpusFile=dir+"test/test.txt";
InputOutput rw=new InputOutput();
String[] inputCorpus=rw.readInput(CorpusFile);
//2预处理
PreProcess p=new PreProcess();
String[] docs=p.preProcessMain(inputCorpus);
String trainFileSeg=CorpusFile.substring(0,CorpusFile.lastIndexOf("."))+"Segment.txt";
rw.writeOutput(docs, trainFileSeg);
System.out.println("预处理完毕");
//3文本表示
//读入特征词典文件
String termDicFile=dir+"termDic.txt";
String[] terms=rw.readInput(termDicFile);
//基于特征词典进行文本表示
TermRepresent tr=new TermRepresent();
String[] trDocs=tr.TermRepresentMain(docs,terms);
//将文本表示写入文件
String trFile=dir+"testSetTR.txt";
rw.writeOutput(trDocs, trFile);
//4scale处理
//2使用range文件对训练集进行归一化处理
String scaleFile=trFile+".scale";
String rangeFile=dir+"spiderSegmentSegmentTR.txt.range";
String argv[]={"-t",scaleFile,"-r",rangeFile,trFile};
SVMScale s = new SVMScale();
s.run(argv);
//5 文本分类
//三个参数分别是经过Scale处理的待分类的数据文件,存放分类器模型的文件,存储分类结果的文件
//String scaleFile="10crossdatairis_libsvm_scale/3/testSet.txt";
//String modelFile="10crossdatairis_libsvm_scale/3/InitTrainSet.txt.model";
String modelFile=dir+"spiderSegmentSegmentTR.txt.scale.model";
String predictFile=scaleFile+"predict.txt";
String argv1[]={scaleFile,modelFile,predictFile};
//String modelFile="Data/InitTrainSetSegmentTR.txt.model";
//String predictFile=trFile+".pred0ict";
//String argv1[]={trFile,modelFile,predictFile};
SVMPredict predict = new SVMPredict();
ArrayList<Integer> list1 =new ArrayList<Integer>(predict.run(argv1));
System.out.println(list1);
for(Integer index:list1){
if(index==0)
indiffient++;
else if(index==1)
happy++;
else if(index==2)
unhappy++;
}
System.out.println("各个情绪所占总数百分比");
System.out.println("indiffient"+": "+indiffient/list1.size());
System.out.println("happy"+": "+happy/list1.size());
System.out.println("unhappy"+": "+unhappy/list1.size());
System.out.println("result(1-2/1+2):"+(happy-unhappy)/(happy+unhappy)*100+"%");
}
}