def test_is_numeric(): assert _is_numeric(0) assert _is_numeric(0.0) assert not _is_numeric(True) assert not _is_numeric(False) assert not _is_numeric("0") assert not _is_numeric(None)
def _get_autolog_metrics(fitted_model): result_metrics = {} failed_evaluating_metrics = set() for metric in _autolog_metric_allowlist: try: if hasattr(fitted_model, metric): metric_value = getattr(fitted_model, metric) if _is_numeric(metric_value): result_metrics[metric] = metric_value except Exception: failed_evaluating_metrics.add(metric) if len(failed_evaluating_metrics) > 0: _logger.warning( f"Failed to autolog metrics: {', '.join(sorted(failed_evaluating_metrics))}." ) return result_metrics
def results_to_dict(results): """ Turns a ResultsWrapper object into a python dict :param results: instance of a ResultsWrapper returned by a call to `fit` :return: a python dictionary with those metrics that are (a) a real number, or (b) an array of the same length of the number of coefficients """ has_features = False features = results.model.exog_names if features is not None: has_features = True nfeat = len(features) results_dict = {} for f in dir(results): try: field = getattr(results, f) # Get all fields except covariances and private ones if ( not callable(field) and not f.startswith("__") and not f.startswith("_") and not f.startswith("cov_") ): if ( has_features and isinstance(field, np.ndarray) and field.ndim == 1 and field.shape[0] == nfeat ): d = dict(zip(features, field)) renamed_keys_dict = prepend_to_keys(d, f) results_dict.update(renamed_keys_dict) elif _is_numeric(field): results_dict[f] = field except AttributeError: pass return results_dict