From 513b9d38e560b7e8904604c61985337cbef5c33a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Merc=C3=A8=20Mart=C3=ADn=20Prats?= Date: Wed, 10 Jun 2020 18:13:32 +0200 Subject: [PATCH] Fixing corner case in local anomaly detectors trained with one row --- HISTORY.rst | 6 ++++++ bigml/anomaly.py | 8 +++++--- bigml/version.py | 2 +- docs/index.rst | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 8cc466e6..8d29930a 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,12 @@ History ------- +4.32.1 (2020-06-10) +~~~~~~~~~~~~~~~~~~~ + +- Fixing local anomaly scores prediction for corner cases of samples with + one row. + 4.32.0 (2020-05-19) ~~~~~~~~~~~~~~~~~~~ diff --git a/bigml/anomaly.py b/bigml/anomaly.py index a581b4be..5d233efc 100644 --- a/bigml/anomaly.py +++ b/bigml/anomaly.py @@ -96,8 +96,8 @@ def __init__(self, anomaly, api=None): "Score will" " not be available") else: - default_depth = ( - 2 * (DEPTH_FACTOR + \ + default_depth = self.mean_depth if \ + self.sample_size == 1 else (2 * (DEPTH_FACTOR + \ math.log(self.sample_size - 1) - \ (float(self.sample_size - 1) / self.sample_size))) self.expected_mean_depth = min(self.mean_depth, @@ -128,7 +128,9 @@ def anomaly_score(self, input_data): value between 0 and 1. """ - + # corner case with only one record + if self.sample_size == 1: + return 1 # Checks and cleans input_data leaving the fields used in the model input_data = self.filter_input_data(input_data) diff --git a/bigml/version.py b/bigml/version.py index 3ce709a9..52e71aee 100644 --- a/bigml/version.py +++ b/bigml/version.py @@ -1 +1 @@ -__version__ = '4.32.0' +__version__ = '4.32.1' diff --git a/docs/index.rst b/docs/index.rst index 3c23331a..39f522e4 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,6 +1,7 @@ .. toctree:: :hidden: + index ml_resources creating_resources 101_model