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

熱線電話:13121318867

登錄
首頁精彩閱讀機器學(xué)習(xí)基礎(chǔ):無監(jiān)督異常檢測和半監(jiān)督異常檢測!
機器學(xué)習(xí)基礎(chǔ):無監(jiān)督異常檢測和半監(jiān)督異常檢測!
2020-06-12
收藏

異常值檢測一般要求新發(fā)現(xiàn)的數(shù)據(jù)是否與現(xiàn)有觀測數(shù)據(jù)具有相同的分布或者不同的分布,相同的分布可以稱之為內(nèi)點(inlier),具有不同分布的點可以稱之為離群值。離群點和新奇點檢測是不同的,有一個重要的區(qū)分必須掌握:

離群點檢測:訓(xùn)練數(shù)據(jù)包含離群點,這些離群點被定義為遠離其它內(nèi)點的觀察值。因此,離群點檢測估計器會嘗試擬合出訓(xùn)練數(shù)據(jù)中內(nèi)圍點聚集的區(qū)域, 而忽略異常值觀察。

新奇點檢測:訓(xùn)練數(shù)據(jù)沒有受到離群點污染,我們感興趣的是檢測一個新的觀測值是否為離群點。在這種情況下,離群點被認為是新奇點。

離群點檢測和新奇點檢測都用于異常檢測, 其中一項感興趣的是檢測異?;虍惓S^察。離群點檢測又被稱之為無監(jiān)督異常檢測,新奇點檢測又被稱之為半監(jiān)督異常檢測。 在離群點檢測的背景下, 離群點/異常點不能夠形成密集的簇,因為可用的估計器假設(shè)離群點/異常點位于低密度區(qū)域。相反的,在新奇點檢測的背景下, 新奇點/異常點只要位于訓(xùn)練數(shù)據(jù)的低密度區(qū)域,是可以形成稠密聚類簇的,在此背景下被認為是正常的。

scikit-learn有一套機器學(xué)習(xí)工具estimator.fit(X_train),可用于新奇點或離群值檢測。然后可以使用estimator.predict(X_test)方法將新觀察值分類為離群點或內(nèi)點 :內(nèi)圍點會被標記為1,而離群點標記為-1。

離群點檢測方法總結(jié)

下面的例子展示了二維數(shù)據(jù)集上不同異常檢測算法的特點。數(shù)據(jù)集包含一種或兩種模式(高密度區(qū)域),以說明算法處理多模式數(shù)據(jù)的能力。

對于每個數(shù)據(jù)集,產(chǎn)生15%的樣本作為隨機均勻噪聲。這個比例是給予OneClassSVM的nu參數(shù)和其他離群點檢測算法的污染參數(shù)的值。由于局部離群因子(LOF)用于離群值檢測時沒有對新數(shù)據(jù)應(yīng)用的預(yù)測方法,因此除了局部離群值因子(LOF)外,inliers和離群值之間的決策邊界以黑色顯示。

sklearn.svm。一個已知的eclasssvm對異常值很敏感,因此在異常值檢測方面表現(xiàn)不太好。該估計器最適合在訓(xùn)練集沒有異常值的情況下進行新穎性檢測。也就是說,在高維的離群點檢測,或者在不對嵌入數(shù)據(jù)的分布做任何假設(shè)的情況下,一個類支持向量機可能在這些情況下給出有用的結(jié)果,這取決于它的超參數(shù)的值。

sklearn.covariance。橢圓包絡(luò)假設(shè)數(shù)據(jù)是高斯分布,并學(xué)習(xí)一個橢圓。因此,當(dāng)數(shù)據(jù)不是單峰時,它就會退化。但是請注意,這個估計器對異常值是穩(wěn)健的。

sklearn.ensemble。IsolationForest sklearn.neighbors。LocalOutlierFactor對于多模態(tài)數(shù)據(jù)集似乎表現(xiàn)得相當(dāng)好。sklearn的優(yōu)勢。第三個數(shù)據(jù)集的局部離群因子超過其他估計顯示,其中兩種模式有不同的密度。這種優(yōu)勢是由LOF的局域性來解釋的,即它只比較一個樣本的異常分數(shù)與其相鄰樣本的異常分數(shù)。

最后,對于最后一個數(shù)據(jù)集,很難說一個樣本比另一個樣本更反常,因為它們是均勻分布在超立方體中。除了sklearn。svm。有一點過度擬合的支持向量機,所有的估計器都對這種情況給出了合適的解決方案。在這種情況下,明智的做法是更密切地觀察樣本的異常分數(shù),因為一個好的估計器應(yīng)該給所有樣本分配相似的分數(shù)。

