Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix xgboost example for hyperparameter tuning #476

Merged
merged 4 commits into from
Jan 15, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix pylint and log fmt
  • Loading branch information
richardsliu committed Jan 15, 2019
commit 385956442234e15e761bd72f3402012ad40b45d9
14 changes: 8 additions & 6 deletions xgboost_ames_housing/housing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

import argparse
import joblib
import logging
import joblib
import pandas as pd
from sklearn.metrics import mean_absolute_error
from sklearn.model_selection import train_test_split
Expand Down Expand Up @@ -55,20 +55,20 @@ def train_model(train_X,
early_stopping_rounds=40,
eval_set=[(test_X, test_y)])

logging.info("Best RMSE on eval: {:.2f} with {} rounds".format(
model.best_score,
model.best_iteration+1))
logging.info("Best RMSE on eval: %.2f with %d rounds",
model.best_score,
model.best_iteration+1)
return model

def eval_model(model, test_X, test_y):
"""Evaluate the model performance."""
predictions = model.predict(test_X)
logging.info("mean_absolute_error={:.2f}".format(mean_absolute_error(predictions, test_y)))
logging.info("mean_absolute_error=%.2f", mean_absolute_error(predictions, test_y))

def save_model(model, model_file):
"""Save XGBoost model for serving."""
joblib.dump(model, model_file)
logging.info("Model export success {}".format(model_file))
logging.info("Model export success: %s", model_file)

def main(args):
(train_X, train_y), (test_X, test_y) = read_input(args.train_input)
Expand Down Expand Up @@ -117,5 +117,7 @@ def main(args):
default=50
)

logging.basicConfig(format='%(message)s')
logging.getLogger().setLevel(logging.INFO)
main_args = parser.parse_args()
main(main_args)