rhadoop linear regression 问题
Posted lxjshuju
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rhadoop linear regression 问题相关的知识,希望对你有一定的参考价值。
library(rhdfs)
library(rmr2)
hdfs.init()
hdfs.delete("/user/output/lm.output")
map <- function(k,lines) {
lines<-unlist(strsplit(lines,‘#‘))
k<-lines[1]
x<-unlist(strsplit(lines[2],‘,‘))
y<-unlist(strsplit(lines[3],‘,‘))
x<-as.numeric(x)
y<-as.numeric(y)
lm <- lm(y ~ x)
return( keyval(k, lm$coefficients[[2]]) )
}
reduce <- function(key, lmres) {
# keyval(key, lmres)
return lmres
}
wordcount <- function (input, output=NULL) {
mapreduce(input=input, output=output, input.format="text",output.format = "text", map=map, reduce=reduce)
}
hdfs.root <- ‘/user‘
hdfs.data <- file.path(hdfs.root, ‘input/lm.input‘)
hdfs.out <- file.path(hdfs.root, ‘output/lm.output‘)
out <- wordcount(hdfs.data, hdfs.out)
输入文件为:/user/input/lm.input
1#1,2,3,4#2,4,6,8
2#1,2,3,4#3,6,9,12
3#1,2,3,4#4,8,12,16
4#1,2,3,4#1.5,3,4.5,6
可是输出却仅仅有2个结果:
1 2
4 1.5
以上是关于rhadoop linear regression 问题的主要内容,如果未能解决你的问题,请参考以下文章
Python 线性回归(Linear Regression) - 到底什么是 regression?