Created
June 5, 2020 06:57
-
-
Save korkridake/f0b761b581fb3e5d4d2703ce72ae460b to your computer and use it in GitHub Desktop.
MLOps Ep.4 Productionizing Training Script (Train, Validate, and Save Models)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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