LoslegenKostenlos loslegen

Preparing for RandomizedSearch

Last semester your professor challenged your class to build a predictive model to predict final exam test scores. You tried running a few different models by randomly selecting hyperparameters. However, running each model required you to code it individually.

After learning about RandomizedSearchCV(), you're revisiting your professors challenge to build the best model. In this exercise, you will prepare the three necessary inputs for completing a random search.

Diese Übung ist Teil des Kurses

Model Validation in Python

Kurs anzeigen

Anleitung zur Übung

  • Finalize the parameter dictionary by adding a list for the max_depth parameter with options 2, 4, 6, and 8.
  • Create a random forest regression model with ten trees and a random_state of 1111.
  • Create a mean squared error scorer to use.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import make_scorer, mean_squared_error

# Finish the dictionary by adding the max_depth parameter
param_dist = {"____": [____],
              "max_features": [2, 4, 6, 8, 10],
              "min_samples_split": [2, 4, 8, 16]}

# Create a random forest regression model
rfr = ____(____=10, ____=1111)

# Create a scorer to use (use the mean squared error)
scorer = ____(____)
Code bearbeiten und ausführen