Created
May 4, 2023 12:58
-
-
Save kidpixo/6ec6c6c575e19b09da3d2207efa38b24 to your computer and use it in GitHub Desktop.
colors: relabelling the classes using the first centroids values
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
##### | |
# colors: relabelling the classes using the first centroids values | |
# calculate all the class centers in data space | |
y = X.groupby(labels).mean().values | |
# position of the data feature used to sort lables | |
feature_index = find_nearest(700) | |
# here the sorting index | |
centroids_sorting_index = np.argsort(y[:, feature_index]) | |
# here the sorting labels, not the index!! | |
centroids_sorted_labels = np.argsort(centroids_sorting_index) | |
# # use pd.Series.map(dict) di directly change values in place | |
labels = pd.Series(labels).map(dict(zip(np.arange(n_clusters),centroids_sorted_labels))).values | |
print('index for label sort :',feature_index) | |
# print(' features y[:,index] :',y[:, feature_index]) | |
# print(centroids_sorting_index) | |
# print(centroids_sorted_labels) | |
print(f'ind:y_feat > new_index') | |
for i,yf,ni in zip(range(len(y[:, feature_index])),y[:, feature_index],centroids_sorted_labels): | |
print(f'{i:3}:{yf:.5f} > {ni:>4}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment