301 - Evaluating keras model using KFold cross validation
Code generated in the video can be downloaded from here:
https://github.com/bnsreenu/python_for_microscopists
Direct link: https://github.com/bnsreenu/python_for_microscopists/tree/master/301-Evaluating%20keras%20model%20using%20KFold%20cross%20validation
We will start with the normal way most of us approach the problem of binary classification using neural networks (deep learning). In this example, we will split our data set the normal way into train and test groups.
Then, we will learn to divide data using K Fold splits.
We will iterate through each split to train and evaluate our model.
Normally, we would use cross_val_score in sklearn to automatically evaluate
the model over all splits and report the cross validation score. But, that method is designed to handle traditional sklearn models such as SVM, RF,
gradient boosting etc. - NOT deep learning models from TensorFlow or pytorch.
Therefore, in order to use cross_val_score, we will find a way to make our
keras model available to the function. This is done using the KerasClassifier
from tensorflow.keras.wrappers.scikit_learn
Note that the cross_val_score() function takes the dataset and cross-validation configuration and returns a list of scores calculated for each fold.
Wisconsin breast cancer example
Dataset link: https://www.kaggle.com/datasets/uciml/breast-cancer-wisconsin-data