mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
documented function
This commit is contained in:
parent
5a5c0d5f18
commit
deda5bc025
1 changed files with 19 additions and 7 deletions
|
|
@ -7,21 +7,33 @@ def classify_decile_newvalues(
|
||||||
decile_boundaries: List[float], decile_labels: List[str], new_values: List[float]
|
decile_boundaries: List[float], decile_labels: List[str], new_values: List[float]
|
||||||
) -> List[str]:
|
) -> List[str]:
|
||||||
"""
|
"""
|
||||||
This is a complementary function to UvalueEstimations.classify_decile_newvalues, which does not use pandas
|
Classify a list of new values into pre-established deciles.
|
||||||
so that we can use this function inside of our lamdbas, without having to import pandas.
|
|
||||||
:param decile_boundaries:
|
|
||||||
:param decile_labels:
|
|
||||||
:param new_values:
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
This function is an alternative to UvalueEstimations.classify_decile_newvalues that does not depend on pandas,
|
||||||
|
making it suitable for use in environments where pandas may not be available (such as AWS Lambda).
|
||||||
|
|
||||||
|
:param decile_boundaries: A list of decile boundaries. These define the ranges of the deciles.
|
||||||
|
:param decile_labels: A list of labels for the deciles. These are the classifications to be assigned to the values.
|
||||||
|
:param new_values: A list of new values to be classified into the deciles.
|
||||||
|
|
||||||
|
:return: A list of classifications for the new values. Each classification corresponds to the decile in which
|
||||||
|
the respective new value falls. If a value falls outside the range of the deciles, its classification is
|
||||||
|
None.
|
||||||
|
"""
|
||||||
classifications = []
|
classifications = []
|
||||||
|
|
||||||
|
# For each new value...
|
||||||
for value in new_values:
|
for value in new_values:
|
||||||
|
# If the value is outside the range of the deciles, classify it as None
|
||||||
if value < decile_boundaries[0] or value > decile_boundaries[-1]:
|
if value < decile_boundaries[0] or value > decile_boundaries[-1]:
|
||||||
classifications.append(None)
|
classifications.append(None)
|
||||||
else:
|
else:
|
||||||
|
# Use bisect_left to find the decile in which the value falls
|
||||||
i = bisect_left(decile_boundaries, value)
|
i = bisect_left(decile_boundaries, value)
|
||||||
|
# If the value falls exactly on a decile boundary, classify it in the lower decile
|
||||||
if i:
|
if i:
|
||||||
i -= 1
|
i -= 1
|
||||||
|
# Append the classification to the list of classifications
|
||||||
classifications.append(decile_labels[i])
|
classifications.append(decile_labels[i])
|
||||||
return classifications
|
return classifications
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue