Spark Structured Streaming and Spark-Ml Regression










1















Is it possible to apply Spark-Ml regression to streaming sources? I see there is StreamingLogisticRegressionWithSGD but It's for older RDD API and I couldn't use It with structured streaming sources.



  1. How I'm supposed to apply regressions on structured streaming sources?

  2. (A little OT) If I cannot use streaming API for regression how can I commit offsets or so to source in a batch processing way? (Kafka sink)









share|improve this question


























    1















    Is it possible to apply Spark-Ml regression to streaming sources? I see there is StreamingLogisticRegressionWithSGD but It's for older RDD API and I couldn't use It with structured streaming sources.



    1. How I'm supposed to apply regressions on structured streaming sources?

    2. (A little OT) If I cannot use streaming API for regression how can I commit offsets or so to source in a batch processing way? (Kafka sink)









    share|improve this question
























      1












      1








      1








      Is it possible to apply Spark-Ml regression to streaming sources? I see there is StreamingLogisticRegressionWithSGD but It's for older RDD API and I couldn't use It with structured streaming sources.



      1. How I'm supposed to apply regressions on structured streaming sources?

      2. (A little OT) If I cannot use streaming API for regression how can I commit offsets or so to source in a batch processing way? (Kafka sink)









      share|improve this question














      Is it possible to apply Spark-Ml regression to streaming sources? I see there is StreamingLogisticRegressionWithSGD but It's for older RDD API and I couldn't use It with structured streaming sources.



      1. How I'm supposed to apply regressions on structured streaming sources?

      2. (A little OT) If I cannot use streaming API for regression how can I commit offsets or so to source in a batch processing way? (Kafka sink)






      apache-spark apache-spark-sql apache-spark-ml






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 14 '18 at 11:17









      ReithReith

      1,563819




      1,563819






















          1 Answer
          1






          active

          oldest

          votes


















          3














          Today (Spark 2.2 / 2.3) there is no support for machine learning in Structured Streaming and there is no ongoing work in this direction. Please follow SPARK-16424 to track future progress.



          You can however:




          • Train iterative, non-distributed models using forEach sink and some form of external state storage. At a high level regression model could be implemented like this:



            • Fetch latest model when calling ForeachWriter.open and initialize loss accumulator (not in a Spark sense, just local variable) for the partition.

            • Compute loss for each record in ForeachWriter.process and update accumulator.

            • Push loses to external store when calling ForeachWriter.close.

            • This would leave external storage in charge with computing gradient and updating model with implementation dependent on the store.


          • Try to hack SQL queries (see https://github.com/holdenk/spark-structured-streaming-ml by Holden Karau)






          share|improve this answer

























          • Thanks. Can you elaborate more about forEach method? As I understand It's a method to do some action (like writing to db) on each Row. But for applying regression I need to do some action (training and evaluating) on a dataset.

            – Reith
            Jan 14 '18 at 11:41











          • Thanks. I think I'll give up with streaming API since by external storage which computes gradients I feel I won't get any help from spark-ml.

            – Reith
            Jan 14 '18 at 11:50












          • True, although it might sound more serious than it is. After all with GD it is just a one line with any decent linear algebra lib. But if you're looking for built-in support in Structured Streaming there is none at the moment.

            – hi-zir
            Jan 14 '18 at 11:57










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48249017%2fspark-structured-streaming-and-spark-ml-regression%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          Today (Spark 2.2 / 2.3) there is no support for machine learning in Structured Streaming and there is no ongoing work in this direction. Please follow SPARK-16424 to track future progress.



          You can however:




          • Train iterative, non-distributed models using forEach sink and some form of external state storage. At a high level regression model could be implemented like this:



            • Fetch latest model when calling ForeachWriter.open and initialize loss accumulator (not in a Spark sense, just local variable) for the partition.

            • Compute loss for each record in ForeachWriter.process and update accumulator.

            • Push loses to external store when calling ForeachWriter.close.

            • This would leave external storage in charge with computing gradient and updating model with implementation dependent on the store.


          • Try to hack SQL queries (see https://github.com/holdenk/spark-structured-streaming-ml by Holden Karau)






          share|improve this answer

























          • Thanks. Can you elaborate more about forEach method? As I understand It's a method to do some action (like writing to db) on each Row. But for applying regression I need to do some action (training and evaluating) on a dataset.

            – Reith
            Jan 14 '18 at 11:41











          • Thanks. I think I'll give up with streaming API since by external storage which computes gradients I feel I won't get any help from spark-ml.

            – Reith
            Jan 14 '18 at 11:50












          • True, although it might sound more serious than it is. After all with GD it is just a one line with any decent linear algebra lib. But if you're looking for built-in support in Structured Streaming there is none at the moment.

            – hi-zir
            Jan 14 '18 at 11:57















          3














          Today (Spark 2.2 / 2.3) there is no support for machine learning in Structured Streaming and there is no ongoing work in this direction. Please follow SPARK-16424 to track future progress.



          You can however:




          • Train iterative, non-distributed models using forEach sink and some form of external state storage. At a high level regression model could be implemented like this:



            • Fetch latest model when calling ForeachWriter.open and initialize loss accumulator (not in a Spark sense, just local variable) for the partition.

            • Compute loss for each record in ForeachWriter.process and update accumulator.

            • Push loses to external store when calling ForeachWriter.close.

            • This would leave external storage in charge with computing gradient and updating model with implementation dependent on the store.


          • Try to hack SQL queries (see https://github.com/holdenk/spark-structured-streaming-ml by Holden Karau)






          share|improve this answer

























          • Thanks. Can you elaborate more about forEach method? As I understand It's a method to do some action (like writing to db) on each Row. But for applying regression I need to do some action (training and evaluating) on a dataset.

            – Reith
            Jan 14 '18 at 11:41











          • Thanks. I think I'll give up with streaming API since by external storage which computes gradients I feel I won't get any help from spark-ml.

            – Reith
            Jan 14 '18 at 11:50












          • True, although it might sound more serious than it is. After all with GD it is just a one line with any decent linear algebra lib. But if you're looking for built-in support in Structured Streaming there is none at the moment.

            – hi-zir
            Jan 14 '18 at 11:57













          3












          3








          3







          Today (Spark 2.2 / 2.3) there is no support for machine learning in Structured Streaming and there is no ongoing work in this direction. Please follow SPARK-16424 to track future progress.



          You can however:




          • Train iterative, non-distributed models using forEach sink and some form of external state storage. At a high level regression model could be implemented like this:



            • Fetch latest model when calling ForeachWriter.open and initialize loss accumulator (not in a Spark sense, just local variable) for the partition.

            • Compute loss for each record in ForeachWriter.process and update accumulator.

            • Push loses to external store when calling ForeachWriter.close.

            • This would leave external storage in charge with computing gradient and updating model with implementation dependent on the store.


          • Try to hack SQL queries (see https://github.com/holdenk/spark-structured-streaming-ml by Holden Karau)






          share|improve this answer















          Today (Spark 2.2 / 2.3) there is no support for machine learning in Structured Streaming and there is no ongoing work in this direction. Please follow SPARK-16424 to track future progress.



          You can however:




          • Train iterative, non-distributed models using forEach sink and some form of external state storage. At a high level regression model could be implemented like this:



            • Fetch latest model when calling ForeachWriter.open and initialize loss accumulator (not in a Spark sense, just local variable) for the partition.

            • Compute loss for each record in ForeachWriter.process and update accumulator.

            • Push loses to external store when calling ForeachWriter.close.

            • This would leave external storage in charge with computing gradient and updating model with implementation dependent on the store.


          • Try to hack SQL queries (see https://github.com/holdenk/spark-structured-streaming-ml by Holden Karau)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 14 '18 at 11:43


























          community wiki





          3 revs
          user8371915













          • Thanks. Can you elaborate more about forEach method? As I understand It's a method to do some action (like writing to db) on each Row. But for applying regression I need to do some action (training and evaluating) on a dataset.

            – Reith
            Jan 14 '18 at 11:41











          • Thanks. I think I'll give up with streaming API since by external storage which computes gradients I feel I won't get any help from spark-ml.

            – Reith
            Jan 14 '18 at 11:50












          • True, although it might sound more serious than it is. After all with GD it is just a one line with any decent linear algebra lib. But if you're looking for built-in support in Structured Streaming there is none at the moment.

            – hi-zir
            Jan 14 '18 at 11:57

















          • Thanks. Can you elaborate more about forEach method? As I understand It's a method to do some action (like writing to db) on each Row. But for applying regression I need to do some action (training and evaluating) on a dataset.

            – Reith
            Jan 14 '18 at 11:41











          • Thanks. I think I'll give up with streaming API since by external storage which computes gradients I feel I won't get any help from spark-ml.

            – Reith
            Jan 14 '18 at 11:50












          • True, although it might sound more serious than it is. After all with GD it is just a one line with any decent linear algebra lib. But if you're looking for built-in support in Structured Streaming there is none at the moment.

            – hi-zir
            Jan 14 '18 at 11:57
















          Thanks. Can you elaborate more about forEach method? As I understand It's a method to do some action (like writing to db) on each Row. But for applying regression I need to do some action (training and evaluating) on a dataset.

          – Reith
          Jan 14 '18 at 11:41





          Thanks. Can you elaborate more about forEach method? As I understand It's a method to do some action (like writing to db) on each Row. But for applying regression I need to do some action (training and evaluating) on a dataset.

          – Reith
          Jan 14 '18 at 11:41













          Thanks. I think I'll give up with streaming API since by external storage which computes gradients I feel I won't get any help from spark-ml.

          – Reith
          Jan 14 '18 at 11:50






          Thanks. I think I'll give up with streaming API since by external storage which computes gradients I feel I won't get any help from spark-ml.

          – Reith
          Jan 14 '18 at 11:50














          True, although it might sound more serious than it is. After all with GD it is just a one line with any decent linear algebra lib. But if you're looking for built-in support in Structured Streaming there is none at the moment.

          – hi-zir
          Jan 14 '18 at 11:57





          True, although it might sound more serious than it is. After all with GD it is just a one line with any decent linear algebra lib. But if you're looking for built-in support in Structured Streaming there is none at the moment.

          – hi-zir
          Jan 14 '18 at 11:57

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48249017%2fspark-structured-streaming-and-spark-ml-regression%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo