mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +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]
|
||||
) -> List[str]:
|
||||
"""
|
||||
This is a complementary function to UvalueEstimations.classify_decile_newvalues, which does not use pandas
|
||||
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:
|
||||
"""
|
||||
Classify a list of new values into pre-established deciles.
|
||||
|
||||
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 = []
|
||||
|
||||
# For each new value...
|
||||
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]:
|
||||
classifications.append(None)
|
||||
else:
|
||||
# Use bisect_left to find the decile in which the value falls
|
||||
i = bisect_left(decile_boundaries, value)
|
||||
# If the value falls exactly on a decile boundary, classify it in the lower decile
|
||||
if i:
|
||||
i -= 1
|
||||
# Append the classification to the list of classifications
|
||||
classifications.append(decile_labels[i])
|
||||
return classifications
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue