代码之家  ›  专栏  ›  技术社区  ›  Regressor

如何在Scala中将.rds R文件加载为Spark数据帧

  •  1
  • Regressor  · 技术社区  · 6 年前

    我正在尝试为模型创建生产数据管道。作为这个管道的一部分,我保存了一个运行在 R 环境作为 .rds

    set.seed(345)
    
    df = data.frame(x = rnorm(20))
    
    df = transform(df , y = 5 + (2.3*x) + rnorm(20))
    
    ## model
    m1 = lm(y ~ x , data = df)
    
    ## Take out the coefficients 
    coeff = m1$coefficients
    
    > coeff
    (Intercept)           x 
       4.938554    2.328345
    
    ## save the model coefficients
    saveRDS(coeff, "~/Desktop/coeff.rds")
    

    现在,我想装上这些 coefficients 在Scala程序中 Spark Dataframe ,可能看起来像这样-

    val loadCoefficients = # some method to load .rds file as a Spark Data frame
    

    loadCoefficients.show
    org.apache.spark.sql.DataFrame
    (Intercept)           x 
       4.938554    2.328345
    
    0 回复  |  直到 6 年前
        1
  •  0
  •   sri hari kali charan Tummala    5 年前

    检查这个可能有助于sparkR作者正在做的非常接近你正在尝试的,sparkR是一个外壳,默认情况下带有Spark分布,希望这有助于。

    https://cosminsanda.com/posts/a-compelling-case-for-sparkr/

    https://spark.apache.org/docs/2.0.0/api/R/createDataFrame.html