After initializing MLEM we have an empty project (except for the config file), but soon we'll save something with MLEM to fill it up.
To save models with MLEM you just need to use
mlem.api.save() method instead
of some other way you saved your model before. Let's take a look at the
following python script:
# train.py from sklearn.datasets import load_iris from sklearn.ensemble import RandomForestClassifier from mlem.api import save def main(): data, y = load_iris(return_X_y=True, as_frame=True) rf = RandomForestClassifier( n_jobs=2, random_state=42, ) rf.fit(data, y) save( rf, "rf", sample_data=data, description="Random Forest Classifier", ) if __name__ == "__main__": main()
Here we load well-known iris dataset with sklearn and train a simple classifier. But instead of pickling the model we saved it with MLEM.
Now let's run this script and see how we save the model.
$ python train.py ... $ tree .mlem/model/ .mlem/model ├── rf └── rf.mlem
By default, MLEM saves your files to
.mlem/ directory, but that can be
changed. See Project Structure for more
The model was saved along with some metadata about it:
rf containing the model
binary and a
rf.mlem metafile containing information about it. Let's take a
look at it:
It's a bit long, but we can see all that we need to use the model later:
pandaswith particular versions we need to run this model.
Note that we didn't specify requirements: MLEM investigates the object you're saving (even if it's a complex one) and finds out all requirements needed!