【问题标题】:How to do regression of 2 dimensions (x,y) determines z in Spark?如何在 Spark 中对二维(x,y)进行回归确定 z?
【发布时间】:2016-03-16 05:06:07
【问题描述】:

我有一个确定 z 的 x,y 值的数据集,我如何使用 Apache Spark 进行回归以找到从 x,y 到 z 的拟合(找到函数)?我找不到任何示例,有人可以指出示例或帮助吗?

【问题讨论】:

标签: apache-spark


【解决方案1】:

有很多例子。但是您必须记住要使用的库,即如果数据是DataFrame,您可能想要使用ml,但如果数据来自RDD 结构,那么您可能更喜欢mllib而是。

例如对于mllibpython

# 1. import the required libraries.
from pyspark.mllib.regression import LabeledPoint, LinearRegressionWithSGD
import numpy as np

# 2. read your data or create it. 
trainingData = sc.parallelize([(23.0, [-1.0, 2.0]), (13.0, [0.5, 2.0]),
                               (15.0, [-2.0, 1.0]), (10.0, [1.0, 0.4])])

# 3. fit your model.
lrModel = LinearRegressionWithSGD.train(trainingData)

# 4. make predictions.
myPrediction = lrModel.predict(np.array([1.0, -2.0]))

注意:我真的建议你审核 edx 的两门课程(都使用 Apache Spark):Introduction to Big DataScalable Machine Learning

【讨论】:

    猜你喜欢
    • 2013-02-15
    • 2020-09-09
    • 2018-04-09
    • 2019-08-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多