【问题标题】:PYSPARK: What is the optimization technique used in pyspark.ml.classification.LogisticRegression?PYSPARK:pyspark.ml.classification.LogisticRegression 中使用的优化技术是什么?
【发布时间】:2017-04-10 15:35:26
【问题描述】:

pyspark.ml.classification.LogisticRegression 中使用的优化技术是什么?是梯度下降还是梯度上升或其他?如果它是一种梯度算法,我该如何指定 stepSize? 我在 Logistic 回归类中没有看到任何 stepSize 参数:

class pyspark.ml.classification.LogisticRegression(self, featuresCol="features", labelCol="label", predictionCol="prediction", maxIter=100, regParam=0.0, elasticNetParam=0.0, tol=1e-6, fitIntercept=True, threshold=0.5, thresholds=None, probabilityCol="probability", rawPredictionCol="rawPrediction", standardization=True, weightCol=None, aggregationDepth=2, family="auto")

【问题讨论】:

    标签: python machine-learning pyspark logistic-regression


    【解决方案1】:

    根据文档,fit 方法需要额外的参数,但是深入兔子洞尝试找到 fit 实际指向的位置非常困难。话虽如此,如果您查看mllib.classification module,您会发现逻辑回归的第一个实现是LogisticRegressionWithSGD。在那里,您会找到一个弃用说明,指向 ml.classifcation 模块。

    注意:在 2.0.0 中已弃用。使用 ml.classification.LogisticRegression 或 LogisticRegressionWithLBFGS。

    所以本质上,spark 是在告诉您,如果您想使用 SGD,请使用ml.classifcation.LogisticRegression。我的假设(当前未经测试)是您可以将 mllib.classifcation.LogisticRegressionWithSGD 方法的参数用作 ml.classification.LogisticRegression.fit 方法的 params= kwargs。因此,在这种情况下,您可以尝试传递以下内容。请注意,旧的 mllib.classification.LogisticRegressionWithSGD.train 方法的默认步长是 1.0。

    my_lr_model = my_lr_obj.fit(params={'step': 0.5})
    

    【讨论】:

    • 谢谢,我按照你的建议使用了。问题是当我改变步长时,我看不到我的结果有任何变化。我使用的步长为 0.00001 到 10000。这可能告诉我们 ml.classification.LogisticRegression.fit 没有考虑步长参数。
    • 我担心会是这样。我用step_sizestepSize 进行了类似的尝试,也没有任何变化。我不得不想象他们默认情况下仍在使用某种形式的梯度下降,因此必须有某种方式来改变步长。这现在会困扰我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 2023-03-08
    • 2012-07-20
    • 2017-09-08
    相关资源
    最近更新 更多