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

熱線電話:13121318867

登錄
首頁(yè)精彩閱讀R語(yǔ)言使用boosting方法對(duì)數(shù)據(jù)分類與交叉驗(yàn)證
R語(yǔ)言使用boosting方法對(duì)數(shù)據(jù)分類與交叉驗(yàn)證
2018-01-19
收藏

R語(yǔ)言使用boosting方法對(duì)數(shù)據(jù)分類與交叉驗(yàn)證

數(shù)據(jù)分類說(shuō)明

與bagging方法類似,boosting算法也是先獲得簡(jiǎn)單的分類器,然后通過調(diào)整錯(cuò)分樣本的權(quán)重逐步改進(jìn)分類器,使得后續(xù)分類器能夠?qū)W習(xí)前一輪分類器,adabag實(shí)現(xiàn)了AdaBoost.M1和SAMME兩個(gè)算法,因此用戶能夠使用adabag包實(shí)施集成學(xué)習(xí)。

數(shù)據(jù)分類操作

導(dǎo)入包
library(rpart)
library(adabag)
調(diào)用adabag包的boosting函數(shù)分類器:
churn.boost = boosting(churn ~ .,data = trainset,mfinal = 10,coeflearn = "Freund",boos = FALSE,control = rpart.control(maxdepth = 3))
使用boosting訓(xùn)練模型對(duì)測(cè)試數(shù)據(jù)集進(jìn)行分類預(yù)測(cè):
churn.boost.pred = predict.boosting(churn.boost,newdata = testset)
基于預(yù)測(cè)結(jié)果生成分類表:
 churn.boost.pred$confusion
               Observed Class
Predicted Class yes  no
            no   41 858
            yes 100  19
根據(jù)分類結(jié)果計(jì)算平均誤差:
churn.boost.pred$error
[1] 0.0589391
數(shù)據(jù)分類原理
boosting算法的思想是通過對(duì)弱分類器(單一決策樹)的“逐步優(yōu)化”,使之成為強(qiáng)分類器。假定當(dāng)前在訓(xùn)練集中存在n個(gè)點(diǎn),對(duì)其權(quán)重分別賦值Wj(0<= j < n),在迭代的學(xué)習(xí)過程中(假定迭代次數(shù)為m),我們將根據(jù)每次迭代的分類結(jié)果,不斷調(diào)整這些點(diǎn)的權(quán)重,如果當(dāng)前這些點(diǎn)分類是正確的,則調(diào)低其權(quán)值,否則,增加樣例點(diǎn)的權(quán)值。這樣,當(dāng)整個(gè)迭代過程結(jié)束時(shí),算法將得到m個(gè)合適的模型,最終,通過對(duì)每棵決策樹加權(quán)平均得到最后的預(yù)測(cè)結(jié)果,權(quán)值b由每棵決策樹的分類質(zhì)量決定。

bagging和boosting都采用了集成學(xué)習(xí)的思想,即將多個(gè)弱分類器組成強(qiáng)分類器,兩者的不同在于,bagging是組合獨(dú)立的模型,而boosting則通過在迭代的過程學(xué)習(xí)的過程中盡可能用正確的分類模型來(lái)降低預(yù)測(cè)誤差。與bagging類似,用戶也需要指定用于分類的模型的公式與分類數(shù)據(jù)集,用戶還要自己指定諸如迭代次數(shù)(mfinal),權(quán)重更新系數(shù)(coeflearn)、觀測(cè)值權(quán)重(boos)以及rpart的控制方法(單一決策樹)等參數(shù),本例中迭代次數(shù)為設(shè)置為10,采用Freund(AdaBoost.M1算法實(shí)現(xiàn)的方法)作為系數(shù)(coeflearn),設(shè)置boos的值是“false”,最大深度為3。
交叉驗(yàn)證說(shuō)明
adabag包支持對(duì)boosting方法的交叉驗(yàn)證,該功能可以通過boosting.cv實(shí)現(xiàn)。
交叉驗(yàn)證操作
獲得boosting方法交叉驗(yàn)證后的最小估計(jì)錯(cuò)誤:
調(diào)用boosting.cv對(duì)訓(xùn)練數(shù)據(jù)集實(shí)施交叉驗(yàn)證:
churn.boost.cv = boosting.cv(churn ~ .,v = 10,data = trainset,mfinal = 5,control=rpart.control(cp = 0.01))
從boosting結(jié)果生成混淆矩陣
churn.boost.cv$confusion
               Observed Class
Predicted Class  yes   no
            no   103 1936
            yes  239   37

得到boosting的平均誤差:
churn.boost.cv$error
[1] 0.06047516

交叉驗(yàn)證原理

函數(shù)參數(shù)v值設(shè)置為10,mfinal的值設(shè)置為5,boosting算法會(huì)執(zhí)行一個(gè)5次迭代的10折交叉驗(yàn)證,另外可以設(shè)置參數(shù)進(jìn)行rpart的匹配控制。我們將復(fù)雜度參數(shù)設(shè)置為0.01。

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

若不方便掃碼,搜微信號(hào):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)的第一個(gè)參數(shù)驗(yàn)證碼對(duì)象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個(gè)配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺(tái)檢測(cè)極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時(shí)表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說(shuō)明請(qǐng)參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計(jì)時(shí)完成 $(".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 = '請(qǐng)輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請(qǐng)輸入正確的'+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); }