Chapter 4: Evaluate Your Model with Cross-Validation with Keras Wrappers
Activity 5: Model Evaluation Using Cross-Validation for a Diabetes Diagnosis Classifier
Solution:
- Load the dataset and print its properties:
# Load the dataset
import numpy
data = numpy.loadtxt(“./data/pima-indians-diabetes.csv”, delimiter=”,”)
X = data[:,0:8]
y = data[:,8]
# Print the sizes of the dataset
print(“Number of Examples in the Dataset = “, X.shape[0])
print(“Number of Features for each example = “, X.shape[1])
print(“Possible Output Classes = “, numpy.unique(y))
- Here’s the expected output:
Figure 4.15: Properties of the pima-indians-diabets.csv dataset
- Define the function that returns the Keras model:
from keras.models import Sequential
from keras.layers import Dense
# Create the function that returns the keras model
def build_model():
model = Sequential()
model.add(Dense(16, input_dim=8, activation=’relu’))
...