新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python數(shù)據(jù)變換如何實現(xiàn)
1、數(shù)據(jù)規(guī)范化,即歸一化的方法

常見方法:最小-規(guī)范化、z-score規(guī)范化、小數(shù)定標(biāo)規(guī)范化
import pandas as pd df=pd.DataFrame(A.data[:,3:6]) df.columns=A.feature_names[3:6] #最小-規(guī)范化,支持矢量運算 (df-df.min())/(df.max()-df.min()) #使用sklearn中的preprocessing模塊 from sklearn import preprocessing preprocessing.minmax_scale(df) #z-score規(guī)范化:結(jié)果=(數(shù)值-均值)/標(biāo)準(zhǔn)差,處理后數(shù)據(jù)的均值為0,標(biāo)準(zhǔn)差為1 (df-df.mean())/df.std() #使用sklearn中的preprocessing模塊 from sklearn import preprocessing preprocessing.scale(df) #小數(shù)定標(biāo)規(guī)范化:常見落在[-1,1]區(qū)間,通過移動小數(shù)點的位數(shù)實現(xiàn),移動位數(shù)取決于屬性絕對值的值的位數(shù) #ceil向上取整 import numpy as np df/10**np.ceil(np.log10(df.abs().max()))
2、連續(xù)屬性離散化
常見方法:分箱法(等寬法、等頻法)、聚類
import pandas as pd #等寬法,5個箱子,標(biāo)簽為0-4 pd.cut(df.AGE,5,label=range(5)) #等頻法 pd.qcut(df.AGE,5,label=range(5))
以上就是python數(shù)據(jù)變換的實現(xiàn),希望對大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)Python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
名稱欄目:創(chuàng)新互聯(lián)Python教程:python數(shù)據(jù)變換如何實現(xiàn)
網(wǎng)站地址:http://www.5511xx.com/article/cceisjd.html


咨詢
建站咨詢
