问题: pyspark和scikit-learn中逻辑回归模型的默认实现(未设置自定义参数)在其默认参数值下似乎会产生不同的结果。
我试图使用scikit-learn的逻辑回归模型(见:http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html)来复制使用pyspark(见:https://spark.apache.org/docs/latest/api/python/pyspark.ml.html#pyspark.ml.classification.LogisticRegression)进行的逻辑回归结果(未设置自定义参数)。
在我看来,pyspark和scikit中的两种模型实现并不具备相同的参数,因此我无法简单地将scikit中的参数匹配到pyspark中。有什么方法可以将两种模型在其默认配置下进行匹配吗?
Scikit模型的参数(默认参数):
`LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,penalty='l2', random_state=None, solver='liblinear', tol=0.0001,verbose=0, warm_start=False`
Pyspark模型的参数(默认参数):
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")
非常感谢!
回答:
到目前为止,我发现正如参数standardization=True
所指示的,pyspark会在模型内部对数据进行标准化,而scikit则不会。在应用scikit模型之前实施preprocessing.scale
让我得到了与两种模型非常接近的结果。