def save_model(self, config, label_performance_metrics, column_order, label_encoder, pipeline): self.is_valid_data_set_manager() label_encoder_object_file_ID = self.file_repository.put_file( MlModel.serialize_label_encoder(label_encoder)) pipeline_object_file_ID = self.file_repository.put_file( MlModel.serialize_pipeline(pipeline)) model_in_db = MlModel(None, config, label_performance_metrics, column_order, label_encoder_object_file_ID, pipeline_object_file_ID) model_id = self.ml_model_repository.add_ml_model(model_in_db) self.workspace_repository.add_ml_model_ref(self.workspace_id, model_id)
def get_ml_model_stub_4_2() -> MlModel: return MlModel( _id="607367362d98418cae5a1522", config=get_training_config_stub_4_2(), label_performance_metrics=get_label_performance_metrics_stub_4_2(), column_order=get_column_order_stub_4_2(), label_encoder_object_file_ID="60736744c795e80494dbc3e9", pipeline_object_file_ID="60736749a4c260179e9be00d")
def get_ml_model_stub_5_1() -> MlModel: return MlModel( _id="60736013b961d239c76711a3", config=get_training_config_stub_5_1(), label_performance_metrics=get_label_performance_metrics_stub_5_1(), column_order=get_column_order_stub_5_1(), label_encoder_object_file_ID="6073604f8741014a0cd09780", pipeline_object_file_ID="607360560b3beb16ac03de77")
def add_ml_model(self, ml_model: MlModel) -> ObjectId: id = ObjectId(random_object_id.generate()) ml_model._id = id self.models[id] = ml_model return id
def get_pipeline(self) -> Pipeline: ml_model = self.get_ml_model() return MlModel.deserialize_pipeline( self.file_repository.get_file(ml_model.pipeline_object_file_ID))
def get_label_encoder(self) -> LabelEncoder: ml_model = self.get_ml_model() return MlModel.deserialize_label_encoder( self.file_repository.get_file( ml_model.label_encoder_object_file_ID))
def add_ml_model(self, ml_model: MlModel) -> ObjectId: ml_model_dict = ml_model.dict_for_db_insertion() return self.collection.insert_one(ml_model_dict).inserted_id