Keras: How to connect a CNN model with a decision tree












0












$begingroup$


I want to train a model to predict one's emotion from the physical signals. I have a physical signal and using it as input feature;




ecg(Electrocardiography)




I want to use the CNN architecture to extract features from the data, and then use these extracted features to feed a classical "Decision Tree Classifier". Below, you can see my CNN aproach without the decision tree;



model = Sequential()
model.add(Conv1D(15,60,padding='valid', activation='relu',input_shape=(18000,1), strides = 1, kernel_regularizer=regularizers.l1_l2(l1=0.1, l2=0.1)))
model.add(MaxPooling1D(2,data_format='channels_last'))
model.add(Dropout(0.6))
model.add(BatchNormalization())
model.add(Conv1D(30, 60, padding='valid', activation='relu',kernel_regularizer = regularizers.l1_l2(l1=0.1, l2=0.1), strides=1))
model.add(MaxPooling1D(4,data_format='channels_last'))
model.add(Dropout(0.6))
model.add(BatchNormalization())
model.add(Flatten())
model.add(Dense(3, activation = 'softmax'))


I want to edit this code so that, in the output layer there will be working decision tree instead of model.add(Dense(3, activation = 'softmax')). I have tried to save the outputs of the last convolutional layer like this;



output = model.layers[-6].output


And when I printed out the output variable, result was this;




THE OUTPUT: Tensor("conv1d_56/Relu:0", shape=(?, 8971, 30),
dtype=float32)




I guess, the output variable holds the extracted features. Now, how can I feed my decision tree classifier model with this data which is stored in the output variable? Here is the decision tree from scikit learn;



from sklearn.tree import DecisionTreeClassifier

dtc = DecisionTreeClassifier(criterion = 'entropy')
dtc.fit()


How should I feed the fit() method? Thanks in advance.









share









