Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log Pickle files as a part of Mlflow run

I am running an MLflow experiment as a part of it I would like to log a few artifacts as a python pickle.

Ex: Trying out different categorical encoders, so wanted to log the encoder objects as a pickle file.

Is there a way to achieve this?

like image 365
Nagaraju Budigam Avatar asked Nov 09 '25 01:11

Nagaraju Budigam


1 Answers

There are two functions for there:

  1. log_artifact - to log a local file or directory as an artifact
  2. log_artifacts - to log a contents of a local directory

so it would be as simple as:

with mlflow.start_run():
    mlflow.log_artifact("encoder.pickle")

And you will need to use the custom MLflow model to use that pickled file, something like this:

import mlflow.pyfunc

class my_model(mlflow.pyfunc.PythonModel):
    def __init__(self, encoders):
        self.encoders = encoders

    def predict(self, context, model_input):
        _X = ...# do encoding using self.encoders.
        return str(self.ctx.predict([_X])[0])
like image 81
Alex Ott Avatar answered Nov 10 '25 14:11

Alex Ott



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!