Created
January 5, 2022 12:11
-
-
Save EvanGertis/e50e0d46e53d1d647bdbf3b3b493fa7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def segmentation_by_natural_partitioning(s): | |
# calculate 5th and 95th percentiles. | |
s_as_array = np.array(s) | |
fith_percentile = np.percentile(s_as_array, 5) | |
nienty_fith_percentile = np.percentile(s_as_array, 95) | |
print(f"range [{s['A2'].max()},{s['A2'].min()}]") | |
print() | |
print("*****************************") | |
print(f'fith_percentile {fith_percentile}') | |
print(f'nienty_fith_percentile {nienty_fith_percentile}') | |
print("*****************************") | |
# sort the data. | |
s['A2'] = s['A2'].sort_values() | |
n = s['A2'].count() | |
print("*****************************") | |
print(f'Total number of records {n}') | |
print("*****************************") | |
# keep the values from floor(n*0.05) to floor(n*0.95) | |
print("******************************") | |
print("Dataset attribute A2") | |
print(s['A2']) | |
print("******************************") | |
f1 = fith_percentile # np.math.floor(n*0.05) | |
f2 = nienty_fith_percentile # np.math.floor(n*0.95) | |
print("*****************************") | |
print(f'fith_percentile {f1}') | |
print(f'nienty_fith_percentile {f2}') | |
print("*****************************") | |
s = s[s['A2'] > f1] | |
s = s[s['A2'] < f2] | |
print(f"range after cleaning [{s['A2'].max()},{s['A2'].min()}]") | |
maximum = ceil(s['A2'].max()) | |
minimum = floor(s['A2'].min()) | |
print(f"[maximum,minimum] [{minimum},{maximum}]") | |
print(f"subtract {most_significant_while_floordiv(maximum)} - {most_significant_while_floordiv(minimum)}") | |
numberOfGaps = most_significant_while_floordiv(maximum) - most_significant_while_floordiv(minimum) | |
print(f"numberOfGaps {numberOfGaps}") | |
print(f"The number of values that cover the range are [{minimum},{maximum}]") | |
return s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment