Created
May 8, 2023 05:52
mlflow gcp experimentation
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
import os | |
os.environ['GOOGLE_APPLICATION_CREDENTIALS']='<<path_to_service_account_json' | |
# set tracking uri to mlflow server running on cloud | |
mlflow.set_tracking_uri('https://mlflowtracker-gcp-XXXXXX-uc.a.run.app') | |
mlflow.set_experiment('term_deposit') | |
with mlflow.start_run(): | |
params = { | |
"n_estimator": 120, | |
"learning_rate": 0.3 | |
} | |
#log experiment parameters | |
mlflow.log_param(key='model_params',value=params) | |
model = GradientBoostingClassifier(n_estimators=120, learning_rate=0.3, random_state=7) | |
model.fit(X_train, y_train) | |
# Get predictions | |
y_predict = model.predict(X_test) | |
metrics = { | |
'precision_score': precision_score(y_true=y_test, y_pred=y_predict), | |
'recall_score': recall_score(y_true=y_test, y_pred=y_predict), | |
'f1_score': f1_score(y_true=y_test, y_pred=y_predict), | |
'accuracy_score': accuracy_score(y_true=y_test, y_pred=y_predict) | |
} | |
#log model metrics | |
mlflow.log_metrics(metrics) | |
# Save model | |
mlflow.sklearn.log_model(model, 'term_deposit') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment