Skip to content

Instantly share code, notes, and snippets.

@korkridake
Created June 5, 2020 06:57
Show Gist options
  • Save korkridake/f0b761b581fb3e5d4d2703ce72ae460b to your computer and use it in GitHub Desktop.
Save korkridake/f0b761b581fb3e5d4d2703ce72ae460b to your computer and use it in GitHub Desktop.
MLOps Ep.4 Productionizing Training Script (Train, Validate, and Save Models)
# Get hold of the current run
run = Run.get_context()
# Experiment parameters
args = {
"n_estimators": 120
}
reg_model = RandomForestRegressor(**args)
reg_model.fit(data["train"]["X"], data["train"]["y"])
# Validate Model on Validation Set
preds = reg_model.predict(data["test"]["X"])
mse = mean_squared_error(preds, y_test)
metrics = {"mse": mse}
print(metrics)
# Save Model
model_name = "sklearn_regression_model.pkl"
joblib.dump(value = reg_model, filename=model_name)
# Register a model
model = Model.register(model_path='sklearn_regression_model.pkl', model_name='sklearn_regression_model', workspace=ws)
print(model.name, model.id, model.version, sep='\t')
run.log('mean squared error', mse)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment