How to do add and subtraction in between three inputs for predict the value using python












0












$begingroup$


This question is related to this unsupported operand type(s) for -: 'list' and 'list' using python
I want to predict value according to the three inputs(X1,X2,X3) . for prediction value,
three inputs
X1-X2+X3 = predict value
according to this algorithm value will be predicted using LSTM neural network. I wrote the code but it gives me so many errors. Can anyone suggest me to solve this error?
here is my code:



data.columns = ['X1', 'X2', 'X3','Y']
data = data.dropna ()
y =data['Y'].astype(int)
cols=['X1', 'X2', 'X3']
x=data[cols].astype(int)
scaler_x = preprocessing.MinMaxScaler(feature_range =(-1, 1))
x = np.array(x).reshape ((len(x),3 ))
x = scaler_x.fit_transform(x)
scaler_y = preprocessing.MinMaxScaler(feature_range =(-1, 1))
y = np.array(y).reshape ((len(y), 1))
y = scaler_y.fit_transform(y)
n = data.shape[0]
p = data.shape[1]
data = data.values
a =
for i in range(0,len(data)):
X1 = data[i][0]
a.append([X1])
b =
for i in range(0,len(data)):
X2 = data[i][1]
b.append([X2])
c =
for i in range(0,len(data)):
X3 = data[i][2]
c.append([X3])

train_start = 0
train_end = int(np.floor(0.8*n))
test_start = train_end+1
test_end = n
x_train = x[np.arange(train_start, train_end), :]
x_test = x[np.arange(test_start, test_end), :]
y_train = y[np.arange(train_start, train_end), :]
y_test = y[np.arange(test_start, test_end), :]
x_train=x_train.reshape(x_train.shape +(1,))
x_test=x_test.reshape(x_test.shape + (1,))

for i in range(len(x_train)):
x_train.append([a[i] ,b[i], c[i]])
x.append((a[i][0] - b[i][0] + c[i][0]))
x_train =np.array(x_train)
x = np.array(x)
seed = 20
np.random.seed(seed)
fit1 = Sequential ()
fit1.add(LSTM(
output_dim = 5,
activation='relu',
input_shape =(3,1)))
fit1.add(Dense(output_dim =1))
fit1.add(Activation(linear))

