99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀用python-pandas作圖矩陣
用python-pandas作圖矩陣
2018-02-24
收藏

python-pandas作圖矩陣

我們在采用機(jī)器學(xué)習(xí)算法對數(shù)據(jù)進(jìn)行分析時,首先要對數(shù)據(jù)進(jìn)行了解,而了解數(shù)據(jù)最快速的方式就是可視化。但是作者可視化采用的方法對很多data都通用,且采用的是各種圖形的圖矩陣,如直方圖、散點(diǎn)圖矩陣等等。本文就根據(jù)作者的分析來介紹如何運(yùn)用pandas作各種矩陣圖。

(1)數(shù)據(jù)

數(shù)據(jù)為PimaIndians dataset,在作者的代碼中包含該數(shù)據(jù)來源網(wǎng)址,即皮馬印第安人糖尿病數(shù)據(jù)集,樣本個數(shù)有768個,包含變量有:

Preg:懷孕次數(shù)

Plas:口服葡萄糖耐量試驗(yàn)中血漿葡萄糖濃度為2小時

Pres:舒張壓(mm Hg)

Skin:三頭肌皮褶厚度(mm)

test :2小時血清胰島素(μU/ml)

mass:體重指數(shù)(kg /(身高(m))^ 2)

pedi:糖尿病血統(tǒng)功能

age:年齡(歲)

class:類變量(0或1),估計是性別。

(2)Histograms(直方圖矩陣)

url = "https://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.data" names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class'] #設(shè)置變量名 data = pandas.read_csv(url, names=names) #采用pandas讀取csv數(shù)據(jù) data.hist() plt.show()

但是,我們看到圖形并不協(xié)調(diào),存在變量與坐標(biāo)重疊的情況,我們可以調(diào)整hist()的參數(shù)來解決,包括對x軸、y軸標(biāo)簽大小的調(diào)節(jié)((xlabelsize,ylabelsize),整個圖形布局大小的調(diào)節(jié)figsize:

data.hist(xlabelsize=7,ylabelsize=7,figsize=(8,6)) # plt.show()

可以看到每一個變量的分布情況,其中mass、plas、pres呈現(xiàn)一定的正態(tài)分布,其他除了class之外,基本上左偏。

(3)Density Plots(密度圖矩陣)

data.plot(kind='density', subplots=True, layout=(3,3), sharex=False,fontsize=8,figsize=(8,6)) plt.show()

原始代碼輸出后仍然存在重疊的地方,在這里加入了對圖中坐標(biāo)文字fontsize,以及整體布局大小figsize。

(4)箱線圖矩陣(Box and Whisker Plots)

data.plot(kind='box', subplots=True, layout=(3,3), sharex=False, sharey=False, fontsize=8,figsize=(8,6)) plt.show()

與(3)類似,在這里注意可以共享x軸和y軸,用了sharex=False, sharey=False的命令。

(5)相關(guān)系數(shù)矩陣圖(Correlation Matrix Plot)

import numpy correlations = data.corr() #計算變量之間的相關(guān)系數(shù)矩陣 # plot correlation matrix fig = plt.figure() #調(diào)用figure創(chuàng)建一個繪圖對象 ax = fig.add_subplot(111) cax = ax.matshow(correlations, vmin=-1, vmax=1) #繪制熱力圖,從-1到1 fig.colorbar(cax) #將matshow生成熱力圖設(shè)置為顏色漸變條 ticks = numpy.arange(0,9,1) #生成0-9,步長為1 ax.set_xticks(ticks) #生成刻度 ax.set_yticks(ticks) ax.set_xticklabels(names) #生成x軸標(biāo)簽 ax.set_yticklabels(names) plt.show()

顏色越深表明二者相關(guān)性越強(qiáng)。

(6)散布圖矩陣(Scatterplot Matrix)

from pandas.tools.plotting import scatter_matrix scatter_matrix(data,figsize=(10,10)) plt.show()

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗(yàn)證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }