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

熱線電話:13121318867

登錄
首頁精彩閱讀機器學習中的非均衡分類問題
機器學習中的非均衡分類問題
2018-04-09
收藏

機器學習中的非均衡分類問題

非均衡分類問題是指在分類器訓練時,正例數(shù)目和反例數(shù)目不相等(相差很大),或者錯分正反例導致的代價不同(可從代價矩陣觀測)時存在的問題。

而大多數(shù)情況下,不同類別的分類代價并不相等,而諸如信用卡欺詐等場景中,正反例的樣本數(shù)目相差巨大,這就需要一些新的分類器性能度量方法和技術,來處理上述非均衡問題。

1、分類器性能度量指標

分類器學習常用的錯誤率指標會掩蓋樣例如何被錯分的細節(jié),可以采用更好的性能度量指標1 ——正確率TP/(TP+FP)和召回率TP/(TP+FN)。

實際上,單獨滿足其中一個指標高性能較容易,但構造一個同時高正確率有高召回率的分類器很難。至于具體選擇正確率還是召回率,關鍵在于場景或者說研究問題,例如在購物刷單問題中,正確率遠比召回率更重要。

此外可以采用性能度量指標2 ——ROC曲線,即接收者操作特征曲線。

ROC曲線給出的是當閾值變化時,假陽率和真陽率之間的變化情況。因此,我們可以通過觀察ROC曲線來調節(jié)分類器的閾值,使得分類器的性能最好處于ROC曲線的左上角。由ROC曲線衍生的AUC(曲線下的面積)指標給出了分類器的平均性能值。

def plotROC(predStrengths, classLabels):  
        import matplotlib.pyplot as plt  
        cur = (1.0,1.0) # current plot node  
        ySum = 0.0 # for AUC  
        numPosClas = sum(numpy.array(classLabels)==1.0)  
        numNegClas = len(classLabels) - numPosClas  
        yStep = 1/float(numPosClas)  
        xStep = 1/float(numNegClas)  
        sortedIndicies = predStrengths.argsort()  
        fig = plt.figure()  
        fig.clf()  
        ax = plt.subplot(111)  
        for index in sortedIndicies.tolist()[0]:  
            if classLabels[index] == 1.0:  
                delX = 0; delY = yStep;  
            else:  
                delX = xStep; delY = 0;  
                ySum += cur[1]  
            ax.plot([cur[0],cur[0]-delX],[cur[1],cur[1]-delY], c='b')  
            cur = (cur[0]-delX,cur[1]-delY)  
        ax.plot([0,1],[0,1],'b--')  
        plt.xlabel('False positive rate'); plt.ylabel('True positive rate')  
        plt.title('ROC curve for AdaBoost horse colic detection system')  
        ax.axis([0,1,0,1])  
        plt.show()  
        print "the Area Under the Curve is: ",ySum*xStep

2、基于代價敏感的學習方法

一方面,重構訓練數(shù)據(jù)集。即不改變已有算法,而是根據(jù)樣本的不同錯分代價給訓練集中的每一個樣本賦一個權值,接著按權重對原始樣本集進行重構。

另一方面,引入代價敏感因子,設計出代價敏感的分類算法。通常可以將各分類器學習時的目標函數(shù)改造成最小化代價函數(shù),即對小樣本賦予較高的代價,大樣本賦予較小的代價,期望以此來平衡樣本之間的數(shù)目差異。

3、改造分類器的訓練數(shù)據(jù) —— 過抽樣或者欠抽樣

過抽樣,即保留樣本數(shù)目小的類別的所有樣本同時,再進行復制或者進行插值,擴大規(guī)模。注意對小樣本數(shù)目的類別的樣本們進行插值有可能造成過擬合。

欠抽樣,即欠抽樣或者剔除樣本數(shù)目大的類別中的部分樣本,縮小規(guī)模。進行剔除時,盡量選擇那些離決策邊界較遠的樣例。

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

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

數(shù)據(jù)分析師考試動態(tài)
數(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(), // 加隨機數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調用 initGeetest 進行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調,回調的第一個參數(shù)驗證碼對象,之后可以使用它調用相應的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗服務器是否宕機 new_captcha: data.new_captcha, // 用于宕機時表示是新驗證碼的宕機 product: "float", // 產品形式,包括: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); }