def log_model(self, key, body=None, tag='', model_dir=None, model_file=None, metrics=None, parameters=None, artifact_path=None, upload=True, labels=None, inputs=None, outputs=None, extra_data=None, db_key=None): """log a model artifact and optionally upload it""" model = ModelArtifact(key, body, model_file=model_file, metrics=metrics, parameters=parameters, inputs=inputs, outputs=outputs, extra_data=extra_data) item = self._artifacts_manager.log_artifact(self, model, local_path=model_dir, artifact_path=artifact_path, tag=tag, upload=upload, db_key=db_key, labels=labels) self._update_db() return item
def log_model( self, key, body=None, framework="", tag="", model_dir=None, model_file=None, algorithm=None, metrics=None, parameters=None, artifact_path=None, upload=True, labels=None, inputs: List[Feature] = None, outputs: List[Feature] = None, feature_vector: str = None, feature_weights: list = None, training_set=None, label_column: Union[str, list] = None, extra_data=None, db_key=None, **kwargs, ): """log a model artifact and optionally upload it to datastore example:: context.log_model("model", body=dumps(model), model_file="model.pkl", metrics=context.results, training_set=training_df, label_column='label', feature_vector=feature_vector_uri, labels={"app": "fraud"}) :param key: artifact key or artifact class () :param body: will use the body as the artifact content :param model_file: path to the local model file we upload (see also model_dir) :param model_dir: path to the local dir holding the model file and extra files :param artifact_path: target artifact path (when not using the default) to define a subpath under the default location use: `artifact_path=context.artifact_subpath('data')` :param framework: name of the ML framework :param algorithm: training algorithm name :param tag: version tag :param metrics: key/value dict of model metrics :param parameters: key/value dict of model parameters :param inputs: ordered list of model input features (name, type, ..) :param outputs: ordered list of model output/result elements (name, type, ..) :param upload: upload to datastore (default is True) :param labels: a set of key/value labels to tag the artifact with :param feature_vector: feature store feature vector uri (store://feature-vectors/<project>/<name>[:tag]) :param feature_weights: list of feature weights, one per input column :param training_set: training set dataframe, used to infer inputs & outputs :param label_column: which columns in the training set are the label (target) columns :param extra_data: key/value list of extra files/charts to link with this dataset value can be abs/relative path string | bytes | artifact object :param db_key: the key to use in the artifact DB table, by default its run name + '_' + key db_key=False will not register it in the artifacts table :returns: artifact object """ if training_set is not None and inputs: raise MLRunInvalidArgumentError( "cannot specify inputs and training set together") model = ModelArtifact( key, body, model_file=model_file, metrics=metrics, parameters=parameters, inputs=inputs, outputs=outputs, framework=framework, algorithm=algorithm, feature_vector=feature_vector, feature_weights=feature_weights, extra_data=extra_data, **kwargs, ) if training_set is not None: model.infer_from_df(training_set, label_column) item = self._artifacts_manager.log_artifact( self, model, local_path=model_dir, artifact_path=extend_artifact_path(artifact_path, self.artifact_path), tag=tag, upload=upload, db_key=db_key, labels=labels, ) self._update_db() return item
def log_model( self, key, body=None, framework="", tag="", model_dir=None, model_file=None, metrics=None, parameters=None, artifact_path=None, upload=True, labels=None, inputs=None, outputs=None, extra_data=None, db_key=None, ): """log a model artifact and optionally upload it to datastore :param key: artifact key or artifact class () :param body: will use the body as the artifact content :param model_file: path to the local model file we upload (seel also model_dir) :param model_dir: path to the local dir holding the model file and extra files :param artifact_path: target artifact path (when not using the default) to define a subpath under the default location use: artifact_path=context.artifact_subpath('data') :param framework: name of the ML framework :param tag: version tag :param metrics: key/value dict of model metrics :param parameters: key/value dict of model parameters :param inputs: ordered list of model input features (name, type, ..) :param outputs: ordered list of model output/result elements (name, type, ..) :param upload: upload to datastore (default is True) :param labels: a set of key/value labels to tag the artifact with :param extra_data: key/value list of extra files/charts to link with this dataset value can be abs/relative path string | bytes | artifact object :param db_key: the key to use in the artifact DB table, by default its run name + '_' + key db_key=False will not register it in the artifacts table :returns: artifact object """ model = ModelArtifact( key, body, model_file=model_file, metrics=metrics, parameters=parameters, inputs=inputs, outputs=outputs, framework=framework, extra_data=extra_data, ) item = self._artifacts_manager.log_artifact( self, model, local_path=model_dir, artifact_path=artifact_path or self.artifact_path, tag=tag, upload=upload, db_key=db_key, labels=labels, ) self._update_db() return item