標籤:特徵 資料預先處理 encode put process 等於 maxscale 方法 label
#資料預先處理方法,主要是處理資料的量綱和同趨勢化問題。
import numpy as np
from sklearn import preprocessing
#零均值規範
data=np.random.rand(3,4)#隨機產生3行4列的資料
data_standardized=preprocessing.scale(data)#對資料進行歸一化處理,即每個數值減去均值除以方差 主要用於svm
#線性資料變換最大最小化處理
data_scaler=preprocessing.MinMaxScaler(feature_range=(0,1))#選定區間(0,1),未經處理資料-最小值/(最大值-最小值)
data_scaled=data_scaler.fit(data)
#資料標準化處理normalized
data_normalized=preprocessing.normalize(data,norm=‘l1‘)#減少人為增加特徵,經過處理後資料賈總等於1
#特徵二值化,
data_binarized=prepressing.Binarizer(threshold=0.5).transform(data)#以0.5為閾值,大於0.5為1,小於0.5為0
#label_encode對標籤進行數值化
label_encode=preprocessing.LabelEncoder()
input_class=[‘audi‘,‘ford‘,‘audi‘,‘bmw‘,‘toyota‘,‘benz‘]
label_encode.fit(input_class)
for i ,item in enmerate(label_encode.class_):
print(item,‘-->‘,i)
#onehotencode
python 機器學習之資料預先處理