When trying to execute the Prefixspan algo in the spark mllib I get the error
The method run(JavaRDD Sequence ) in the type PrefixSpan is not applicable >for the arguments (JavaRDD List String)
The code I see on the website is
JavaRDD<List<List<Integer>>> sequences = sc.parallelize(Arrays.asList(
Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3)),
Arrays.asList(Arrays.asList(1), Arrays.asList(3, 2), Arrays.asList(1, 2)),
Arrays.asList(Arrays.asList(1, 2), Arrays.asList(5)),
Arrays.asList(Arrays.asList(6))), 2);
PrefixSpan prefixSpan = new PrefixSpan().setMinSupport(0.5).setMaxPatternLength(5);
PrefixSpanModel<Integer> model = prefixSpan.run(sequences);
for (PrefixSpan.FreqSequence<Integer> freqSeq: model.freqSequences().toJavaRDD().collect()) {
System.out.println(freqSeq.javaSequence() + ", " + freqSeq.freq());
}
My code is
List<List<String>> sequences = createLists(featuresForAlgo);
JavaRDD<List<String>> rdd = sc.parallelize(sequences);
PrefixSpan prefixSpan = new PrefixSpan()
.setMinSupport(0.5)
.setMaxPatternLength(5);
PrefixSpanModel<String> model = prefixSpan.run(rdd);
for (PrefixSpan.FreqSequence<Integer> freqSeq: model.freqSequences().toJavaRDD().collect()) {
System.out.println(freqSeq.javaSequence() + ", " + freqSeq.freq());
}
Where the method prefixSpan.run(rdd) gives the error. Any idea why I get this error? As far as I know a List is a sequence.
Thanks
The error is slightly misleading but if you see the source code of PrefixSpan class you will find that run method parameter is like
@param data ordered sequences of itemsets stored as Java Iterable of Iterables
So prefixSpan.run method needs JavaRDD<List<List<String>>>
. In your code you can do like
List<List<List<String>>> seqNew = new ArrayList<List<List<String>>>();
seqNew.add(sequences);
JavaRDD<List<List<String>>> rdd = sc.parallelize(seqNew);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.