question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question : acc: 81.97% but predict result always 0

See original GitHub issue

Please make sure that the boxes below are checked before you submit your issue. If your issue is an implementation question, please ask your question on StackOverflow or join the Keras Slack channel and ask there instead of filing a GitHub issue.

Thank you!

  • Check that you are up-to-date with the master branch of Keras. You can update with: pip install git+git://github.com/keras-team/keras.git --upgrade --no-deps

  • If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found here.

  • If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with: pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps

  • Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).

Hi, I can’t figure out what’s wrong, I just modified script from pima indian database.csv with my data and predict result always 0 (but accuracy and training is 81.97%)

data is attached (rename it to data.csv first)

data.txt

Thanks and I’m sorry if I made stupid mistake (very newbie about this ML) 😃

from keras.models import Sequential
from keras.layers import Dense
import numpy
# fix random seed for reproducibility
numpy.random.seed(7)

dataset = numpy.loadtxt("data.csv", delimiter=",")
# split into input (X) and output (Y) variables
X = dataset[:,0:7]
Y = dataset[:,7]


# create model
model = Sequential()
model.add(Dense(12, input_dim=7, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))

# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

# Fit the model
print('Training')
model.fit(X, Y, epochs=20, batch_size=16,verbose=0)

# evaluate the model
scores = model.evaluate(X, Y)
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))

#predictions = model.predict(XTEST)
predictions = model.predict(X)
# round predictions
rounded = [round(x[0]) for x in predictions]
print(rounded)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
tRosenflanzcommented, May 28, 2018

.fit method has class_weight argument which can help you rebalance the losses of data without changing the data class_weight={0:1,1:5} should work

0reactions
x4080commented, May 28, 2018

Thanks @tRosenflanz and @JamesTrick

I will close this because I finally found out the problem 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is the probability predicted by my keras model always zero
This model provides accuracy of 81.43%. The problem arises when I try to make a prediction based on this model. Here I've passed...
Read more >
Logistic regression is predicting all 1, and no 0 - Cross Validated
No, it doesn't make a sense that his model predicts always 1s, because 7% is a rather high rate of default and logit...
Read more >
A dynamic neural network model for predicting risk of Zika ... - bioRxiv
Results. 35. The model is applied to the recent Zika epidemic in the Americas at a weekly. 36 temporal resolution and country spatial...
Read more >
Two Methodologies: How Well Can Universities Predict Retention
proven to yield significant results in a variety of research fields. As these new statistical methodologies emerge, it is always worthwhile to compare...
Read more >
Current Techniques for Diabetes Prediction: Review and ... - MDPI
Many Machine Learning (ML) techniques have been utilized in predicting diabetes in the last couple of years. The increasing complexity of this problem...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found