Is this a data issue, or a model issue? A Keras binary classification model












0












$begingroup$


I've been trying to create a binary classification model that predicts wether there will be a train delay based on the train and time. Here is a link to the data



The issue I'm having is that my accuracy goes to 94.07 in the first 5 epochs. Meanwhile, my class prediction will always be 0 and never 1.



From what I understand, this is "Accuracy Paradox". A symptom of Class Imbalance. To combat this, I implemented Kfold.



kfold = StratifiedKFold(n_splits=10,shuffle=True)
cvs_scores =

for train,test in kfold.split(X,Y):

history = model.fit(X[train],Y[train],epochs=50,batch_size=15, shuffle = False, verbose = 1)
scores = model.evaluate(X[test],Y[test],verbose=0)

print("%s: %.2f%%" % (model.metrics_names[1],scores[1]*100))
cvs_scores.append(scores[1] * 100)

print("%.2f%% (+/- %.2f%%)" % (numpy.mean(cvs_scores),numpy.std(cvs_scores)))


No luck. Still had the same issue as before.



Here is how I import my data:



raw_data = pd.read_csv('MTA_DELAY_DATA_DUMP - Sheet1.csv')

X = raw_data.iloc[1:-2,0:2].dropna().values
Y = raw_data.iloc[1:-2,2:3].dropna().astype(int).values


My Model:



model = Sequential()
model.add(Dense(32, kernel_initializer='uniform', activation='relu',input_dim =2))
model.add(Dense(16, kernel_initializer='uniform', activation='relu'))
model.add(Dense(8, kernel_initializer='uniform', activation='relu'))
model.add(Dense(1, kernel_initializer='uniform', activation='sigmoid'))

model.compile(loss='binary_crossentropy', optimizer=Adam(lr=0.001),metrics=['accuracy'])
history = model.fit(X,Y,epochs=150,batch_size=15, shuffle = False, verbose = 1)


I tried assigning class weights to balance the data out. Even manually deleting 0's in the data, but nothing seems to result in accurate predictions. Am I doing something wrong in the model, or is this simply data that cannot be utilized by machine learning?









share







New contributor