$endgroup$

















    0












    $begingroup$


    I want to train a model to predict one's emotion from the physical signals. I have a physical signal and using it as input feature;




    ecg(Electrocardiography)




    I want to use the CNN architecture to extract features from the data, and then use these extracted features to feed a classical "Decision Tree Classifier". Below, you can see my CNN aproach without the decision tree;



    model = Sequential()
    model.add(Conv1D(15,60,padding='valid', activation='relu',input_shape=(18000,1), strides = 1, kernel_regularizer=regularizers.l1_l2(l1=0.1, l2=0.1)))
    model.add(MaxPooling1D(2,data_format='channels_last'))
    model.add(Dropout(0.6))
    model.add(BatchNormalization())
    model.add(Conv1D(30, 60, padding='valid', activation='relu',kernel_regularizer = regularizers.l1_l2(l1=0.1, l2=0.1), strides=1))
    model.add(MaxPooling1D(4,data_format='channels_last'))
    model.add(Dropout(0.6))
    model.add(BatchNormalization())
    model.add(Flatten())
    model.add(Dense(3, activation = 'softmax'))


    I want to edit this code so that, in the output layer there will be working decision tree instead of model.add(Dense(3, activation = 'softmax')). I have tried to save the outputs of the last convolutional layer like this;



    output = model.layers[-6].output


    And when I printed out the output variable, result was this;




    THE OUTPUT: Tensor("conv1d_56/Relu:0", shape=(?, 8971, 30),
    dtype=float32)




    I guess, the output variable holds the extracted features. Now, how can I feed my decision tree classifier model with this data which is stored in the output variable? Here is the decision tree from scikit learn;



    from sklearn.tree import DecisionTreeClassifier

    dtc = DecisionTreeClassifier(criterion = 'entropy')
    dtc.fit()


    How should I feed the fit() method? Thanks in advance.









    share









    $endgroup$















      0












      0








      0





      $begingroup$


      I want to train a model to predict one's emotion from the physical signals. I have a physical signal and using it as input feature;




      ecg(Electrocardiography)




      I want to use the CNN architecture to extract features from the data, and then use these extracted features to feed a classical "Decision Tree Classifier". Below, you can see my CNN aproach without the decision tree;



      model = Sequential()
      model.add(Conv1D(15,60,padding='valid', activation='relu',input_shape=(18000,1), strides = 1, kernel_regularizer=regularizers.l1_l2(l1=0.1, l2=0.1)))
      model.add(MaxPooling1D(2,data_format='channels_last'))
      model.add(Dropout(0.6))
      model.add(BatchNormalization())
      model.add(Conv1D(30, 60, padding='valid', activation='relu',kernel_regularizer = regularizers.l1_l2(l1=0.1, l2=0.1), strides=1))
      model.add(MaxPooling1D(4,data_format='channels_last'))
      model.add(Dropout(0.6))
      model.add(BatchNormalization())
      model.add(Flatten())
      model.add(Dense(3, activation = 'softmax'))


      I want to edit this code so that, in the output layer there will be working decision tree instead of model.add(Dense(3, activation = 'softmax')). I have tried to save the outputs of the last convolutional layer like this;



      output = model.layers[-6].output


      And when I printed out the output variable, result was this;




      THE OUTPUT: Tensor("conv1d_56/Relu:0", shape=(?, 8971, 30),
      dtype=float32)




      I guess, the output variable holds the extracted features. Now, how can I feed my decision tree classifier model with this data which is stored in the output variable? Here is the decision tree from scikit learn;



      from sklearn.tree import DecisionTreeClassifier

      dtc = DecisionTreeClassifier(criterion = 'entropy')
      dtc.fit()


      How should I feed the fit() method? Thanks in advance.









      share









      $endgroup$




      I want to train a model to predict one's emotion from the physical signals. I have a physical signal and using it as input feature;




      ecg(Electrocardiography)




      I want to use the CNN architecture to extract features from the data, and then use these extracted features to feed a classical "Decision Tree Classifier". Below, you can see my CNN aproach without the decision tree;



      model = Sequential()
      model.add(Conv1D(15,60,padding='valid', activation='relu',input_shape=(18000,1), strides = 1, kernel_regularizer=regularizers.l1_l2(l1=0.1, l2=0.1)))
      model.add(MaxPooling1D(2,data_format='channels_last'))
      model.add(Dropout(0.6))
      model.add(BatchNormalization())
      model.add(Conv1D(30, 60, padding='valid', activation='relu',kernel_regularizer = regularizers.l1_l2(l1=0.1, l2=0.1), strides=1))
      model.add(MaxPooling1D(4,data_format='channels_last'))
      model.add(Dropout(0.6))
      model.add(BatchNormalization())
      model.add(Flatten())
      model.add(Dense(3, activation = 'softmax'))


      I want to edit this code so that, in the output layer there will be working decision tree instead of model.add(Dense(3, activation = 'softmax')). I have tried to save the outputs of the last convolutional layer like this;



      output = model.layers[-6].output


      And when I printed out the output variable, result was this;




      THE OUTPUT: Tensor("conv1d_56/Relu:0", shape=(?, 8971, 30),
      dtype=float32)




      I guess, the output variable holds the extracted features. Now, how can I feed my decision tree classifier model with this data which is stored in the output variable? Here is the decision tree from scikit learn;



      from sklearn.tree import DecisionTreeClassifier

      dtc = DecisionTreeClassifier(criterion = 'entropy')
      dtc.fit()


      How should I feed the fit() method? Thanks in advance.







      deep-learning classification keras scikit-learn decision-trees





      share












      share










      share



      share










      asked 5 mins ago









      Ozan YurtseverOzan Yurtsever

      1085




      1085






















          0






          active

          oldest

          votes












          Your Answer








          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%2f51100%2fkeras-how-to-connect-a-cnn-model-with-a-decision-tree%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%2f51100%2fkeras-how-to-connect-a-cnn-model-with-a-decision-tree%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

          Aikido

          Tivadar Csontváry Kosztka

          Metroo de Marsejlo