- 阅读权限
- 255
- 威望
- 1 级
- 论坛币
- 49635 个
- 通用积分
- 55.6937
- 学术水平
- 370 点
- 热心指数
- 273 点
- 信用等级
- 335 点
- 经验
- 57805 点
- 帖子
- 4005
- 精华
- 21
- 在线时间
- 582 小时
- 注册时间
- 2005-5-8
- 最后登录
- 2023-11-26
已卖:4897份资源
学术权威
还不是VIP/贵宾
TA的文库 其他... R资源总汇
Panel Data Analysis
Experimental Design
- 威望
- 1 级
- 论坛币
 - 49635 个
- 通用积分
- 55.6937
- 学术水平
- 370 点
- 热心指数
- 273 点
- 信用等级
- 335 点
- 经验
- 57805 点
- 帖子
- 4005
- 精华
- 21
- 在线时间
- 582 小时
- 注册时间
- 2005-5-8
- 最后登录
- 2023-11-26
 | 开心 2017-10-21 10:25:33 |
|---|
签到天数: 1 天 连续签到: 1 天 [LV.1]初来乍到
|
经管之家送您一份
应届毕业生专属福利!
求职就业群
感谢您参与论坛问题回答
经管之家送您两个论坛币!
+2 论坛币
- from __future__ import print_function
- import sys
- from pyspark import SparkContext
- from pyspark.ml.classification import LogisticRegression
- from pyspark.mllib.evaluation import MulticlassMetrics
- from pyspark.ml.feature import StringIndexer
- from pyspark.sql import SQLContext
- """
- A simple example demonstrating a logistic regression with elastic net regularization Pipeline.
- Run with:
- bin/spark-submit examples/src/main/python/ml/logistic_regression.py
- """
- if __name__ == "__main__":
- if len(sys.argv) > 1:
- 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()
复制代码
扫码加我 拉你入群
请注明:姓名-公司-职位
以便审核进群资格,未注明则拒绝
|
|
|