PavlovsCat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$

















    0












    $begingroup$


    I've been trying to create a binary classification model that predicts wether there will be a train delay based on the train and time. Here is a link to the data



    The issue I'm having is that my accuracy goes to 94.07 in the first 5 epochs. Meanwhile, my class prediction will always be 0 and never 1.



    From what I understand, this is "Accuracy Paradox". A symptom of Class Imbalance. To combat this, I implemented Kfold.



    kfold = StratifiedKFold(n_splits=10,shuffle=True)
    cvs_scores =

    for train,test in kfold.split(X,Y):

    history = model.fit(X[train],Y[train],epochs=50,batch_size=15, shuffle = False, verbose = 1)
    scores = model.evaluate(X[test],Y[test],verbose=0)

    print("%s: %.2f%%" % (model.metrics_names[1],scores[1]*100))
    cvs_scores.append(scores[1] * 100)

    print("%.2f%% (+/- %.2f%%)" % (numpy.mean(cvs_scores),numpy.std(cvs_scores)))


    No luck. Still had the same issue as before.



    Here is how I import my data:



    raw_data = pd.read_csv('MTA_DELAY_DATA_DUMP - Sheet1.csv')

    X = raw_data.iloc[1:-2,0:2].dropna().values
    Y = raw_data.iloc[1:-2,2:3].dropna().astype(int).values


    My Model:



    model = Sequential()
    model.add(Dense(32, kernel_initializer='uniform', activation='relu',input_dim =2))
    model.add(Dense(16, kernel_initializer='uniform', activation='relu'))
    model.add(Dense(8, kernel_initializer='uniform', activation='relu'))
    model.add(Dense(1, kernel_initializer='uniform', activation='sigmoid'))

    model.compile(loss='binary_crossentropy', optimizer=Adam(lr=0.001),metrics=['accuracy'])
    history = model.fit(X,Y,epochs=150,batch_size=15, shuffle = False, verbose = 1)


    I tried assigning class weights to balance the data out. Even manually deleting 0's in the data, but nothing seems to result in accurate predictions. Am I doing something wrong in the model, or is this simply data that cannot be utilized by machine learning?









    share







    New contributor




    PavlovsCat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$















      0












      0








      0





      $begingroup$


      I've been trying to create a binary classification model that predicts wether there will be a train delay based on the train and time. Here is a link to the data



      The issue I'm having is that my accuracy goes to 94.07 in the first 5 epochs. Meanwhile, my class prediction will always be 0 and never 1.



      From what I understand, this is "Accuracy Paradox". A symptom of Class Imbalance. To combat this, I implemented Kfold.



      kfold = StratifiedKFold(n_splits=10,shuffle=True)
      cvs_scores =

      for train,test in kfold.split(X,Y):

      history = model.fit(X[train],Y[train],epochs=50,batch_size=15, shuffle = False, verbose = 1)
      scores = model.evaluate(X[test],Y[test],verbose=0)

      print("%s: %.2f%%" % (model.metrics_names[1],scores[1]*100))
      cvs_scores.append(scores[1] * 100)

      print("%.2f%% (+/- %.2f%%)" % (numpy.mean(cvs_scores),numpy.std(cvs_scores)))


      No luck. Still had the same issue as before.



      Here is how I import my data:



      raw_data = pd.read_csv('MTA_DELAY_DATA_DUMP - Sheet1.csv')

      X = raw_data.iloc[1:-2,0:2].dropna().values
      Y = raw_data.iloc[1:-2,2:3].dropna().astype(int).values


      My Model:



      model = Sequential()
      model.add(Dense(32, kernel_initializer='uniform', activation='relu',input_dim =2))
      model.add(Dense(16, kernel_initializer='uniform', activation='relu'))
      model.add(Dense(8, kernel_initializer='uniform', activation='relu'))
      model.add(Dense(1, kernel_initializer='uniform', activation='sigmoid'))

      model.compile(loss='binary_crossentropy', optimizer=Adam(lr=0.001),metrics=['accuracy'])
      history = model.fit(X,Y,epochs=150,batch_size=15, shuffle = False, verbose = 1)


      I tried assigning class weights to balance the data out. Even manually deleting 0's in the data, but nothing seems to result in accurate predictions. Am I doing something wrong in the model, or is this simply data that cannot be utilized by machine learning?









      share







      New contributor




      PavlovsCat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      I've been trying to create a binary classification model that predicts wether there will be a train delay based on the train and time. Here is a link to the data



      The issue I'm having is that my accuracy goes to 94.07 in the first 5 epochs. Meanwhile, my class prediction will always be 0 and never 1.



      From what I understand, this is "Accuracy Paradox". A symptom of Class Imbalance. To combat this, I implemented Kfold.



      kfold = StratifiedKFold(n_splits=10,shuffle=True)
      cvs_scores =

      for train,test in kfold.split(X,Y):

      history = model.fit(X[train],Y[train],epochs=50,batch_size=15, shuffle = False, verbose = 1)
      scores = model.evaluate(X[test],Y[test],verbose=0)

      print("%s: %.2f%%" % (model.metrics_names[1],scores[1]*100))
      cvs_scores.append(scores[1] * 100)

      print("%.2f%% (+/- %.2f%%)" % (numpy.mean(cvs_scores),numpy.std(cvs_scores)))


      No luck. Still had the same issue as before.



      Here is how I import my data:



      raw_data = pd.read_csv('MTA_DELAY_DATA_DUMP - Sheet1.csv')

      X = raw_data.iloc[1:-2,0:2].dropna().values
      Y = raw_data.iloc[1:-2,2:3].dropna().astype(int).values


      My Model:



      model = Sequential()
      model.add(Dense(32, kernel_initializer='uniform', activation='relu',input_dim =2))
      model.add(Dense(16, kernel_initializer='uniform', activation='relu'))
      model.add(Dense(8, kernel_initializer='uniform', activation='relu'))
      model.add(Dense(1, kernel_initializer='uniform', activation='sigmoid'))

      model.compile(loss='binary_crossentropy', optimizer=Adam(lr=0.001),metrics=['accuracy'])
      history = model.fit(X,Y,epochs=150,batch_size=15, shuffle = False, verbose = 1)


      I tried assigning class weights to balance the data out. Even manually deleting 0's in the data, but nothing seems to result in accurate predictions. Am I doing something wrong in the model, or is this simply data that cannot be utilized by machine learning?







      machine-learning deep-learning keras dataset data-cleaning





      share







      New contributor




      PavlovsCat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      PavlovsCat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      PavlovsCat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 mins ago









      PavlovsCatPavlovsCat

      1




      1




      New contributor




      PavlovsCat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      PavlovsCat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      PavlovsCat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          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
          });


          }
          });






          PavlovsCat is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f49448%2fis-this-a-data-issue-or-a-model-issue-a-keras-binary-classification-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








          PavlovsCat is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          PavlovsCat is a new contributor. Be nice, and check out our Code of Conduct.













          PavlovsCat is a new contributor. Be nice, and check out our Code of Conduct.












          PavlovsCat is a new contributor. Be nice, and check out our Code of Conduct.
















          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%2f49448%2fis-this-a-data-issue-or-a-model-issue-a-keras-binary-classification-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

          Ponta tanko

          Tantalo (mitologio)

          Erzsébet Schaár