使用SQL和重量与火花ML LogisticRegressionModel [英] Using SQL and weights with the spark ML LogisticRegressionModel

查看:318
本文介绍了使用SQL和重量与火花ML LogisticRegressionModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与spark.ml库和管道能力试验。似乎有一个限制使用具有分裂(例如列车和测试)SQL:

I am experimenting with spark.ml library and the the pipelines capability. There seems to be a limitation in using SQL with splits (e.g. for train and test):


  • 我很高兴,spark.ml关闭工作模式RDD的,但随机拆分模式在测试车组RDD没有简单的方法。我可以使用randomSplit(0.6,0.4),但还给RDD数组,失去架构。我可以强制案例类上它和隐蔽回架构RDD,但我有很多的功能。我用的过滤器,并使用基于我独立同分布的特征之一,一些基本的分区状态)。的还有什么任何建议可以做什么?

对于生成的模型:


  • 如何访问模型的权重? LR的优化和LR模型的内部具有的权重,但目前还不清楚如何向我们他们。

推荐答案

好了,对于这个问题的第二部分,

Ok, For 2nd part of the question,

How do I access the model weights? The lr optimizer and lr model internally has weights but it is unclear how to use them

通过库的源会(与非现有的Scala知识)后,

After going through the source of the library(with non-existing Scala knowledge),

该LogisticRegressionModel(的spark.ml)有属性的权重(型载体)。

The LogisticRegressionModel(of spark.ml) has attribute weights (of type vector).

案例1

如果您有LogisticRegressionModel(spark.ml的)

If you have the LogisticRegressionModel (of spark.ml)

LogisticRegression lr = new LogisticRegression();
LogisticRegressionModel lr1 = lr.fit(df_train);
System.out.println("The weights are  " + lr1.weights())

案例2

如果您有管道模型,先用getModel得到LogisticRegressionModel(变压器)

If you have the Pipeline Model, first get the LogisticRegressionModel (Transformer) by using getModel

    LogisticRegression lr = new LogisticRegression().setMaxIter(10).setRegParam(0.01);
    Pipeline pipeline = new Pipeline().setStages(new PipelineStage[] { lr });

    PipelineModel model = pipeline.fit(train_df);
    LogisticRegressionModel lrModel =model.getModel(lr);
    System.out.println("The model is  {}", lrm.weights());

如果不正确或者有更好的办法,你让我知道。

If it is incorrect or there is a better way, do let me know.

这篇关于使用SQL和重量与火花ML LogisticRegressionModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