从Spark中的Logistic回归模型中提取权重和特征名称

问题描述 投票:0回答:1

我有一个交叉验证器模型,该模型具有估计器作为管道对象。训练的模型是OneVsAll,其中Logistic回归是OneVsAll的基本分类器。

这是经过拟合的Cross_validated模型中的最佳模型的样子

jpsa_lr.cvModel.bestModel.stages
Out[281]:
[StringIndexer_4c8399b4ed29d68bc275,
 Tokenizer_48ae8fc24affa2e6a68e,
 StopWordsRemover_4b7996719495950017eb,
 CountVectorizer_444c8ac83adb883350a1,
 IDF_4e0793e75252aa6a2477,
 OneVsRestModel_4941951599f4c8a07352]

这是我的训练方式:

 evaluator = MulticlassClassificationEvaluator(metricName="f1",\
            labelCol=self.pipeline.getStages()[5].getLabelCol(), predictionCol=self.pipeline.getStages()[5].getPredictionCol())

        # Declare the CrossValidator, which runs model tuning for us.
        cv = CrossValidator(estimator=self.pipeline, evaluator=evaluator, estimatorParamMaps=self.paramGrid,numFolds=5)

        # Training the cross validator model
        self.cvModel=cv.fit(self.jpsa_train)

管道对象是上面的转换器和估计器的对象。

现在,我想从cvModel.bestModel中获取逻辑模型的权重。

我在这里检查了这个答案并尝试了以下方法:

Extract variable weight from spark pipeline logistic model?

cvModel.bestModel.weights 
cvModel.bestModel.weight

cvModel.bestModel.stages[5].getClassifier().weights
cvModel.bestModel.stages[5].getClassifier().weight

但是它们都没有指定属性。虽然上面的答案似乎暗示了它的存在。我什至查看了OnevsAll,logistic,crossvalidator的文档,它们都不具有weight或intercept属性。

关于获得权重向量和相应特征名称的任何建议?

python apache-spark pyspark
1个回答
0
投票

你有重量吗?我需要同样的东西,但是我还没有得到。

© www.soinside.com 2019 - 2024. All rights reserved.