Recreate Model

it's desirable for prediction models
to increase their accuracy continuously.

Add a "model-recreate" command to
recreate model with new datasets.

implements blueprint recreate-model
Change-Id: Ib69bcf9df0de38b5d31c338d09cf13b9b6a8e144
This commit is contained in:
Hiroyuki Eguchi 2017-02-09 15:46:41 +09:00
parent 6ca3903487
commit 0a6e3912c1
5 changed files with 96 additions and 6 deletions

View File

@ -84,6 +84,48 @@ class ModelMixin(object):
return {'model': {'id': id}}
def _recreate(self, req, id, body):
"""Recreate model with new Dataset"""
context = req.environ['meteos.context']
if not self.is_valid_body(body, 'os-recreate'):
raise exc.HTTPUnprocessableEntity()
b_model = body['os-recreate']
LOG.debug("Recreate model with request: %s", b_model)
try:
model = self.engine_api.get_model(context, id)
experiment = self.engine_api.get_experiment(
context, model.experiment_id)
template = self.engine_api.get_template(
context, experiment.template_id)
except exception.NotFound:
raise exc.HTTPNotFound()
source_dataset_url = b_model.get('source_dataset_url')
dataset_format = b_model.get('dataset_format', 'csv')
swift_tenant = b_model.get('swift_tenant')
swift_username = b_model.get('swift_username')
swift_password = b_model.get('swift_password')
self.engine_api.recreate_model(id,
context,
source_dataset_url,
dataset_format,
model.model_type,
model.model_params,
template.id,
template.job_template_id,
experiment.id,
experiment.cluster_id,
swift_tenant,
swift_username,
swift_password)
return {'model': {'id': id}}
class ModelController(wsgi.Controller, ModelMixin, wsgi.AdminActionsMixin):
@ -211,6 +253,11 @@ class ModelController(wsgi.Controller, ModelMixin, wsgi.AdminActionsMixin):
"""Unload model."""
return self._unload(req, id, body)
@wsgi.action('os-recreate')
def recreate(self, req, id, body):
"""Recreate model."""
return self._recreate(req, id, body)
def create_resource():
return wsgi.Resource(ModelController())

View File

@ -15,6 +15,7 @@
STATUS_NEW = 'new'
STATUS_CREATING = 'creating'
STATUS_RECREATING = 'recreating'
STATUS_DEACTIVATING = 'deactivating'
STATUS_DELETING = 'deleting'
STATUS_DELETED = 'deleted'

View File

@ -398,7 +398,44 @@ class API(base.Base):
return model
def delete_model(self, context, id, force=False):
def recreate_model(self, id, context, source_dataset_url, dataset_format,
model_type, model_params, template_id,
job_template_id, experiment_id, cluster_id,
swift_tenant, swift_username, swift_password):
"""Recreate a Model"""
policy.check_policy(context, 'model', 'recreate')
model = {'source_dataset_url': source_dataset_url,
'dataset_format': dataset_format,
'model_type': model_type,
'model_params': model_params,
'experiment_id': experiment_id,
'cluster_id': cluster_id,
'status': constants.STATUS_RECREATING
}
try:
self.delete_model(context, id, recreate=True)
self.db.model_update(context, id, model)
model['id'] = id
model['job_template_id'] = job_template_id
model['template_id'] = template_id
model['swift_tenant'] = swift_tenant
model['swift_username'] = swift_username
model['swift_password'] = swift_password
self.engine_rpcapi.create_model(context, model)
LOG.info(_LI("Accepted recreation of model %s."), id)
except Exception:
with excutils.save_and_reraise_exception():
self.db.model_delete(context, id)
# Retrieve the learning with instance details
model = self.db.model_get(context, id)
return model
def delete_model(self, context, id, force=False, recreate=False):
"""Delete model."""
policy.check_policy(context, 'model', 'delete')
@ -415,7 +452,8 @@ class API(base.Base):
self.engine_rpcapi.delete_model(context,
model['cluster_id'],
model['job_id'],
id)
id,
recreate)
def load_model(self, context, id, dataset_format, model_type,
job_template_id, experiment_id, cluster_id):

View File

@ -279,7 +279,8 @@ class LearningManager(manager.Manager):
self._update_status(context, 'Model', request_spec['id'],
job_id, stdout, stderr)
def delete_model(self, context, cluster_id=None, job_id=None, id=None):
def delete_model(self, context, cluster_id=None, job_id=None, id=None,
recreate=False):
"""Deletes a Model."""
context = context.elevated()
@ -295,7 +296,9 @@ class LearningManager(manager.Manager):
)
LOG.info(_LI("Model %s deleted successfully."), id)
self.db.model_delete(context, id)
if not recreate:
self.db.model_delete(context, id)
def load_model(self, context, request_spec=None):
"""Load a Model."""

View File

@ -100,11 +100,12 @@ class LearningAPI(object):
return self.cast(context, self.make_msg('create_model',
request_spec=request_spec_p))
def delete_model(self, context, cluster_id, job_id, id):
def delete_model(self, context, cluster_id, job_id, id, recreate):
return self.call(context, self.make_msg('delete_model',
cluster_id=cluster_id,
job_id=job_id,
id=id))
id=id,
recreate=recreate))
def load_model(self, context, request_spec):
request_spec_p = jsonutils.to_primitive(request_spec)