Created
July 28, 2022 14:26
-
-
Save kylegallatin/3539824e1a160d5a41cdde75fd5beae3 to your computer and use it in GitHub Desktop.
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 csv | |
| import joblib | |
| import sklearn.pipeline | |
| from datetime import datetime | |
| ## helper function to save a model/pipeline | |
| def save_pipeline(pipeline: sklearn.pipeline.Pipeline, ts: datetime = None) -> str: | |
| model_path = f"data/pipeline-{ts}.pkl".replace(" ","-") | |
| joblib.dump(pipeline, model_path) | |
| return model_path | |
| ## helper function to write a new line to the csv | |
| def record_model(pipeline: sklearn.pipeline.Pipeline, score: float, parameters: dict) -> None: | |
| model = str(pipeline) | |
| ts = datetime.now() | |
| model_path = save_pipeline(pipeline, ts) | |
| f = open('metadata_store.csv', 'a') | |
| csv_writer = csv.writer(f) | |
| csv_writer.writerow([ts, model, parameters, score, model_path]) | |
| f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment