Keras prediction from saved model












0












$begingroup$


I created a regression ML model in Keras on a different PC, saved the model, and now I am attempting to create an addition pandas dataframe of 'modeled' data. And finally .sum() the modelled data.



There is not a lot of wisdom in this experiment, so my methods could most like be improved on... Feel free to give me any tips :)



This script below will take my .h5 model weights and I can recreate the model architecture to make some predictions in keras. Ultimately at the bottom I am attempting to create the additional pandas df, with a data['calcKwh'] = data['kWh'].apply(lambda x: method..



Opening up the file in Excel, this is how the data looks. One part I am not sure is correct is I am attempting utilize rows in the CSV `data.loc[: , "runTime":"vacation"] Runtime thru vacation, these are my input variables. And the target variable highlighted yellow is kWh.



enter image description here



Scipt.py file runs and calculates 'values' but it doesn't appear to calculate just one sum of the calcKwh df… I am not sure where I am going wrong..



from keras.models import load_model
from keras.models import Sequential
from keras.layers import Dense
import os
import numpy as np
import pandas as pd
import math


#path to saved model
weights_path = "C:/Users/bbartling/Desktop/EC/kwhFinal_backup.h5"

#load data
data = pd.read_csv("joinedRuntime2.csv", index_col='Date', parse_dates=True)

def create_model():
model = Sequential()
model.add(Dense(60, input_dim=7, kernel_initializer='normal', activation='relu'))
model.add(Dense(55, kernel_initializer='normal', activation='relu'))
model.add(Dense(50, kernel_initializer='normal', activation='relu'))
model.add(Dense(45, kernel_initializer='normal', activation='relu'))
model.add(Dense(30, kernel_initializer='normal', activation='relu'))
model.add(Dense(20, kernel_initializer='normal', activation='relu'))
model.add(Dense(1, kernel_initializer='normal'))
return model


def load_trained_model(weights_path):
model = create_model()
model.load_weights(weights_path)
return model


#select columns in the CSV runTime thru vacation
params = np.array(data.loc[: , "runTime":"vacation"])


if (params.ndim == 1):
params = np.array([params])

data['calcKwh'] = data['kWh'].apply(lambda x: load_trained_model(weights_path).predict(params))

print(data['calcKwh'].sum())









share|improve this question









$endgroup$

















    0












    $begingroup$


    I created a regression ML model in Keras on a different PC, saved the model, and now I am attempting to create an addition pandas dataframe of 'modeled' data. And finally .sum() the modelled data.



    There is not a lot of wisdom in this experiment, so my methods could most like be improved on... Feel free to give me any tips :)



    This script below will take my .h5 model weights and I can recreate the model architecture to make some predictions in keras. Ultimately at the bottom I am attempting to create the additional pandas df, with a data['calcKwh'] = data['kWh'].apply(lambda x: method..



    Opening up the file in Excel, this is how the data looks. One part I am not sure is correct is I am attempting utilize rows in the CSV `data.loc[: , "runTime":"vacation"] Runtime thru vacation, these are my input variables. And the target variable highlighted yellow is kWh.



    enter image description here



    Scipt.py file runs and calculates 'values' but it doesn't appear to calculate just one sum of the calcKwh df… I am not sure where I am going wrong..



    from keras.models import load_model
    from keras.models import Sequential
    from keras.layers import Dense
    import os
    import numpy as np
    import pandas as pd
    import math


    #path to saved model
    weights_path = "C:/Users/bbartling/Desktop/EC/kwhFinal_backup.h5"

    #load data
    data = pd.read_csv("joinedRuntime2.csv", index_col='Date', parse_dates=True)

    def create_model():
    model = Sequential()
    model.add(Dense(60, input_dim=7, kernel_initializer='normal', activation='relu'))
    model.add(Dense(55, kernel_initializer='normal', activation='relu'))
    model.add(Dense(50, kernel_initializer='normal', activation='relu'))
    model.add(Dense(45, kernel_initializer='normal', activation='relu'))
    model.add(Dense(30, kernel_initializer='normal', activation='relu'))
    model.add(Dense(20, kernel_initializer='normal', activation='relu'))
    model.add(Dense(1, kernel_initializer='normal'))
    return model


    def load_trained_model(weights_path):
    model = create_model()
    model.load_weights(weights_path)
    return model


    #select columns in the CSV runTime thru vacation
    params = np.array(data.loc[: , "runTime":"vacation"])


    if (params.ndim == 1):
    params = np.array([params])

    data['calcKwh'] = data['kWh'].apply(lambda x: load_trained_model(weights_path).predict(params))

    print(data['calcKwh'].sum())









    share|improve this question









    $endgroup$















      0












      0








      0





      $begingroup$


      I created a regression ML model in Keras on a different PC, saved the model, and now I am attempting to create an addition pandas dataframe of 'modeled' data. And finally .sum() the modelled data.



      There is not a lot of wisdom in this experiment, so my methods could most like be improved on... Feel free to give me any tips :)



      This script below will take my .h5 model weights and I can recreate the model architecture to make some predictions in keras. Ultimately at the bottom I am attempting to create the additional pandas df, with a data['calcKwh'] = data['kWh'].apply(lambda x: method..



      Opening up the file in Excel, this is how the data looks. One part I am not sure is correct is I am attempting utilize rows in the CSV `data.loc[: , "runTime":"vacation"] Runtime thru vacation, these are my input variables. And the target variable highlighted yellow is kWh.



      enter image description here



      Scipt.py file runs and calculates 'values' but it doesn't appear to calculate just one sum of the calcKwh df… I am not sure where I am going wrong..



      from keras.models import load_model
      from keras.models import Sequential
      from keras.layers import Dense
      import os
      import numpy as np
      import pandas as pd
      import math


      #path to saved model
      weights_path = "C:/Users/bbartling/Desktop/EC/kwhFinal_backup.h5"

      #load data
      data = pd.read_csv("joinedRuntime2.csv", index_col='Date', parse_dates=True)

      def create_model():
      model = Sequential()
      model.add(Dense(60, input_dim=7, kernel_initializer='normal', activation='relu'))
      model.add(Dense(55, kernel_initializer='normal', activation='relu'))
      model.add(Dense(50, kernel_initializer='normal', activation='relu'))
      model.add(Dense(45, kernel_initializer='normal', activation='relu'))
      model.add(Dense(30, kernel_initializer='normal', activation='relu'))
      model.add(Dense(20, kernel_initializer='normal', activation='relu'))
      model.add(Dense(1, kernel_initializer='normal'))
      return model


      def load_trained_model(weights_path):
      model = create_model()
      model.load_weights(weights_path)
      return model


      #select columns in the CSV runTime thru vacation
      params = np.array(data.loc[: , "runTime":"vacation"])


      if (params.ndim == 1):
      params = np.array([params])

      data['calcKwh'] = data['kWh'].apply(lambda x: load_trained_model(weights_path).predict(params))

      print(data['calcKwh'].sum())









      share|improve this question









      $endgroup$




      I created a regression ML model in Keras on a different PC, saved the model, and now I am attempting to create an addition pandas dataframe of 'modeled' data. And finally .sum() the modelled data.



      There is not a lot of wisdom in this experiment, so my methods could most like be improved on... Feel free to give me any tips :)



      This script below will take my .h5 model weights and I can recreate the model architecture to make some predictions in keras. Ultimately at the bottom I am attempting to create the additional pandas df, with a data['calcKwh'] = data['kWh'].apply(lambda x: method..



      Opening up the file in Excel, this is how the data looks. One part I am not sure is correct is I am attempting utilize rows in the CSV `data.loc[: , "runTime":"vacation"] Runtime thru vacation, these are my input variables. And the target variable highlighted yellow is kWh.



      enter image description here



      Scipt.py file runs and calculates 'values' but it doesn't appear to calculate just one sum of the calcKwh df… I am not sure where I am going wrong..



      from keras.models import load_model
      from keras.models import Sequential
      from keras.layers import Dense
      import os
      import numpy as np
      import pandas as pd
      import math


      #path to saved model
      weights_path = "C:/Users/bbartling/Desktop/EC/kwhFinal_backup.h5"

      #load data
      data = pd.read_csv("joinedRuntime2.csv", index_col='Date', parse_dates=True)

      def create_model():
      model = Sequential()
      model.add(Dense(60, input_dim=7, kernel_initializer='normal', activation='relu'))
      model.add(Dense(55, kernel_initializer='normal', activation='relu'))
      model.add(Dense(50, kernel_initializer='normal', activation='relu'))
      model.add(Dense(45, kernel_initializer='normal', activation='relu'))
      model.add(Dense(30, kernel_initializer='normal', activation='relu'))
      model.add(Dense(20, kernel_initializer='normal', activation='relu'))
      model.add(Dense(1, kernel_initializer='normal'))
      return model


      def load_trained_model(weights_path):
      model = create_model()
      model.load_weights(weights_path)
      return model


      #select columns in the CSV runTime thru vacation
      params = np.array(data.loc[: , "runTime":"vacation"])


      if (params.ndim == 1):
      params = np.array([params])

      data['calcKwh'] = data['kWh'].apply(lambda x: load_trained_model(weights_path).predict(params))

      print(data['calcKwh'].sum())






      machine-learning python keras regression data-science-model






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      HenryHubHenryHub

      1567




      1567






















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "557"
          };
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2fdatascience.stackexchange.com%2fquestions%2f46944%2fkeras-prediction-from-saved-model%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Data Science Stack Exchange!


          • 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.


          Use MathJax to format equations. MathJax reference.


          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%2fdatascience.stackexchange.com%2fquestions%2f46944%2fkeras-prediction-from-saved-model%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

          How to label and detect the document text images

          Vallis Paradisi

          Tabula Rosettana