python 機器學習之資料預先處理

來源:互聯網
上載者:User

標籤:特徵   資料預先處理   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 機器學習之資料預先處理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.