雖然這些例子給出了一些關(guān)于算法的直覺,但這種直覺可能不適用于非常高維的數(shù)據(jù)。

最后,請注意,模型的參數(shù)在這里是精心挑選的,但在實踐中需要進行調(diào)整。在沒有標記數(shù)據(jù)的情況下,這個問題是完全無監(jiān)督的,因此模型的選擇是一個挑戰(zhàn)。

# Author: Alexandre Gramfort <alexandre.gramfort@inria.fr>
#         Albert Thomas <albert.thomas@telecom-paristech.fr>
# License: BSD 3 clause

import time

import numpy as np
import matplotlib
import matplotlib.pyplot as plt

from sklearn import svm
from sklearn.datasets import make_moons, make_blobs
from sklearn.covariance import EllipticEnvelope
from sklearn.ensemble import IsolationForest
from sklearn.neighbors import LocalOutlierFactor

print(__doc__)

matplotlib.rcParams['contour.negative_linestyle'] = 'solid'

# Example settings
n_samples = 300
outliers_fraction = 0.15
n_outliers = int(outliers_fraction * n_samples)
n_inliers = n_samples - n_outliers

# define outlier/anomaly detection methods to be compared
anomaly_algorithms = [
    ("Robust covariance", EllipticEnvelope(contamination=outliers_fraction)),
    ("One-Class SVM", svm.OneClassSVM(nu=outliers_fraction, kernel="rbf",
                                      gamma=0.1)),
    ("Isolation Forest", IsolationForest(contamination=outliers_fraction,
                                         random_state=42)),
    ("Local Outlier Factor", LocalOutlierFactor(
        n_neighbors=35, contamination=outliers_fraction))]

# Define datasets
blobs_params = dict(random_state=0, n_samples=n_inliers, n_features=2)
datasets = [
    make_blobs(centers=[[0, 0], [0, 0]], cluster_std=0.5,
               **blobs_params)[0],
    make_blobs(centers=[[2, 2], [-2, -2]], cluster_std=[0.5, 0.5],
               **blobs_params)[0],
    make_blobs(centers=[[2, 2], [-2, -2]], cluster_std=[1.5, .3],
               **blobs_params)[0],
    4. * (make_moons(n_samples=n_samples, noise=.05, random_state=0)[0] -
          np.array([0.5, 0.25])),
    14. * (np.random.RandomState(42).rand(n_samples, 2) - 0.5)]

# Compare given classifiers under given settings
xx, yy = np.meshgrid(np.linspace(-7, 7, 150),
                     np.linspace(-7, 7, 150))

plt.figure(figsize=(len(anomaly_algorithms) * 2 + 3, 12.5))
plt.subplots_adjust(left=.02, right=.98, bottom=.001, top=.96, wspace=.05,
                    hspace=.01)

plot_num = 1
rng = np.random.RandomState(42)

for i_dataset, X in enumerate(datasets):
    # Add outliers
    X = np.concatenate([X, rng.uniform(low=-6, high=6,
                       size=(n_outliers, 2))], axis=0)

    for name, algorithm in anomaly_algorithms:
        t0 = time.time()
        algorithm.fit(X)
        t1 = time.time()
        plt.subplot(len(datasets), len(anomaly_algorithms), plot_num)
        if i_dataset == 0:
            plt.title(name, size=18)

        # fit the data and tag outliers
        if name == "Local Outlier Factor":
            y_pred = algorithm.fit_predict(X)
        else:
            y_pred = algorithm.fit(X).predict(X)

        # plot the levels lines and the points
        if name != "Local Outlier Factor":  # LOF does not implement predict
            Z = algorithm.predict(np.c_[xx.ravel(), yy.ravel()])
            Z = Z.reshape(xx.shape)
            plt.contour(xx, yy, Z, levels=[0], linewidths=2, colors='black')

        colors = np.array(['#377eb8', '#ff7f00'])
        plt.scatter(X[:, 0], X[:, 1], s=10, color=colors[(y_pred + 1) // 2])

        plt.xlim(-7, 7)
        plt.ylim(-7, 7)
        plt.xticks(())
        plt.yticks(())
        plt.text(.99, .01, ('%.2fs' % (t1 - t0)).lstrip('0'),
                 transform=plt.gca().transAxes, size=15,
                 horizontalalignment='right')
        plot_num += 1

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(), // 加隨機數(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); }