Complete the code to import the KFold class from scikit-learn.
from sklearn.model_selection import [1]
The KFold class is used to split data into K folds for cross-validation.
Complete the code to create a KFold object with 5 splits and shuffling enabled.
kf = KFold(n_splits=[1], shuffle=True, random_state=42)
Setting n_splits=5 creates 5 folds for cross-validation.
Fix the error in the loop to correctly split data indices using KFold.
for train_index, [1] in kf.split(X):
The kf.split() method returns train and test indices for each fold.
Fill both blanks to create training and testing sets from data arrays X and y.
X_train, y_train = X[[1]], y[[1]] X_test, y_test = X[[2]], y[[2]]
Use train_index to select training data and test_index for testing data.
Fill all three blanks to compile accuracy scores for each fold using a TensorFlow model.
accuracies = [] for train_idx, test_idx in kf.split(X): X_train, y_train = X[[1]], y[[1]] X_test, y_test = X[[2]], y[[2]] model = tf.keras.Sequential([ tf.keras.layers.Dense(10, activation='relu', input_shape=(X.shape[1],)), tf.keras.layers.Dense(1, activation='sigmoid') ]) model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy']) model.fit(X_train, y_train, epochs=5, verbose=0) loss, acc = model.evaluate(X_test, y_test, verbose=0) accuracies.append(acc) print(f"Average accuracy: {sum(accuracies)/len(accuracies):.2f}")
Use train_idx for training data and test_idx for testing data. The accuracy is appended from the test evaluation.