是對原始資料的線性變換,使結果對映到[0,1]區間。方便資料的處理。消除單位影響及變異大小因素影響。
基本公式為:
x"=(x-min)/(max-min)
程式碼:
#!/user/bin/env python
#-*- coding:utf-8 -*-#author:M10import numpy as npimport pandas as pdimport matplotlib.pylab as pltimport mysql.connectorconn = mysql.connector.connect(host="localhost", user="root", passwd="123456", db="python")#連結本地資料庫sql = "select price,comment from taob"#sql語句data = pd.read_sql(sql,conn)#獲取資料#離差標準化data1 = (data-data.min())/(data.max()-data.min())print(data1)
是對原始資料的線性變換,使結果對映到[0,1]區間。方便資料的處理。消除單位影響及變異大小因素影響。
基本公式為:
x"=(x-min)/(max-min)
程式碼:
#!/user/bin/env python
#-*- coding:utf-8 -*-#author:M10import numpy as npimport pandas as pdimport matplotlib.pylab as pltimport mysql.connectorconn = mysql.connector.connect(host="localhost", user="root", passwd="123456", db="python")#連結本地資料庫sql = "select price,comment from taob"#sql語句data = pd.read_sql(sql,conn)#獲取資料#離差標準化data1 = (data-data.min())/(data.max()-data.min())print(data1)