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

熱線電話:13121318867

登錄
首頁精彩閱讀異常檢測原理與實驗
異常檢測原理與實驗
2018-08-19
收藏

異常檢測原理與實驗

最近需要對欺詐報價進行識別處理,簡單的模型就是給定很多不同數(shù)據(jù)集,需要找出每個spu下可能存在的欺詐數(shù)據(jù),比如{20,22,30},其中的欺詐數(shù)據(jù)可能就是30。其實加以抽象,屬于異常檢測范圍。

異常檢測是發(fā)現(xiàn)與大部分對象不同的對象,其中這些不同的對象稱為離群點。一般異常檢測的方法主要有數(shù)理統(tǒng)計法、數(shù)據(jù)挖掘方法。一般在預(yù)處理階段發(fā)生的異常檢測,更多的是依托數(shù)理統(tǒng)計的思想完成的。
一、基于模型
  首先判斷出數(shù)據(jù)的分布模型,比如某種分布(高斯分布、泊松分布等等)。然后根據(jù)原始數(shù)據(jù)(包括正常點與離群點),算出分布的參數(shù),從而可以代入分布方程求出概率。例如高斯分布,根據(jù)原始數(shù)據(jù)求出期望u和方差?,然后擬合出高斯分布函數(shù),從而求出原始數(shù)據(jù)出現(xiàn)的概率;根據(jù)數(shù)理統(tǒng)計的思想,概率小的可以當(dāng)做離群點。


優(yōu)點:

方法簡單,無需訓(xùn)練,可以用在小數(shù)據(jù)集上。

缺點:

發(fā)現(xiàn)離群點效果差,離群點對模型參數(shù)影響大,造成區(qū)分效果差。需要數(shù)值化

import java.util.List;
 
/**
 * 實現(xiàn)描述:計算正態(tài)分布
 *
 * @author jin.xu
 * @version v1.0.0
 * @see
 * @since 16-9-9 下午12:02
 */
public class Gauss {
    public double getMean(List<Double> dataList) {
        double sum = 0;
        for (double data : dataList) {
            sum += data;
        }
        double mean = sum;
        if (dataList.size() > 0) {
            mean = sum / dataList.size();
        }
        return mean;
    }
 
    public double getStd(List<Double> dataList, double mean) {
        double sum = 0;
        for (double data : dataList) {
            sum += (data - mean) * (data - mean);
        }
        double std = sum;
        if (dataList.size() > 0) {
            std = sum / dataList.size();
        }
        return Math.sqrt(std);
    }
 
    public double getProbability(double data, double meam, double std) {
        double tmp = (1.0 / (Math.sqrt(2 * 3.141592653) * std)) * Math.exp(-(Math.pow(data - meam, 2) / (2 * Math.pow(std, 2))));
        return tmp;
    }
}


二、基于近鄰度
 需要度量對象之間的距離,離群點一般是距離大部分數(shù)據(jù)比較遠的點。一般這種方法是計算每個點與其距離最近的k個點的距離和,然后累加起來,這就是K近鄰方法。

 

優(yōu)點:

原理簡單,無需訓(xùn)練,可用在任何數(shù)據(jù)集

缺點:

需要計算距離,計算量大,K的選定以及多于K個離群點聚集在一起導(dǎo)致誤判。


public class KNN {
    
    public static double process(int index,Position position, int k, List<Position> positionList) {
        List<Double> distances = Lists.newArrayList();
        for (int i = 0; i < positionList.size(); ++i) {
            if (i != index) {
                distances.add(Math.sqrt(Math.pow((positionList.get(i).getX() - position.getX()), 2)+Math.pow((positionList.get(i).getY()-position.getY()),2)));
            }
        }
        Collections.sort(distances);
        k = k < distances.size() ? k : distances.size();
 
        double knnDistance = 0.0;
        for (int i = 0; i < k; ++i) {
            knnDistance += distances.get(i);
        }
        return knnDistance;
    }
 
    private static class Position{
        int x;
        int y;
 
        public int getX() {
            return x;
        }
 
        public void setX(int x) {
            this.x = x;
        }
 
        public int getY() {
            return y;
        }
 
        public void setY(int y) {
            this.y = y;
        }
    }
 
}

三、基于密度
 低密度區(qū)域的數(shù)據(jù)點可以當(dāng)做某種程度上的離群點?;诿芏鹊暮突诮彽氖敲芮邢嚓P(guān)的,簡單來說,密度和近鄰的距離成反比。一般的度量公式如下:

density(x,k)表示包含x的k近鄰的密度,distance(x,y)表示x到y(tǒng)的距離,N(x,k)表示x的k近鄰集合。


優(yōu)點:

相對準確

缺點:

需要度量密度,需要設(shè)定閾值


四、基于聚類
  丟棄遠離其他聚類簇的小聚類簇。需要給出小聚類簇的大小閾值、聚類簇距離閾值。常用的聚類方法比較多,比如K-means(變種K-models)、EM、層次聚類算法(分裂型和歸約型)。具體方法說明可見:漫話數(shù)據(jù)挖掘。

優(yōu)點:

引入數(shù)據(jù)挖掘聚類的方法,在樣本充足的情況下準確度會相對較高

缺點:

需要訓(xùn)練,計算量大,原理相對復(fù)雜

需要建立適當(dāng)?shù)哪P?,需要充足的?xùn)練樣本

總之異常檢測的通用方法大致有4種:基于模型、k近鄰、基于密度和基于聚類的。實際使用數(shù)據(jù)是線上的報價,由于每個SPU下報價有限,聚類不適合,所以用基于模型的和k近鄰的做了試驗;基于密度的和K近鄰差不多,而且需要密度范圍的距離閾值,就沒有選擇。此外,涉及的實驗數(shù)據(jù)是公司的,代碼是興趣使然,所以就不公布具體實驗數(shù)據(jù)。



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