Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Second East European Symposium Adbis 98 Poznan Poland September 1998 Proceedings Lncs 1475

Authors: Witold Litwin ,Tadeusz Morzy ,Gottfried Vossen

1st Edition

3540649247, 978-3540649243

More Books

Students also viewed these Databases questions

Question

What is flow?

Answered: 1 week ago

Question

If ( A^2 - A + I = 0 ), then inverse of matrix ( A ) is?

Answered: 1 week ago

Question

What is computer neworking ?

Answered: 1 week ago