Question : acc: 81.97% but predict result always 0
See original GitHub issuePlease 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)
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:
- Created 5 years ago
- Comments:5
.fit
method has class_weight argument which can help you rebalance the losses of data without changing the dataclass_weight={0:1,1:5}
should workThanks @tRosenflanz and @JamesTrick
I will close this because I finally found out the problem 😃