Model Evaluation Function In this section, I have created a function that takes the model and the model name, and the function will return - • Time to find best hyperparamters using training dataset including time to predict target values on validation set • Function will print best hyperparameters that generated the best AUC_ROC on training set • Function will print AUC_ROC on training dataset • Function will print AUC_ROC on validation dateset using hyperparamters found in tuning This function will allow me to avoid code duplication and it will train all of the models using the same search space so that we can equally compare all models. In the following sections I will plug in the names of the models to this function so that I can obtain timings and values. I will compare these values and timings after all models have been tuned so that I can select a model that I can use to predict test targets. # Create model evaluation function # For model tuning, we will use GridSearchCV and keep the search space constant across models def model_evaluation(model,model_name): # Create a search space to optimize for best combination of n_estimators and max_depth search_space = {'n_estimators': [5,10,25,50] , 'max_depth': [5,10,25,50]} # Initialize Model model = model # Create list of scoring/evaluation metrics scoring = ['accuracy','roc_auc'] # Create a GridSearchCV Object # Use 3-fold cross validation (5 is the default, but to save time on training, we will use 3-fold) # Select Best Model Using roc_auc as Scorer function model_grid = GridSearchCV(model, param_grid = search_space, cv = 5, scoring = 'roc_auc', refit = 'roc_auc', verbose = 0) # Fit model to training data model_grid.fit(features_train, target_train) # Save best parameters to variable that produce the smallest AUC_ROC # best_parameters will contain a dictionary of the best parameters that produced the lowest AUC_ROC best_parameters = model_grid.bestparams # Best score is the AUC_ROC value on the training data best_score = model_grid.bestscore # Best grid will contain the parameters that can be used to predict values on the validation set # The refitted estimator is made available at the bestestimator attribute and permits using predict directly on this GridSearchCV instance best_grid = model_grid.bestestimator # Predict target values on the validation set predicted_values = best_grid.predict(features_valid) # Calculate and Print AUC_ROC Score probabilities_valid = best_grid.predict_proba(features_valid) probabilities_one_valid = probabilities_valid[:, 1] auc_roc = roc_auc_score(target_valid, probabilities_one_valid) print('The AUC_ROC Score is',round(auc_roc,2)) # Calculate accuracy between predicted target and actual target for validation set accuracy = accuracy_score(target_valid, predicted_values) # Print results of tuning and AUC_ROC & Accuracy on validation set print("Best Parameters For", model_name,":", best_parameters ) print("These Parameters Produced a Best AUC_ROC Score of", round(best_score,2), "on the Training Data") print() print("The AUC_ROC Using the Tuned", model_name, "on the Validation Set:", round(auc_roc,3)) print("The Accuracy Using the Tuned", model_name, "on the Validation Set:",round(accuracy,3)) print() print('Hyperparameter Tuning, Training, & Prediction Time for', model_name,':') explain in detail in a simpler manner