def get_algorithm( self, name: str, prescience: PrescienceClient = None) -> AlgorithmConfiguration: return Option(self.json_dict.get(name))\ .map(lambda x: AlgorithmConfiguration(json_dict=x, category=self.category, prescience=prescience))\ .get_or_else(None)
def get_forecasting_discount(self): """ Getter of the forecasting discount :return: the forecasting discount """ return Option(self.kwargs())\ .map(lambda x: x.get('forecasting_discount'))\ .get_or_else(None)
def get_past_steps(self): """ Getter of the past_steps attribute :return: the past_steps attribute """ return Option(self.kwargs())\ .map(lambda x: x.get('past_steps'))\ .get_or_else(None)
def get_forecasting_horizon_steps(self): """ Getter of the forecasting horizon steps :return: the forecasting horizon steps """ return Option(self.kwargs())\ .map(lambda x: x.get('forecasting_horizon_steps'))\ .get_or_else(None)
def table_row(self, output: OutputFormat) -> dict: return { 'id': str(self.id), 'name': Option(self.get_name()).get_or_else('-'), 'type': Option(self.get_type()).get_or_else('-'), 'log': Option(self.get_log()).get_or_else('-'), 'lower': Option(self.get_lower()).get_or_else('-'), 'upper': Option(self.get_upper()).get_or_else('-'), 'default': Option(self.get_default()).get_or_else('-'), 'choices': Option(self.get_choices()).get_or_else('-'), 'value': Option(self.get_value()).get_or_else('-') }
def test_list_find_smthg(self): self.assertEqual(Option(1), List([1, 2, 3]).find(lambda x: x == 1))
def test_list_find_None(self): self.assertEqual(Option(None), List([1, 2, 3]).find(lambda x: x == 4))
def test_map_on_none_option(self): self.assertEqual(Option(None), Option(None).map(lambda x: x + ' dupond'))
def test_map_on_valued_option(self): self.assertEqual(Option('toto dupond'), Option('toto').map(lambda x: x + ' dupond'))
def test_is_empty_on_valued_option(self): self.assertEqual(False, Option('toto').is_empty())
def test_is_empty_on_none_option(self): self.assertEqual(True, Option(None).is_empty())
def test_get_or_else_on_valued_option(self): self.assertEqual('toto', Option('toto').get_or_else('other'))
def test_list_tail_option(self): self.assertEqual(Option(3), List([1, 2, 3]).tail_option())
def test_list_head_option(self): self.assertEqual(Option(1), List([1, 2, 3]).head_option())
def table_row(self, output: OutputFormat) -> dict: def round_3(x): if isinstance(x, str): return float('nan') else: return round(x, 3) cost_get_safe = lambda key: \ Option((self.costs() or {})\ .get(key, None))\ .map(func=round_3)\ .get_or_else(None) return { 'uuid': self.uuid(), 'status': self.status().to_colored(output), 'config_name': self.config().name(), 'past_steps': self.config().get_past_steps(), 'horizon': self.config().get_forecasting_horizon_steps(), 'discount': self.config().get_forecasting_discount(), # Classification 'accuracy_cost': cost_get_safe('accuracy'), 'cohen_kappa_cost': cost_get_safe('cohen_kappa'), # Binary 'f1_cost': cost_get_safe('f1'), 'roc_auc_cost': cost_get_safe('roc_auc'), 'average_precision_cost': cost_get_safe('average_precision'), 'precision_cost': cost_get_safe('precision'), 'recall_cost': cost_get_safe('recall'), 'log_loss_cost': cost_get_safe('log_loss'), # Regression 'mape_cost': cost_get_safe('mape'), 'r2_cost': cost_get_safe('r2'), 'mae_cost': cost_get_safe('mae'), 'mse_cost': cost_get_safe('mse'), # Multiclass 'f1_micro_cost': cost_get_safe('f1_micro'), 'f1_macro_cost': cost_get_safe('f1_macro'), 'roc_auc_micro_cost': cost_get_safe('roc_auc_micro'), 'roc_auc_macro_cost': cost_get_safe('roc_auc_macro'), 'average_precision_micro_cost': cost_get_safe('average_precision_micro'), 'average_precision_macro_cost': cost_get_safe('average_precision_macro'), }
def get_hyperparameters(self) -> list: hyperparameters_dict = self.json_dict.get('hyperparameters') return Option(hyperparameters_dict)\ .map(lambda x: [Hyperparameter(param_id=k, json_dict=v) for k, v in x.items()])\ .get_or_else(None)
def test_get_or_else_on_none_option(self): self.assertEqual('other', Option(None).get_or_else('other'))