コード例 #1
0
 def _run_step(self, model, train_data, validate_data, feature_mask,
               n_model, model_mask):
     if self.direction == 'forward' and self.n_step == 0:
         if self.role == consts.GUEST:
             loss, ic_val = self.get_ic_val_guest(model, train_data)
             LOGGER.info("step {} n_model {}: ic_val {}".format(
                 self.n_step, n_model, ic_val))
             model_info = ModelInfo(self.n_step, n_model, ic_val, loss,
                                    self.step_direction)
             self.models_trained[model_mask] = model_info
             model_key = model_info.get_key()
             self._put_model(model_key, model)
         else:
             model_info = ModelInfo(self.n_step, n_model, None, None,
                                    self.step_direction)
             self.models_trained[model_mask] = model_info
             model_key = model_info.get_key()
             self._put_model(model_key, model)
         return
     curr_step = Step()
     curr_step.set_step_info((self.n_step, n_model))
     trained_model = curr_step.run(model, train_data, validate_data,
                                   feature_mask)
     loss, ic_val = self.get_ic_val(trained_model, model_mask)
     LOGGER.info("step {} n_model {}: ic_val {}".format(
         self.n_step, n_model, ic_val))
     model_info = ModelInfo(self.n_step, n_model, ic_val, loss,
                            self.step_direction)
     self.models_trained[model_mask] = model_info
     model_key = model_info.get_key()
     self._put_model(model_key, trained_model)
コード例 #2
0
 def predict(data_instances, model):
     if data_instances is None:
         return
     d_header = data_instances.schema.get("header")
     best_feature = [d_header.index(x) for x in model.header]
     best_mask = np.zeros(len(d_header), dtype=bool)
     np.put(best_mask, best_feature, 1)
     new_data = data_instances.mapValues(lambda v: Step.slice_data_instance(v, best_mask))
     pred_result = model.predict(new_data)
     return pred_result