How Normalize Data Mining Min Max From Mysql In Python
This is example of my data in mysql, I use lib flashext.mysql and python 3 RT NK NB SU SK P TNI IK IB TARGET 84876 902 1192 2098 3623 169 39 133
Solution 1:
Here is a SQL query that should get you started (assuming you want to calculate it per column):
create table normalize as
select
(RT - min(RT)over()) / (max(RT)over() - min(RT)over()) * 0.8 + 0.1 as RT_norm
from test;
I tested this query in sqlite3, not MySQL. It isn't necessarily optimal, but intuitively follows the formula. Notice, the over
turns the min / max aggregate functions into window functions, which means they look at whole column, but the result is repeated on each row.
Todo
You would still need to:
- send the MySQl query via Python
- repeat the same code for each column
- give each column a name
- assign the resulting table to a schema (most likely)
- handle divide by 0 in case a column max and min are equal
Post a Comment for "How Normalize Data Mining Min Max From Mysql In Python"