<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Combine MLlib Prediction and Features on Dstreams in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-MLlib-Prediction-and-Features-on-Dstreams/m-p/41414#M29919</link>
    <description>&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I need help on Dstream operation.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;In fact, I am using a MLlib randomforest model to predict using spark streaming. In the end, I want to combine the feature Dstream &amp;amp; prediction Dstream together for further downstream processing.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am predicting using below piece of code:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;predictions = texts.map( lambda x : getFeatures(x) ).map(lambda x : x.split(',')).map( lambda parts : [float(i) for i in parts] ).transform(lambda rdd: rf_model.predict(rdd))&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Here texts is dstream having single line of text as records&lt;/DIV&gt;&lt;DIV&gt;getFeatures generates a comma separated features extracted from each record&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I want the output as below tuple:&lt;/DIV&gt;&lt;DIV&gt;("predicted value", "original text")&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;How can I achieve that ?&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;or&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;at least can I perform .zip like normal RDD operation on two Dstreams, like below:&lt;/DIV&gt;&lt;DIV&gt;output = texts.zip(predictions)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Note: I posted the same problem on spark user mailing list.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks,&lt;/DIV&gt;&lt;DIV&gt;Obaid&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Sep 2022 10:22:04 GMT</pubDate>
    <dc:creator>Obaidul</dc:creator>
    <dc:date>2022-09-16T10:22:04Z</dc:date>
    <item>
      <title>Combine MLlib Prediction and Features on Dstreams</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-MLlib-Prediction-and-Features-on-Dstreams/m-p/41414#M29919</link>
      <description>&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I need help on Dstream operation.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;In fact, I am using a MLlib randomforest model to predict using spark streaming. In the end, I want to combine the feature Dstream &amp;amp; prediction Dstream together for further downstream processing.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am predicting using below piece of code:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;predictions = texts.map( lambda x : getFeatures(x) ).map(lambda x : x.split(',')).map( lambda parts : [float(i) for i in parts] ).transform(lambda rdd: rf_model.predict(rdd))&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Here texts is dstream having single line of text as records&lt;/DIV&gt;&lt;DIV&gt;getFeatures generates a comma separated features extracted from each record&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I want the output as below tuple:&lt;/DIV&gt;&lt;DIV&gt;("predicted value", "original text")&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;How can I achieve that ?&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;or&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;at least can I perform .zip like normal RDD operation on two Dstreams, like below:&lt;/DIV&gt;&lt;DIV&gt;output = texts.zip(predictions)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Note: I posted the same problem on spark user mailing list.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks,&lt;/DIV&gt;&lt;DIV&gt;Obaid&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 10:22:04 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-MLlib-Prediction-and-Features-on-Dstreams/m-p/41414#M29919</guid>
      <dc:creator>Obaidul</dc:creator>
      <dc:date>2022-09-16T10:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: Combine MLlib Prediction and Features on Dstreams</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-MLlib-Prediction-and-Features-on-Dstreams/m-p/41469#M29920</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the solution.&lt;/P&gt;&lt;P&gt;Please check my post in&amp;nbsp;&lt;SPAN&gt;stackoverflow:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://stackoverflow.com/questions/37466361/how-to-combine-two-dstreams-using-pyspark-similar-to-zip-on-normal-rdd/37537555#37537555" target="_blank"&gt;http://stackoverflow.com/questions/37466361/how-to-combine-two-dstreams-using-pyspark-similar-to-zip-on-normal-rdd/37537555#37537555&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Obaid&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2016 05:39:57 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-MLlib-Prediction-and-Features-on-Dstreams/m-p/41469#M29920</guid>
      <dc:creator>Obaidul</dc:creator>
      <dc:date>2016-05-31T05:39:57Z</dc:date>
    </item>
  </channel>
</rss>

