def create_prediction(self, model, input_data=None, args=None, wait_time=3, retries=10, by_name=True): """Creates a new prediction. The model parameter can be: - a simple tree model - a simple logistic regression model - an ensemble The by_name argument is now deprecated. It will be removed. """ logistic_regression_id = None ensemble_id = None model_id = None resource_type = get_resource_type(model) if resource_type == ENSEMBLE_PATH: ensemble_id = get_ensemble_id(model) if ensemble_id is not None: check_resource(ensemble_id, query_string=TINY_RESOURCE, wait_time=wait_time, retries=retries, raise_on_error=True, api=self) elif resource_type == MODEL_PATH: model_id = get_model_id(model) check_resource(model_id, query_string=TINY_RESOURCE, wait_time=wait_time, retries=retries, raise_on_error=True, api=self) elif resource_type == LOGISTIC_REGRESSION_PATH: logistic_regression_id = get_logistic_regression_id(model) check_resource(logistic_regression_id, query_string=TINY_RESOURCE, wait_time=wait_time, retries=retries, raise_on_error=True, api=self) else: raise Exception("A model or ensemble id is needed to create a" " prediction. %s found." % resource_type) if input_data is None: input_data = {} create_args = {} if args is not None: create_args.update(args) create_args.update({ "input_data": input_data}) if model_id is not None: create_args.update({ "model": model_id}) elif ensemble_id is not None: create_args.update({ "ensemble": ensemble_id}) elif logistic_regression_id is not None: create_args.update({ "logisticregression": logistic_regression_id}) body = json.dumps(create_args) return self._create(self.prediction_url, body, verify=self.verify_prediction)
def delete_ensemble(self, ensemble): """Deletes a ensemble. """ check_resource_type(ensemble, ENSEMBLE_PATH, message="An ensemble id is needed.") ensemble_id = get_ensemble_id(ensemble) if ensemble_id: return self._delete("%s%s" % (self.url, ensemble_id))
def update_ensemble(self, ensemble, changes): """Updates a ensemble. """ check_resource_type(ensemble, ENSEMBLE_PATH, message="An ensemble id is needed.") ensemble_id = get_ensemble_id(ensemble) if ensemble_id: body = json.dumps(changes) return self._update("%s%s" % (self.url, ensemble_id), body)
def get_ensemble(self, ensemble, query_string=''): """Retrieves an ensemble. The ensemble parameter should be a string containing the ensemble id or the dict returned by create_ensemble. As an ensemble is an evolving object that is processed until it reaches the FINISHED or FAULTY state, the function will return a dict that encloses the ensemble values and state info available at the time it is called. """ check_resource_type(ensemble, ENSEMBLE_PATH, message="An ensemble id is needed.") ensemble_id = get_ensemble_id(ensemble) if ensemble_id: return self._get("%s%s" % (self.url, ensemble_id), query_string=query_string)