how does prediction with keras work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how does prediction with keras work?

so, I've been racking my head over the following code. please help me. # first neural network with keras tutorial from numpy import loadtxt from keras.models import Sequential from keras.layers import Dense # load the dataset dataset = loadtxt('pima-indians-diabetes.csv', delimiter=',') # split into input (X) and output (y) variables X = dataset[:,0:8] y = dataset[:,8] # define the keras model model = Sequential() model.add(Dense(12, input_dim=8, activation='relu')) model.add(Dense(8, activation='relu')) model.add(Dense(1, activation='sigmoid')) # compile the keras model model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) # fit the keras model on the dataset model.fit(X, y, epochs=150, batch_size=10) # evaluate the keras model accuracy = model.evaluate(X, y) print('Accuracy: %.2f' % (accuracy*100)) any help would be greatly appreciated. thank you!

5th Aug 2020, 10:41 AM
sujay simha
sujay simha - avatar
2 Answers
+ 1
U want to learn keras posted in Sololearn ? ) So. Firstly, u import modules, as usual. Than u load dataset in csv format. Than u split dataset X and y. Make an instance of model. model.add - u have 3 layers in your model with activation function relu and sigmoid ( strange thing to use different functions at the same tume). Than u compile model, using binary_ crossentropy, that say u will have on exit only 2 variants of answer. Than u fit model on your splitted dataset. U use 150 epoch, not much but enough. And finally, u evaluate a model and find out the accuracy of a model.
14th Aug 2020, 6:25 AM
zoldaten
zoldaten - avatar
+ 1
@zoldaten, thanks, but can you tell me more about model.add?
15th Aug 2020, 9:30 AM
sujay simha
sujay simha - avatar