How does Spark's StreamingLinearRegressionWithSGD work?

会有一股神秘感。 提交于 2019-12-23 18:49:38

问题


I am working on StreamingLinearRegressionWithSGD which has two methods trainOn and predictOn. This class has a model object that is updated as training data arrives in the stream specified in trainOn argument.

Simultaneously It give prediction using same model.

I want to know that how the model weights are updated and synchronized across workers/executors.

Any link or reference will be helpful. Thanks.


回答1:


There is no magic here. StreamingLinearAlgorithm keeps a mutable reference to the current GeneralizedLinearModel.

trainOn uses DStream.foreachRDD to train a new model on each batch, and then updates the model. Similarly predictOn uses DStream.map to predict with the current version of the model.

Since Spark will serialize closures for each stage there is no need for any additional synchronization. Spark will use the current value of the model each time it computes the closure.

Effectively it equivalent to running a loop on the driver with interleaving run and predict.



来源:https://stackoverflow.com/questions/43114971/how-does-sparks-streaminglinearregressionwithsgd-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!