Check out our new VS Code extension for experiment tracking and model development
Saves given object to a given path
def save(
obj: Any,
path: str,
project: Optional[str] = None,
sample_data=None,
fs: Union[str, AbstractFileSystem] = None,
index: bool = None,
external: Optional[bool] = None,
description: str = None,
params: Dict[str, str] = None,
labels: List[str] = None,
update: bool = False,
) -> MlemObject
from mlem.api import save
save(obj, path, index=False, external=True)
Saves a given object to a given path. The path can belong to different file
systems (eg: S3
). The function returns and saves the object as a
MLEM Object.
obj
(required) - Object to dumppath
(required) - If not located on LocalFileSystem, then should be uri
or fs
argument should be providedproject
(optional) - path to mlem projectsample_data
(optional) - If the object is a model or function, you can
provide input data sample, so MLEM will include it's schema in the model's
metafilefs
(optional) - FileSystem for the path
argumentindex
(optional) - Whether to add object to mlem project indexexternal
(optional) - Save result directly to path
(not inside .mlem/
)description
(optional) - description for objectparams
(optional) - arbitrary params for objectlabels
(optional) - labels for objectupdate
(optional) - whether to keep old description/labels/params if new
values were not providedMlemObjectNotFound
- Thrown if we can't find MLEM objectimport os
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
from pandas import DataFrame
from mlem.api import save
train, target = load_iris(return_X_y=True)
train = DataFrame(train)
train.columns = train.columns.astype(str)
model = DecisionTreeClassifier().fit(train, target)
path = os.path.join(os.getcwd(), "saved-model")
save(model, path, sample_data=train, index=False)