我正在使用 RHadoop rhdfs 包对具有大量列的 CSV 输入文件执行降维。输出将是所有列的选定子集。为简单起见,我尝试仅获取 CSV 文件的前 5 列。
我正在尝试应用 mapreduce 函数来使用 MR 框架并使用 HDFS 存储而不是任何内存处理来执行降维。
我的代码如下:
transfer.csvfile.hdfs.to.hdfs.reduced =
function(hdfsFilePath, hdfsWritePath, reducedCols=1) {
local.matrix = as.numeric()
hdfs.get(hdfsFilePath, local.Matrix, srcFS=hdfs.defaults("fs"))
transfer.reduced.map =
function(.,M) {
label <- M[,1]
reduced.predictors <- M[,1:reducedCols]
reduced.M <- cbind(reduced.predictors, label)
keyval(
1,
as.numeric(reduced.M[,-1]))
}
reduced.values =
values(
from.dfs(
mapreduce(
local.matrix,
map = function(.,M) {
label <- M[,1]
reduced.predictors <- M[,1:reducedCols]
reduced.M <- cbind(reduced.predictors, label)
keyval(
1,
as.numeric(reduced.M[,-1]))}
)))
to.dfs(reduced.values)
}
它需要一个带有预测列和标签列的训练数据集作为最后一个。我正在尝试将预测变量的数量从 100 个减少到 5 个,cbind
并将类标签列减少为减少的预测变量,最后将减少的训练数据集存储到 hdfs 中。
现在,我将 hdfs 文件按名称存储在本地矩阵中,local.matrix
这需要我将整个文件存储在内存中。有没有办法可以通过使用绕过内存local.matrix
中
to.dfs(local.matrix)
然后将 local.matrix 的 HDFS 存储位置传递hdfsWritePath
给transfer.csvfile.hdfs.to.hdfs.reduced function
?