【发布时间】:2018-06-17 07:29:14
【问题描述】:
我正在计算 TFIDF,为此我需要将我的数据集转换为列表行。
我的数据集有 40,00,000 条记录,当我为我的数据集调用 collectAsList 函数时,它需要 20 多分钟才能完成。 我的 RAM 配置为 16gb。
基本上我需要处理单个行来计算该特定记录的 TFIDF。
请建议我是否有任何其他类型的函数可以将数据集转换为 spark 中的列表行。
即使我也尝试过 for 和 foreach 循环,但仍然需要时间。
下面是我的示例代码。
JavaSparkContext sc = new JavaSparkContext(new SparkConf().setAppName("SparkJdbcDs").setMaster("local[*]"));
SQLContext sqlContext = new SQLContext(sc);
SparkSession spark = SparkSession.builder().appName("connection example").getOrCreate();
Dataset<Row> tokenlist= sqlContext.read().format("com.databricks.spark.csv").option("header", "true").option("nullValue", "").load("D:\\AI_MATCHING\\exampleTFIDF.csv");
tokenlist= tokenlist.select("features");
tokenlist.show(false);
List<Row> tokenizedWordsList1 = tokenlist.collectAsList();
/*tokenlist.foreach((ForeachFunction<Row>) individaulRow -> {
newtest.ItemIDSourceIndex=individaulRow.fieldIndex("ItemIDSource");
newtest.upcSourceIndex=individaulRow.fieldIndex("upcSource");
newtest.ManufacturerSourceIndex=individaulRow.fieldIndex("ManufacturerSource");
newtest.ManufacturerPartNumberSourceIndex=individaulRow.fieldIndex("Manufacturer part NumberSource");
newtest.PART_NUMBER_SOURCEIndex=individaulRow.fieldIndex("PART_NUMBER_SOURCE");
newtest.productDescriptionSourceIndex=individaulRow.fieldIndex("productDescriptionSource");
newtest.HASH_CODE_dummyIndex=individaulRow.fieldIndex("HASH_CODE_dummy");
newtest.rowIdSourceIndex=individaulRow.fieldIndex("rowIdSource");
newtest.rawFeaturesIndex=individaulRow.fieldIndex("rawfeatures ");
newtest.featuresIndex=individaulRow.fieldIndex("features ");
});*/
【问题讨论】:
-
Spark 已经实现了 TF-IDF,为什么不用呢? spark.apache.org/docs/2.2.0/ml-features.html#tf-idf
-
在 TFIDF 计算之后,我需要获取单独的行并分配该值。
-
你需要分配什么?使用提供的
fit/transform方法并设置输出列。 -
基本上我需要找到 2 条记录之间的匹配,所以我需要分配 TFIDF 值。我需要列表形式的输出列而不是数据集形式
标签: apache-spark apache-spark-sql apache-spark-mllib