• python异常值处理sklearn的调用


    Sklearn异常检测模型一览

     Robust covariance:

      https://scikit-learn.org/stable/modules/generated/sklearn.covariance.EllipticEnvelope.html#sklearn.covariance.EllipticEnvelope

    
    

    # Robust convariance
    import numpy as np
    from sklearn.covariance import EllipticEnvelope
    true_cov = np.array([[.8, .3],
    [.3, .4]])
    X = np.random.RandomState(0).multivariate_normal(mean=[0, 0],
    cov=true_cov,
    size=500)
    cov = EllipticEnvelope(random_state=0).fit(X)
    # predict returns 1 for an inlier and -1 for an outlier
    cov.predict([[0, 0],
    [3, 3]])

    One-Class SVM:

      https://scikit-learn.org/stable/modules/generated/sklearn.svm.OneClassSVM.html#sklearn.svm.OneClassSVM

    # SVM有监督
    from sklearn.svm import OneClassSVM
    X = [[0], [0.44], [100], [0.46], [1]]
    clf = OneClassSVM(gamma='auto').fit(X)
    clf.predict(X)
    
    # clf.score_samples(X)

    Isolation Forest:

      https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.IsolationForest.html#sklearn.ensemble.IsolationForest 

    # IsolationForest
    from sklearn.ensemble import IsolationForest
    # X = [[-1.1], [0.3], [0.5], [100]]
    X=[[3910], [70], [3910], [3920], [3890]]
    clf = IsolationForest(random_state=0).fit(X)
    clf.predict(X)
    # clf.fit([[0.1], [1400], [90],[1210]])

    Local Outlier Factor:

      https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.LocalOutlierFactor.html#sklearn.neighbors.LocalOutlierFactor

    # Local Outlier Factor
    import numpy as np
    from sklearn.neighbors import LocalOutlierFactor
    X = [[-1.1], [0.2], [101.1], [0.3]]
    clf = LocalOutlierFactor(n_neighbors=2)
    clf.fit_predict(X)
    
    clf.negative_outlier_factor_

    参考:https://blog.csdn.net/hustqb/article/details/75216241

    sklearn原文:https://scikit-learn.org/stable/auto_examples/miscellaneous/plot_anomaly_comparison.html

  • 相关阅读:
    查看 并发请求数及其TCP连接状态【转】
    nohup使用(转)
    Linux下高cpu解决方案(转载)
    Java.lang.String 乱码反编译
    apache2.2 搭载本地中转服务器
    转:对于服务器AdminServer, 与计算机Machine-0相关联的节点管理器无法访问
    感兴趣的github项目
    .NET CORE学习
    使用hMailServer搭建邮件服务器
    记录Sqlserver2012附加Sqlserver2008的数据库出错的解决方案
  • 原文地址:https://www.cnblogs.com/StarZhai/p/15416421.html
Copyright © 2020-2023  润新知