zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    zabbix实现mysql数据库的监控(四)
    Redis高级进阶(一)
    Redis高级进阶(二)
    Redis的管理
    9.动态SQL
    8.Mapper动态代理
    7.属性名与查询字段名不相同
    6.单表的CRUD操作
    5.API详解
    4.主配置文件详解
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/7397612.html
Copyright © 2011-2022 走看看