Question: X _ train, X _ test, y _ train, y _ test = train _ test _ split , test _ size = 0 .

X_train, X_test, y_train, y_test = train_test_split , test_size =0.2, random_state =42
# Define the column transformer for preprocessing
numeric_features =['YrSold', 'SaleType']
categorical_features =['GarageCars',' PoolArea']
preprocessor = ColumnTransformer(
transformers
('num', MinMaxScaler(), numeric_features),
('cat', OneHotEncoder(), categorical_features)
# Create Random Forest pipeline
rf_pipeline = Pipeline(steps=[('preprocessor', preprocessor),
('regressor', RandomForestRegressor())])
# Create K-Nearest Neighbors pipeline
knn_pipeline = Pipeline(steps=[('preprocessor', preprocessor),
('regressor', KNeighborsRegressor())])
# Define hyperparameters grid for GridSearchcv
rf_param_grid
'regressor_n_estimators ': [50,100],
'regressor_max_depth': [2,3,4],
}
'regressor_criterion': ['mse', 'mae']
knn_param_grid
'regressor_n_neighbors': [2,5,10,20,50,100],
}
'regressor_weights': ['uniform', 'distance']
# Perform GridSearchCV with 5-fold cross validation for Random Forest
rf_grid_search = GridSearchCV(rfR
Calculate the following evaluation metrics of the 2 models' performance on the training data set:
Root mean squared error MSE
Mean absolute error MAE
Mean absolute percentage error MAPE
Write a paragraph describing the results and which model and set of hyper parameters worked the best and based on which accuracy metric(s)? If you were to explore more hyper parameters for each model, how would you expand or limit the current hyperparameter grid.
as
[19] df = pd.read_csv('train.csv')
[20] df.columns
Index ('Id', 'MSSubClass', 'MSZoning', 'LotFrontage', 'LotArea', 'Street',
'Alley', 'LotShape', 'LandContour', 'Utilities', 'LotConfig',
'LandSlope', 'Neighborhood', 'Condition1', 'Condition2', 'BldgType',
'HouseStyle', 'Overallqual', 'Overalicond', 'YearBuilt', 'YearRemodAdd',
'RoofStyle', 'RoofMatl', 'Exterior1st', 'Exterior2nd', 'MasVnrType',
'MasVnrArea', 'ExterQual': 'ExterCond', 'Foundation', 'BsmtQual',
'BsmtCond', 'BsmtExposure', 'BsmtFinType1', 'BsmtFinSF1',_pipeline, rf_paran_grid, cv=5)
 X_train, X_test, y_train, y_test = train_test_split , test_size =0.2, random_state =42

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!