# How to normalize skewed data before clustering?

My question deals with what is the right way to normalize my data. My data consists 6 features, all together representing a state in an environment for reinforcement learning. My goal is to cluster states with KMeans, so of course I need to normalize values first.

(X axis is feature value, Y axis is number of appearances. if you wonder where are features 3 and 5, they are kinda look like normal)

I wonder what is the right way to normalize each feature (or all of them together) to use kmeans.

I tried to apply f-score (all features toghther, not one by one) but I wonder if it is the right away. The minimum value I get is -4.6 (in feature 2, as you can see it has values around zero) with maximum of around ~1. Are there better suggestions what can I do?

• so of course I need to normalize values first Why? K-means itself requires no pre-processing. It may be good or even necessary, but then the question is why? Put forward the reason. Also, what are the f-scores? Dec 26, 2021 at 12:15

There are several ways you can follow:

1. Box-cox transform
2. Log transform
3. Square root transform

– Community Bot
Dec 24, 2021 at 7:54

The k-means algorithm is not guaranteed to converge to a global optimum and is very initialization dependent; furthermore, its objective of squared Euclidean distance results in it minimizing intra-cluster variance. This means for k-means, you generally want your covariance matrix to be spherical; i.e. the covariance matrix is proportional to the identity matrix.

This means techniques like z-score scaling or range normalization on each feature can be useful. To see why, try coming up with a 2D example of where k-means changes depending on the initialization -- it's a common exam question that I've gotten that lends more insight into the behavior of k-means.

Obviously, it's hard (impossible, even) to visualize things in 6 dimensions, but if you can't plot out your data to analyze it yourself, I'd recommend asking yourself -- why k-means as opposed to any other clustering algorithm?
{"ft_lang_label":"__label__en","ft_lang_prob":0.9420591,"math_prob":0.88165855,"size":1029,"snap":"2023-40-2023-50","text_gpt3_token_len":239,"char_repetition_ratio":0.12487805,"word_repetition_ratio":0.07608695,"special_character_ratio":0.22740525,"punctuation_ratio":0.106481485,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.965176,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-11T17:04:38Z\",\"WARC-Record-ID\":\"<urn:uuid:f22102ca-7fc6-4a85-850c-dedc4ee3bbf4>\",\"Content-Length\":\"174166\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2b9186fd-47c8-4c6e-b5a5-d8964a2d2168>\",\"WARC-Concurrent-To\":\"<urn:uuid:6451eac6-fbb4-4ba1-a504-aec5718e3ffd>\",\"WARC-IP-Address\":\"104.18.43.226\",\"WARC-Target-URI\":\"https://stats.stackexchange.com/questions/467371/how-to-normalize-skewed-data-before-clustering\",\"WARC-Payload-Digest\":\"sha1:YFNTFXMUJLFNS4K2LIQNY2AWDO54535X\",\"WARC-Block-Digest\":\"sha1:7KATYX4QQ4MGRP66BFMX4JLSWTBITFL7\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679515260.97_warc_CC-MAIN-20231211143258-20231211173258-00899.warc.gz\"}"}