Build multiple Random forest regressor on X_train set and Y_train labels with max_depth parameter value changing from 3 to 5 and also setting n_estimators to one of 50, 100, 200 values.
Evaluate each model accuracy on testing data set.
Hint: Make use of for loop Print the max_depth and n_estimators values of the model with highest accuracy.
Note: Print the parameter values in the form of tuple (a, b). a refers to max_depth value and b refers to n_estimators
This is what I've tried so far:
boston= datasets.load_boston()
X_train, X_test, Y_train, Y_test = train_test_split(boston.data, boston.target, random_state=30)
for m in range(3,6) :
rf_reg = RandomForestRegressor(n_estimators =100, max_depth=m)
rf_reg = rf_reg.fit(X_train, Y_train)
print(rf_reg.score(X_test,Y_test))
This gives me the accuracy score for the 3 models but I am not able to fetch the highest accuracy's parameters individually. I can use rf_reg.get_params()
, but it gives me all the parameters. I only want max_depth
and n_estimators
of the highest score one's