如何从 Spark-MLlib 线性回归模型(Scala)中获取系数值?
How to obtain coefficient values from Spark-MLlib Linear Regression model (Scala)?
我想在 Spark-MLlib 中获取线性回归 (LR) 模型的系数值。这里我使用 'LinearRegressionWithSGD' 来构建模型,你可以从下面的 link:
中找到示例
https://spark.apache.org/docs/2.1.0/mllib-linear-methods.html#regression
我可以从 Spark-ML 线性回归中获取系数值。请从下面找到参考 link。
https://spark.apache.org/docs/2.1.0/ml-classification-regression.html#linear-regression
请帮我解决这个问题。提前致谢!!
从您发送的第一个 link 开始创建模型的第一行:
val model: LinearRegressionModel = LinearRegressionWithSGD.train(parsedData, numIterations, stepSize)
.run(training)
// Here are the coefficient and intercept
val weights: org.apache.spark.mllib.linalg.Vector = model.weights
val intercept = model.intercept
val weightsData: Array[Double] = weights.asInstanceOf[DenseVector].values
最后3行是系数和截距
weights
的类型是
: org.apache.spark.mllib.linalg.Vector
那是 Breeze 的包装纸 DenseVector
我想在 Spark-MLlib 中获取线性回归 (LR) 模型的系数值。这里我使用 'LinearRegressionWithSGD' 来构建模型,你可以从下面的 link:
中找到示例https://spark.apache.org/docs/2.1.0/mllib-linear-methods.html#regression
我可以从 Spark-ML 线性回归中获取系数值。请从下面找到参考 link。
https://spark.apache.org/docs/2.1.0/ml-classification-regression.html#linear-regression
请帮我解决这个问题。提前致谢!!
从您发送的第一个 link 开始创建模型的第一行:
val model: LinearRegressionModel = LinearRegressionWithSGD.train(parsedData, numIterations, stepSize)
.run(training)
// Here are the coefficient and intercept
val weights: org.apache.spark.mllib.linalg.Vector = model.weights
val intercept = model.intercept
val weightsData: Array[Double] = weights.asInstanceOf[DenseVector].values
最后3行是系数和截距
weights
的类型是
: org.apache.spark.mllib.linalg.Vector
那是 Breeze 的包装纸 DenseVector