Skip to content

Instantly share code, notes, and snippets.

@archena
Created November 11, 2019 11:47
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 archena/62ed4dcac28cb5e3780ea1198b5ee8fc to your computer and use it in GitHub Desktop.
Save archena/62ed4dcac28cb5e3780ea1198b5ee8fc to your computer and use it in GitHub Desktop.
def fit(train_X, train_y):
rf_model = RandomForestRegressor(random_state=1, n_estimators=10)
rf_model.fit(train_X, train_y)
return rf_model
def validate(model, val_X, val_y):
rf_val_predictions = model.predict(val_X)
return mean_absolute_error(rf_val_predictions, val_y)
rf_model = fit(train_X, train_y)
rf_val_mae = validate(rf_model, val_X, val_y)
print("Validation MAE for Random Forest Model: {:,.0f}".format(rf_val_mae))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment