我正在运行Flink (0.10-SNAPSHOT)的示例多元线性回归。我不知道如何提取权重(例如斜率和截距,beta0-beta1,你想叫他们什么)。我对Scala不是很熟悉,这可能是我一半的问题。
感谢任何人给予的任何帮助。
object Job {
def main(args: Array[String]) {
// set up the execution environment
val env = ExecutionEnvironment.getExecutionEnvironment
val survival = env.readCsvFile[(String, String, String, String)]("/home/danger/IdeaProjects/quickstart/docs/haberman.data")
val survivalLV = survival
.map{tuple =>
val list = tuple.productIterator.toList
val numList = list.map(_.asInstanceOf[String].toDouble)
LabeledVector(numList(3), DenseVector(numList.take(3).toArray))
}
val mlr = MultipleLinearRegression()
.setStepsize(1.0)
.setIterations(100)
.setConvergenceThreshold(0.001)
mlr.fit(survivalLV)
println(mlr.toString()) // This doesn't do anything productive...
println(mlr.weightsOption) // Neither does this.
}
}
问题是您只构造了Flink作业(DAG),它将计算权重,但尚未执行。触发执行的最简单方法是使用collect
方法,该方法将检索DataSet
的结果返回给您的客户端。
mlr.fit(survivalLV)
val weights = mlr.weightsOption match {
case Some(weights) => weights.collect()
case None => throw new Exception("Could not calculate the weights.")
}
println(weights)