zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    centos7 安装配置openstack-dashboard (官网openstack-juno版)
    OpenCV图像处理篇之图像平滑
    在matlab中生成m序列
    【转】oracle创建表空间
    Android代码中动态设置图片的大小(自动缩放),位置
    Eclipse安装SVN插件
    visualSVN server库迁移
    Win7 64bit 安装VisualSVN出现报错:Servic 'VisualSVN Server' failed to start.解决办法
    具体图解 Flume介绍、安装配置
    hadoop(八)
  • 原文地址:https://www.cnblogs.com/StarZhai/p/15416421.html
Copyright © 2011-2022 走看看