接上篇blog,继续分析。接下来要调用代码如下:

// Should document frequency features be processed
if (shouldPrune || processIdf) {
docFrequenciesFeatures = TFIDFConverter.calculateDF(new Path(outputDir, tfDirName),
outputDir, conf, chunkSize);
}

首先不看shouldPrune变量,单单看processIdf变量来说,这个变量肯定是true的,所以肯定要执行if里面的部分了,这个是计算DF的函数(单单就单词意思来说);

打开这个函数可以看到主要进行了两个操作:

startDFCounting(input, wordCountPath, baseConf);

    return createDictionaryChunks(wordCountPath, output, baseConf, chunkSizeInMegabytes);

第一个是什么计数,第二个是产生一个dictionary 块;怎么感觉和前面的 Twenty Newsgroups Classification任务之二seq2sparse(2)一模一样,额,好吧,确实有很多相同的地方,应该说基本是一样的,可以参考前面的来分析;但是有点区别的地方是,首先计数的Job里面的Mapper,TermDocumentCountMapper有这样的一句:

private static final IntWritable TOTAL_COUNT = new IntWritable(-1);
while (it.hasNext()) {
Vector.Element e = it.next();
context.write(new IntWritable(e.index()), ONE);
}
context.write(TOTAL_COUNT, ONE);

可以看到在最后还写多了一句、这里先明确几个变量,全部的单词个数有93563个,一共的文件个数(或者说vector个数)有18846个;看这个job的详细信息:


这里就再次说明了reduce接受的key的个数比单词数多了一个即93564;

其次,在新建dictionary块的时候也有不同的地方,首先调用的类是TFIDFConverter。但是其操作基本一样,看到下面的代码:

if (key.get() >= 0) {
freqWriter.append(key, value);
} else if (key.get() == -1) {
vectorCount = value.get();
}
featureCount = Math.max(key.get(), featureCount); }
featureCount++;
Long[] counts = {featureCount, vectorCount};
return new Pair<Long[], List<Path>>(counts, chunkPaths);

这里确实是有多一个key为-1的记录,然后featureCount应该是记录vector的key值,在++之前应该是18846,在++之后就是18847了,所以counts应该为[18847,93564];这个可以通过设置断点来查看;具体下次分析,还有下面两个Job其实应该是和seq2sparse(3)、(4)类似了,只是分析的数据的vector由单词转换为了数值,其他都一样,这样分析之后,后面两个Job就很简单了,然后就是最后的算法精髓了。然后就这个算法就分析完了吧(感觉看了好久的样子。。。)

分享,快乐,成长

转载请注明出处:http://blog.csdn.net/fansy1990

Twenty Newsgroups Classification任务之二seq2sparse(5)的更多相关文章

  1. Twenty Newsgroups Classification任务之二seq2sparse

    seq2sparse对应于mahout中的org.apache.mahout.vectorizer.SparseVectorsFromSequenceFiles,从昨天跑的算法中的任务监控界面可以看到 ...

  2. Twenty Newsgroups Classification任务之二seq2sparse(3)

    接上篇,如果想对上篇的问题进行测试其实可以简单的编写下面的代码: package mahout.fansy.test.bayes.write; import java.io.IOException; ...

  3. Twenty Newsgroups Classification任务之二seq2sparse(2)

    接上篇,SequenceFileTokenizerMapper的输出文件在/home/mahout/mahout-work-mahout0/20news-vectors/tokenized-docum ...

  4. mahout 运行Twenty Newsgroups Classification实例

    按照mahout官网https://cwiki.apache.org/confluence/display/MAHOUT/Twenty+Newsgroups的说法,我只用运行一条命令就可以完成这个算法 ...

  5. Twenty Newsgroups Classification实例任务之TrainNaiveBayesJob(一)

    接着上篇blog,继续看log里面的信息如下: + echo 'Training Naive Bayes model' Training Naive Bayes model + ./bin/mahou ...

  6. 项目笔记《DeepLung:Deep 3D Dual Path Nets for Automated Pulmonary Nodule Detection and Classification》(二)(上)模型设计

    我只讲讲检测部分的模型,后面两样性分类的试验我没有做,这篇论文采用了很多肺结节检测论文都采用的u-net结构,准确地说是具有DPN结构的3D版本的u-net,直接上图. DPN是颜水成老师团队的成果, ...

  7. 深度学习数据集Deep Learning Datasets

    Datasets These datasets can be used for benchmarking deep learning algorithms: Symbolic Music Datase ...

  8. Open Data for Deep Learning

    Open Data for Deep Learning Here you’ll find an organized list of interesting, high-quality datasets ...

  9. 深度学习课程笔记(二)Classification: Probility Generative Model

    深度学习课程笔记(二)Classification: Probility Generative Model  2017.10.05 相关材料来自:http://speech.ee.ntu.edu.tw ...

随机推荐

  1. 跟我一起写 Makefile(一)

    跟我一起写 Makefile  陈皓 概述—— 什么是makefile?也许非常多Winodws的程序猿都不知道这个东西,由于那些Windows的IDE都为你做了这个工作,但我认为要作一个好的和pro ...

  2. poj 2054 Color a Tree(贪婪)

    # include <stdio.h> # include <algorithm> # include <string.h> using namespace std ...

  3. 用Delphi进行word开发

    使用以CreateOleObjects方式调用Word 实际上还是Ole,但是这种方式能够真正做到完全控制Word文件,能够使用Word的所有属性,包括自己编写的VBA宏代码.------------ ...

  4. mac下brew install 报错

    mac下brew install 报错 错误提示: 原因:是这个brew的权限不正确 修改一下这个brew的权限 chown root:wheel /usr/local/bin/brew

  5. MFC用GDI+动感歌词的制作

    源代码:http://download.csdn.net/detail/nuptboyzhb/4219669 源代码: 1.       插入一个对话框的资源,删除默认控件,并为对话框创建一个类,命名 ...

  6. HDU1027 Ignatius and the Princess II 【next_permutation】【DFS】

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...

  7. .atitit.web 推送实现解决方式集合(3)----dwr3 Reverse Ajax

    .atitit.web 推送实现解决方式集合(3)----dwr3 Reverse Ajax 1. 原理实现 1 2. Page  添加配置.添加回调函数dwr.engine.setActiveRev ...

  8. 通过程序预览Office文档

    我承认,标题是夸大了,就是为了吸引注意力.这里只有Word文档和Excel文档的预览代码. Word://此部分来源:http://princed.mblogger.cn/posts/11885.as ...

  9. Jsp中使用数据库连接池.

    原文 Jsp中使用数据库连接池. 1. 在tomcat服务器目录下面的conf中找到一个叫Context.xml的配置文件,在其中加入以下代码 <Resource name="jdbc ...

  10. windows消息处理(强烈推荐,收藏)

    由于看了一下,比较好理解,暂时先放到这里,待有空再翻译.只是在每节后大致介绍一下讲的内容. 感觉写的比较全,无论从消息的原理还是从MFC操作上来说,值得一看,我也在此做个收藏. (一) 说明:以下首先 ...