Skip to content

Instantly share code, notes, and snippets.

@kylegallatin
Created July 28, 2022 14:26
Show Gist options
  • Select an option

  • Save kylegallatin/3539824e1a160d5a41cdde75fd5beae3 to your computer and use it in GitHub Desktop.

Select an option

Save kylegallatin/3539824e1a160d5a41cdde75fd5beae3 to your computer and use it in GitHub Desktop.
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