Skip to content

Instantly share code, notes, and snippets.

@lakshay-arora
Created January 28, 2020 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lakshay-arora/4d2c2226a5961544d2436ab4f062c1d1 to your computer and use it in GitHub Desktop.
Save lakshay-arora/4d2c2226a5961544d2436ab4f062c1d1 to your computer and use it in GitHub Desktop.
# training data with 7 most important features
train_x_if = train_x[['Item_MRP',
'Outlet_Type_Grocery Store',
'Item_Visibility',
'Outlet_Type_Supermarket Type3',
'Outlet_Identifier_OUT027',
'Outlet_Establishment_Year',
'Item_Weight']]
# test data with 7 most important features
test_x_if = test_x[['Item_MRP',
'Outlet_Type_Grocery Store',
'Item_Visibility',
'Outlet_Type_Supermarket Type3',
'Outlet_Identifier_OUT027',
'Outlet_Establishment_Year',
'Item_Weight']]
# create an object of the RandfomForestRegressor Model
model_RFR_with_if = RandomForestRegressor(max_depth=10,random_state=2)
# fit the model with the training data
model_RFR_with_if.fit(train_x_if, train_y)
# predict the target on the training and test data
predict_train_with_if = model_RFR_with_if.predict(train_x_if)
predict_test_with_if = model_RFR_with_if.predict(test_x_if)
# Root Mean Squared Error on the train and test data
print('RMSE on train data: ', mean_squared_error(train_y, predict_train_with_if)**(0.5))
print('RMSE on test data: ', mean_squared_error(test_y, predict_test_with_if)**(0.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment