Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql query to apply min-max normalization to different columns in sql server 2008?

I have different columns containing int values like age, gender etc. I want these column values to be replaced with 0-1 range values by applying min-max normalization so that i can load it to rapid minor and apply k-means.

plz tell me the sql query of this?

like image 732
user1015347 Avatar asked Dec 06 '25 13:12

user1015347


1 Answers

The query to calculate this is as follows

SELECT
    1.00*(Age-MinAge)/AgeRange,
    1.00*(Gender-MinGender)/GenderRange,
FROM
    (
    SELECT
       Age,
       MIN(Age) OVER () AS MinAge,
       MAX(Age) OVER () - MIN(Age) OVER () AS AgeRange,
       Gender,
       MIN(Gender) OVER () AS MinGender,
       MAX(Gender) OVER () - MIN(Gender) OVER () AS GenderRange,
    FROM
       MyTable
    ) X

You can use this to populate a new table or new columns etc

like image 54
gbn Avatar answered Dec 10 '25 21:12

gbn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!