4.3 Practical Exercises for Chapter 4
These exercises will help you practice feature selection and model tuning using Recursive Feature Elimination (RFE) and feature importance. Each exercise includes a solution with code for guidance.
Exercise 1: Identify Important Features with Random Forests
Use a Random Forest Classifier to identify the most important features in a dataset. Focus on understanding the feature importance scores and select the top features based on these scores.
Load the dataset and split it into training and testing sets.
Train a Random Forest Classifier and display the feature importance scores.
Select the top 5 features based on their importance and re-evaluate the model.
from sklearn.ensemble import RandomForestClassifier