batchsize = 1
fit1.compile(loss="mean_squared_error",optimizer="adam")
#train the model
fit1.fit(x_train , y_train , batch_size = batchsize, nb_epoch =1, shuffle=True)
score_train = fit1.evaluate(x_train ,y_train ,batch_size =batchsize)
score_test = fit1.evaluate(x_test , y_test ,batch_size =batchsize)
#Make prediction
pred1=fit1.predict(x_test)
#data=pd.DataFrame(fit1.predict(x_test))
pred1 = scaler_y.inverse_transform(np.array(pred1).reshape ((len(pred1), 1)))
real_test = scaler_y.inverse_transform(np.array(y_test).reshape ((len(y_test)))


Here is my csv file;



enter image description here










share|improve this question









$endgroup$

















    0












    $begingroup$


    This question is related to this unsupported operand type(s) for -: 'list' and 'list' using python
    I want to predict value according to the three inputs(X1,X2,X3) . for prediction value,
    three inputs
    X1-X2+X3 = predict value
    according to this algorithm value will be predicted using LSTM neural network. I wrote the code but it gives me so many errors. Can anyone suggest me to solve this error?
    here is my code:



    data.columns = ['X1', 'X2', 'X3','Y']
    data = data.dropna ()
    y =data['Y'].astype(int)
    cols=['X1', 'X2', 'X3']
    x=data[cols].astype(int)
    scaler_x = preprocessing.MinMaxScaler(feature_range =(-1, 1))
    x = np.array(x).reshape ((len(x),3 ))
    x = scaler_x.fit_transform(x)
    scaler_y = preprocessing.MinMaxScaler(feature_range =(-1, 1))
    y = np.array(y).reshape ((len(y), 1))
    y = scaler_y.fit_transform(y)
    n = data.shape[0]
    p = data.shape[1]
    data = data.values
    a =
    for i in range(0,len(data)):
    X1 = data[i][0]
    a.append([X1])
    b =
    for i in range(0,len(data)):
    X2 = data[i][1]
    b.append([X2])
    c =
    for i in range(0,len(data)):
    X3 = data[i][2]
    c.append([X3])

    train_start = 0
    train_end = int(np.floor(0.8*n))
    test_start = train_end+1
    test_end = n
    x_train = x[np.arange(train_start, train_end), :]
    x_test = x[np.arange(test_start, test_end), :]
    y_train = y[np.arange(train_start, train_end), :]
    y_test = y[np.arange(test_start, test_end), :]
    x_train=x_train.reshape(x_train.shape +(1,))
    x_test=x_test.reshape(x_test.shape + (1,))

    for i in range(len(x_train)):
    x_train.append([a[i] ,b[i], c[i]])
    x.append((a[i][0] - b[i][0] + c[i][0]))
    x_train =np.array(x_train)
    x = np.array(x)
    seed = 20
    np.random.seed(seed)
    fit1 = Sequential ()
    fit1.add(LSTM(
    output_dim = 5,
    activation='relu',
    input_shape =(3,1)))
    fit1.add(Dense(output_dim =1))
    fit1.add(Activation(linear))

    batchsize = 1
    fit1.compile(loss="mean_squared_error",optimizer="adam")
    #train the model
    fit1.fit(x_train , y_train , batch_size = batchsize, nb_epoch =1, shuffle=True)
    score_train = fit1.evaluate(x_train ,y_train ,batch_size =batchsize)
    score_test = fit1.evaluate(x_test , y_test ,batch_size =batchsize)
    #Make prediction
    pred1=fit1.predict(x_test)
    #data=pd.DataFrame(fit1.predict(x_test))
    pred1 = scaler_y.inverse_transform(np.array(pred1).reshape ((len(pred1), 1)))
    real_test = scaler_y.inverse_transform(np.array(y_test).reshape ((len(y_test)))


    Here is my csv file;



    enter image description here










    share|improve this question









    $endgroup$















      0












      0








      0





      $begingroup$


      This question is related to this unsupported operand type(s) for -: 'list' and 'list' using python
      I want to predict value according to the three inputs(X1,X2,X3) . for prediction value,
      three inputs
      X1-X2+X3 = predict value
      according to this algorithm value will be predicted using LSTM neural network. I wrote the code but it gives me so many errors. Can anyone suggest me to solve this error?
      here is my code:



      data.columns = ['X1', 'X2', 'X3','Y']
      data = data.dropna ()
      y =data['Y'].astype(int)
      cols=['X1', 'X2', 'X3']
      x=data[cols].astype(int)
      scaler_x = preprocessing.MinMaxScaler(feature_range =(-1, 1))
      x = np.array(x).reshape ((len(x),3 ))
      x = scaler_x.fit_transform(x)
      scaler_y = preprocessing.MinMaxScaler(feature_range =(-1, 1))
      y = np.array(y).reshape ((len(y), 1))
      y = scaler_y.fit_transform(y)
      n = data.shape[0]
      p = data.shape[1]
      data = data.values
      a =
      for i in range(0,len(data)):
      X1 = data[i][0]
      a.append([X1])
      b =
      for i in range(0,len(data)):
      X2 = data[i][1]
      b.append([X2])
      c =
      for i in range(0,len(data)):
      X3 = data[i][2]
      c.append([X3])

      train_start = 0
      train_end = int(np.floor(0.8*n))
      test_start = train_end+1
      test_end = n
      x_train = x[np.arange(train_start, train_end), :]
      x_test = x[np.arange(test_start, test_end), :]
      y_train = y[np.arange(train_start, train_end), :]
      y_test = y[np.arange(test_start, test_end), :]
      x_train=x_train.reshape(x_train.shape +(1,))
      x_test=x_test.reshape(x_test.shape + (1,))

      for i in range(len(x_train)):
      x_train.append([a[i] ,b[i], c[i]])
      x.append((a[i][0] - b[i][0] + c[i][0]))
      x_train =np.array(x_train)
      x = np.array(x)
      seed = 20
      np.random.seed(seed)
      fit1 = Sequential ()
      fit1.add(LSTM(
      output_dim = 5,
      activation='relu',
      input_shape =(3,1)))
      fit1.add(Dense(output_dim =1))
      fit1.add(Activation(linear))

      batchsize = 1
      fit1.compile(loss="mean_squared_error",optimizer="adam")
      #train the model
      fit1.fit(x_train , y_train , batch_size = batchsize, nb_epoch =1, shuffle=True)
      score_train = fit1.evaluate(x_train ,y_train ,batch_size =batchsize)
      score_test = fit1.evaluate(x_test , y_test ,batch_size =batchsize)
      #Make prediction
      pred1=fit1.predict(x_test)
      #data=pd.DataFrame(fit1.predict(x_test))
      pred1 = scaler_y.inverse_transform(np.array(pred1).reshape ((len(pred1), 1)))
      real_test = scaler_y.inverse_transform(np.array(y_test).reshape ((len(y_test)))


      Here is my csv file;



      enter image description here










      share|improve this question









      $endgroup$




      This question is related to this unsupported operand type(s) for -: 'list' and 'list' using python
      I want to predict value according to the three inputs(X1,X2,X3) . for prediction value,
      three inputs
      X1-X2+X3 = predict value
      according to this algorithm value will be predicted using LSTM neural network. I wrote the code but it gives me so many errors. Can anyone suggest me to solve this error?
      here is my code:



      data.columns = ['X1', 'X2', 'X3','Y']
      data = data.dropna ()
      y =data['Y'].astype(int)
      cols=['X1', 'X2', 'X3']
      x=data[cols].astype(int)
      scaler_x = preprocessing.MinMaxScaler(feature_range =(-1, 1))
      x = np.array(x).reshape ((len(x),3 ))
      x = scaler_x.fit_transform(x)
      scaler_y = preprocessing.MinMaxScaler(feature_range =(-1, 1))
      y = np.array(y).reshape ((len(y), 1))
      y = scaler_y.fit_transform(y)
      n = data.shape[0]
      p = data.shape[1]
      data = data.values
      a =
      for i in range(0,len(data)):
      X1 = data[i][0]
      a.append([X1])
      b =
      for i in range(0,len(data)):
      X2 = data[i][1]
      b.append([X2])
      c =
      for i in range(0,len(data)):
      X3 = data[i][2]
      c.append([X3])

      train_start = 0
      train_end = int(np.floor(0.8*n))
      test_start = train_end+1
      test_end = n
      x_train = x[np.arange(train_start, train_end), :]
      x_test = x[np.arange(test_start, test_end), :]
      y_train = y[np.arange(train_start, train_end), :]
      y_test = y[np.arange(test_start, test_end), :]
      x_train=x_train.reshape(x_train.shape +(1,))
      x_test=x_test.reshape(x_test.shape + (1,))

      for i in range(len(x_train)):
      x_train.append([a[i] ,b[i], c[i]])
      x.append((a[i][0] - b[i][0] + c[i][0]))
      x_train =np.array(x_train)
      x = np.array(x)
      seed = 20
      np.random.seed(seed)
      fit1 = Sequential ()
      fit1.add(LSTM(
      output_dim = 5,
      activation='relu',
      input_shape =(3,1)))
      fit1.add(Dense(output_dim =1))
      fit1.add(Activation(linear))

      batchsize = 1
      fit1.compile(loss="mean_squared_error",optimizer="adam")
      #train the model
      fit1.fit(x_train , y_train , batch_size = batchsize, nb_epoch =1, shuffle=True)
      score_train = fit1.evaluate(x_train ,y_train ,batch_size =batchsize)
      score_test = fit1.evaluate(x_test , y_test ,batch_size =batchsize)
      #Make prediction
      pred1=fit1.predict(x_test)
      #data=pd.DataFrame(fit1.predict(x_test))
      pred1 = scaler_y.inverse_transform(np.array(pred1).reshape ((len(pred1), 1)))
      real_test = scaler_y.inverse_transform(np.array(y_test).reshape ((len(y_test)))


      Here is my csv file;



      enter image description here







      python lstm






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 30 mins ago









      kaskas

      477




      477






















          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%2f45244%2fhow-to-do-add-and-subtraction-in-between-three-inputs-for-predict-the-value-usin%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%2f45244%2fhow-to-do-add-and-subtraction-in-between-three-inputs-for-predict-the-value-usin%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