本文整理汇总了Python中pyspark.ml.classification.LogisticRegression.setElasticNetParam方法的典型用法代码示例。如果您正苦于以下问题:Python LogisticRegression.setElasticNetParam方法的具体用法?Python LogisticRegression.setElasticNetParam怎么用?Python LogisticRegression.setElasticNetParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyspark.ml.classification.LogisticRegression
的用法示例。
在下文中一共展示了LogisticRegression.setElasticNetParam方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_int_to_float
# 需要导入模块: from pyspark.ml.classification import LogisticRegression [as 别名]
# 或者: from pyspark.ml.classification.LogisticRegression import setElasticNetParam [as 别名]
def test_int_to_float(self):
from pyspark.mllib.linalg import Vectors
df = self.sc.parallelize([
Row(label=1.0, weight=2.0, features=Vectors.dense(1.0))]).toDF()
lr = LogisticRegression(elasticNetParam=0)
lr.fit(df)
lr.setElasticNetParam(0)
lr.fit(df)
示例2: test_invalid_to_float
# 需要导入模块: from pyspark.ml.classification import LogisticRegression [as 别名]
# 或者: from pyspark.ml.classification.LogisticRegression import setElasticNetParam [as 别名]
def test_invalid_to_float(self):
from pyspark.mllib.linalg import Vectors
self.assertRaises(Exception, lambda: LogisticRegression(elasticNetParam="happy"))
lr = LogisticRegression(elasticNetParam=0)
self.assertRaises(Exception, lambda: lr.setElasticNetParam("panda"))
示例3: print
# 需要导入模块: from pyspark.ml.classification import LogisticRegression [as 别名]
# 或者: from pyspark.ml.classification.LogisticRegression import setElasticNetParam [as 别名]
print("Usage: logistic_regression", file=sys.stderr)
exit(-1)
sc = SparkContext(appName="PythonLogisticRegressionExample")
sqlContext = SQLContext(sc)
# Load the data stored in LIBSVM format as a DataFrame.
df = sqlContext.read.format("libsvm").load("data/mllib/sample_libsvm_data.txt")
# Map labels into an indexed column of labels in [0, numLabels)
stringIndexer = StringIndexer(inputCol="label", outputCol="indexedLabel")
si_model = stringIndexer.fit(df)
td = si_model.transform(df)
[training, test] = td.randomSplit([0.7, 0.3])
lr = LogisticRegression(maxIter=100, regParam=0.3).setLabelCol("indexedLabel")
lr.setElasticNetParam(0.8)
# Fit the model
lrModel = lr.fit(training)
predictionAndLabels = lrModel.transform(test).select("prediction", "indexedLabel") \
.map(lambda x: (x.prediction, x.indexedLabel))
metrics = MulticlassMetrics(predictionAndLabels)
print("weighted f-measure %.3f" % metrics.weightedFMeasure())
print("precision %s" % metrics.precision())
print("recall %s" % metrics.recall())
sc.stop()