All our Data Science projects include bite-sized activities to test your knowledge and practice in an environment with constant feedback.
All our activities include solutions with explanations on how they work and why we chose them.
Compute the accuracy score, confusion matrix, precision and recall using the testing dataset.
Then select the correct answers
For this task, use the following dataset:
# Generate a random dataset for classification X, y = make_classification(n_samples=1000, n_features=10, random_state=42) # Split the dataset into training and testing sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
Your task is to train a Random Forest classifier using different max_depth values and select the correct answers. Here are the instructions:
1. Create a list of max_depth values: max_depths = [2, 4, 6, 8, 10,100]. 2. Loop through the list of max_depth values and train a RandomForestClassifier for each value. Use also , random_state=42 and n_estimators=100. 3. Use the trained classifier to make predictions on the test set. 4. Compute the accuracy score for each classifier using the accuracy_score function from scikit-learn. 5. Select the correct answer(s) based on the accuracy score(s), precision and recall.