Last active
September 28, 2021 09:19
-
-
Save PennyQ/16acc7d6630d3ebb4a72a450b8a9cc05 to your computer and use it in GitHub Desktop.
This file contains 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 pandas as pd | |
import argparse | |
# Parse the run id from the passed argument, the run id is get from each MLflow experiment run (within the URL) | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--run_id', dest='run_id') | |
args = parser.parse_args() | |
# generate predict results for each model | |
for i, model_key in enumerate(model_keys): | |
model_key = model_key.strip() | |
model_name = f"model_{model_key}" | |
model_uri = f"runs:/{args.run_id}/{model_name}" | |
model = mlflow.sklearn.load_model(model_uri) | |
#(load and preprocess data...) | |
features = model.features | |
X_score = df[features] | |
preds = pd.Series(model.predict_proba(X_score)[:, 1]) | |
preds.name = 'model_score' | |
df_pred = pd.concat([df[['model_key']], preds], axis=1) | |
df_pred_all = df_pred_all.append(df_pred) | |
# select the best model and result from df_pred_all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment