yuxd 2014-05-23 05:49
浏览 940

mahout文档自动分类(有监督学习)问题求救

Hadoop2.2.0, mahout0.6
想做一个word文档自动分类的程序(有监督学习,类别事先已经定义好,就两类财务和人事),始终不成功,求救
一,训练数据
搞了7个finance的word和7个hr的word,用程序生成一个分词后的文本.如下:
terms.txt
finance 会计 会计制度 会计 制度 会计核算 会计 核算 aa
finance 会计 会计制度 会计 制度 会计核算 会计 核算 aa
finance 会计 会计制度 会计 制度 会计核算 会计 核算 核算 管理 会计 管理 aa
finance 会计统计 会计 统计 会计制度 会计 制度 aa
finance 会计核算 会计 核算 制度 1 aa
finance 会计 报销 制度 aa
finance 会计 任免 奖惩制度 奖惩 制度 aa
hr 干部 提拔 制度 bb
hr 机关干部 机关 干部 部奖 奖惩 bb
hr 领导干部 领导 干部 行为规范 行为 规范 第 1 页 共 1 页 bb
hr 人事管理 人事 管理 系统分析 系统 统分 分析 与 设计 干部 任免 会议 1 1 bb
hr 老干部 干部 活动中心 活动 中心 bb
hr 群众 干部 打成一片 打成 一片 一 片 bb
hr 行政 干部 条例 机关干部 机关 干部 部下 下乡 bb
二\生成模型
hadoop fs -put /download/terms.txt hdfs://hadoop-node1:9000/testdata/train
mahout trainclassifier -i /testdata/train -o /testdata/model -type bayes -ng 1 -source hdfs
模型也生成的很好
[root@hadoop-node1 Desktop]# hadoop fs -ls hdfs://hadoop-node1:9000/testdata/model/trainer-tfIdf/trainer-tfIdf
Found 1 items
-rw-r--r-- 3 root supergroup 1524 2014-05-23 11:22 hdfs://hadoop-node1:9000/testdata/model/trainer-tfIdf/trainer-tfIdf/part-00000
三\测试
1)测试1
public static void main(String[] args) {
// TODO Auto-generated method stub
BayesParameters params = new BayesParameters();
params.set("classifierType", "bayes");
params.set("method", "sequential");
params.set("gramSize", "1");
params.set("dataSource", "hdfs");
params.set("model", "hdfs://192.168.1.201:9000/testdata/model");

        Algorithm algorithm = new BayesAlgorithm();

        Datastore datastore = new InMemoryBayesDatastore(params);

        try {
              ClassifierContext classifier = new ClassifierContext(algorithm,
                          datastore);
              classifier.initialize();
              String[] str = new String[1];
              str[0] = "会计";    
              ClassifierResult best = classifier.classifyDocument(str, "unknown");
              System.out.println(best.getLabel() + "---1---" + best.getScore());
              str = new String[1];
              str[0] = "aa";    
              best = classifier.classifyDocument(str, "unknown");
              System.out.println(best.getLabel() + "---2---" + best.getScore());
              str[0] = "干部";    
              best = classifier.classifyDocument(str, "unknown");
              System.out.println(best.getLabel() + "---3---" + best.getScore());
              str[0] = "bb";    
              best = classifier.classifyDocument(str, "unknown");
              System.out.println(best.getLabel() + "---3---" + best.getScore());
        } catch (Exception e) {
              e.printStackTrace();
        }

  }

用 java -jar ml.jar结果都是
2014-05-23 12:23:09,464 WARN [main] util.NativeCodeLoader (NativeCodeLoader.java:(62)) - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable (这段提示应该没关系,我做别的应用都有,不影响结果)
unknown---1---1.7976931348623157E308
unknown---2---1.7976931348623157E308
unknown---3---1.7976931348623157E308
unknown---3---1.7976931348623157E308
2)测试2
准备测试数据
terms4test.txt
finance 会计 报销 制度 aa
hr 老干部 干部 活动中心 活动 中心 bb
执行
mahout testclassifier -d /testdata/test -m /testdata/model -type bayes -ng 1 -source hdfs -method sequential
结果是:
[root@hadoop-node1 Desktop]# mahout testclassifier -d /testdata/test -m /testdata/model -type bayes -ng 1 -source hdfs -method sequential
MAHOUT_LOCAL is not set; adding HADOOP_CONF_DIR to classpath.
Running on hadoop, using HADOOP_HOME=/home/cluster/hadoop-2.2.0
HADOOP_CONF_DIR=/home/cluster/hadoop-2.2.0/etc/hadoop
MAHOUT-JOB: /home/cluster/mahout-0.6/mahout-examples-0.6-job.jar
14/05/23 13:47:16 INFO bayes.TestClassifier: Loading model from: {basePath=/testdata/model, classifierType=bayes, alpha_i=1.0, dataSource=hdfs, gramSize=1, verbose=false, confusionMatrix=null, encoding=UTF-8, defaultCat=unknown, testDirPath=/testdata/test}
14/05/23 13:47:16 INFO bayes.TestClassifier: Testing Bayes Classifier
14/05/23 13:47:19 INFO bayes.SequenceFileModelReader: 13.234485816760284
14/05/23 13:47:19 INFO bayes.InMemoryBayesDatastore: finance -32.77372087917866 88.2943409498656 -0.3711871058394094
14/05/23 13:47:19 INFO bayes.InMemoryBayesDatastore: hr -88.2943409498656 88.2943409498656 -1.0
14/05/23 13:47:19 INFO bayes.TestClassifier: =======================================================

Summary

Correctly Classified Instances : 0 �%
Incorrectly Classified Instances : 0 �%
Total Classified Instances : 0

Confusion Matrix

a b <--Classified as
0 0 | 0 a = finance
0 0 | 0 b = hr

14/05/23 13:47:19 INFO driver.MahoutDriver: Program took 3380 ms (Minutes: 0.05633333333333333)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