Ich versuche, die aus dem Modell generierten häufigen Itemsets in einer Textdatei zu speichern. Der Code ist ein Beispiel für das FPGrowth-Beispiel in der Spark ML-Bibliothek. Wenn saveAsTextFile direkt im Modell verwendet wird, werden die RDD-Speicherorte und nicht die tatsächlichen Werte geschrieben.Wie speichern FP-Growth-Modell FrequentItemSet Ergebnisse in einer Textdatei?
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.SparkConf;
import org.apache.spark.mllib.fpm.FPGrowth;
import org.apache.spark.mllib.fpm.FPGrowthModel;
import org.apache.spark.api.java.function.Function;
import java.util.Arrays;
import java.util.List;
public class Test_ItemFrequency {
public static void main(String args[]) {
SparkConf conf = new SparkConf().setAppName("FP-Growth_ItemFrequency").setMaster("local");
JavaSparkContext sc = new JavaSparkContext(conf);
JavaRDD<String> data = sc.textFile("/data/mllib/sample_fpgrowth.txt");
JavaRDD<List<String>> transactions = data.map(new Function<String, List<String>>() {
public List<String> call(String line) {
String[] parts = line.split(" ");
return Arrays.asList(parts);
}
});
FPGrowth fpg = new FPGrowth().setMinSupport(0.2).setNumPartitions(1);
FPGrowthModel<String> model = fpg.run(transactions);
model.freqItemsets().saveAsTextFile("/home/data/itemset");
sc.stop();
}
}
Die Ausgabe in Textdatei erzeugt wird, wie
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
kann jemand erklären, wie fix zu? Danke im Voraus.
Siehe http://stackoverflow.com/q/35969258/1560062 – zero323
Sie Java-Code teilen können? –