【发布时间】:2014-05-20 05:48:55
【问题描述】:
我需要使用 Weka 及其 AttributeSelection 算法 LatentSemanticAnalysis 来做文本分类。我将数据集拆分为要应用 LSA 的训练集和测试集。我已经阅读了一些关于 LSA 的帖子,但是我还没有找到如何使用它来分离数据集并保持它们兼容。这是我到目前为止但内存不足...:
AttributeSelection selecter = new AttributeSelection();
weka.attributeSelection.LatentSemanticAnalysis lsa = new weka.attributeSelection.LatentSemanticAnalysis();
Ranker rank = new Ranker();
selecter.setEvaluator(lsa);
selecter.setSearch(rank);
selecter.setRanking(true);
selecter.SelectAttributes(input);
Instances outputData = selecter.reduceDimensionality(input);
编辑1 针对@Jose 的回复,我添加了我的源代码的新版本。这会导致 OutOfMemoryError:
AttributeSelection filter = new AttributeSelection(); // package weka.filters.supervised.attribute!
LatentSemanticAnalysis lsa = new LatentSemanticAnalysis();
Ranker rank = new Ranker();
filter.setEvaluator(lsa);
filter.setSearch(rank);
filter.setInputFormat(train);
train = Filter.useFilter(train, filter);
test = Filter.useFilter(test, filter);
编辑2 我得到的错误:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at weka.core.matrix.Matrix.getArrayCopy(Matrix.java:301)
at weka.core.matrix.SingularValueDecomposition.<init>(SingularValueDecomposition.java:76)
at weka.core.matrix.Matrix.svd(Matrix.java:913)
at weka.attributeSelection.LatentSemanticAnalysis.buildAttributeConstructor(LatentSemanticAnalysis.java:511)
at weka.attributeSelection.LatentSemanticAnalysis.buildEvaluator(LatentSemanticAnalysis.java:416)
at weka.attributeSelection.AttributeSelection.SelectAttributes(AttributeSelection.java:596)
at weka.filters.supervised.attribute.AttributeSelection.batchFinished(AttributeSelection.java:455)
at weka.filters.Filter.useFilter(Filter.java:682)
at test.main(test.java:44)
【问题讨论】:
-
您是否尝试通过 java 可执行文件的-Xmx 命令行参数增加分配给您的 java 程序的堆内存?
-
@StevenMagana-Zook 是的,它已经是 2048MB
-
@StevenMagana-Zook 我把它调到了 4096MB,但仍然是 OutOfMemoryError
-
您的数据集有多大,您的计算机上有多少 RAM?从您的堆栈跟踪看来,复制 svd 矩阵会使您超出限制。
-
@StevenMagana-Zook 我在 9,603 个实例中使用了 118 个类属性和 25,765 个属性。这是针对训练集的,对于测试集,我有相同数量的类和普通属性,但这里我有 3,299 个实例。如果它有助于解决我的问题,我正在使用 Reuters21578 (ModApte split) 数据集。我的 2011 MBP intel core 2duo 总共有 8GB 内存
标签: machine-learning nlp weka document-classification text-classification