Spark:从管道模型中提取ML Logistic回归模型的摘要 [英] Spark: Extracting summary for a ML logistic regression model from a pipeline model
本文介绍了Spark:从管道模型中提取ML Logistic回归模型的摘要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我估计使用管道进行逻辑回归.
I've estimated a logistic regression using pipelines.
我在进行逻辑回归之前的最后几行:
My last few lines before fitting the logistic regression:
from pyspark.ml.feature import VectorAssembler
from pyspark.ml.classification import LogisticRegression
lr = LogisticRegression(featuresCol="lr_features", labelCol = "targetvar")
# create assember to include encoded features
lr_assembler = VectorAssembler(inputCols= numericColumns +
[categoricalCol + "ClassVec" for categoricalCol in categoricalColumns],
outputCol = "lr_features")
from pyspark.ml.classification import LogisticRegression
from pyspark.ml import Pipeline
# Model definition:
lr = LogisticRegression(featuresCol = "lr_features", labelCol = "targetvar")
# Pipeline definition:
lr_pipeline = Pipeline(stages = indexStages + encodeStages +[lr_assembler, lr])
# Fit the logistic regression model:
lrModel = lr_pipeline.fit(train_train)
然后我尝试运行该模型的摘要.但是,下面的代码行:
And then I tried to run the summary of the model. However, the code line below:
trainingSummary = lrModel.summary
导致:"PipelineModel"对象没有属性"summary"
results in: 'PipelineModel' object has no attribute 'summary'
关于如何从管道模型中提取回归模型中通常包含的摘要信息的任何建议?
Any advice on how one could extract the summary information that is usually contained in regression's model from a pipeline model?
非常感谢!
推荐答案
只需从阶段中获取模型:
Just get the model from stages:
lrModel.stages[-1].summary
如果模型在管道中更早,则将-1替换为其索引.
If model is earlier in the Pipeline replace -1 with its index.
这篇关于Spark:从管道模型中提取ML Logistic回归模型的摘要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文