Python Package for Outlier Detection PyOD Setup (Apr 2020)


PYOD SETUP 

Installation:
It is recommended to use pip for installation. Please make sure the latest version is installed, as PyOD is updated frequently:

pip install pyod            # normal install
pip install --upgrade pyod  # or update if needed
pip install --pre pyod      # or include pre-release version for new features

Alternatively, you could clone and run setup.py file:

git clone https://github.com/yzhao062/pyod.git
cd pyod
pip install .

Ref: https://pyod.readthedocs.io/en/latest/install.html

LISTING ALL THE MODELS 

(tf) C:\Users\ashish>python
Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32

Code snippets not working:
>>> import pyod
>>> dir(pyod.models)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']

>>> import pyod.models.auto_encoder
Using TensorFlow backend.
>>> dir(pyod.models)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'auto_encoder', 'base', 'sklearn_base']

>>> import types
>>> for key, obj in pyod.models.__dict__.items():
...  if type(obj) is types.ModuleType:
...   print(key)
...
sklearn_base
base
auto_encoder

Success:
>>> import pkgutil
>>> import pyod.models as pm
>>> for importer, modname, ispkg in pkgutil.iter_modules(pm.__path__):
...  print("Found submodule %s (is a package: %s)" % (modname, ispkg))
...
Found submodule abod (is a package: False)
Found submodule auto_encoder (is a package: False)
Found submodule base (is a package: False)
Found submodule cblof (is a package: False)
Found submodule cof (is a package: False)
Found submodule combination (is a package: False)
Found submodule feature_bagging (is a package: False)
Found submodule gaal_base (is a package: False)
Found submodule hbos (is a package: False)
Found submodule iforest (is a package: False)
Found submodule knn (is a package: False)
Found submodule lmdd (is a package: False)
Found submodule loci (is a package: False)
Found submodule loda (is a package: False)
Found submodule lof (is a package: False)
Found submodule lscp (is a package: False)
Found submodule mcd (is a package: False)
Found submodule mo_gaal (is a package: False)
Found submodule ocsvm (is a package: False)
Found submodule pca (is a package: False)
Found submodule sklearn_base (is a package: False)
Found submodule so_gaal (is a package: False)
Found submodule sod (is a package: False)
Found submodule sos (is a package: False)
Found submodule vae (is a package: False)
Found submodule xgbod (is a package: False)
>>>

NOTE: If you are facing issues in importing "PyOD" submodules, then you should use the "git" method for installation, and import submodules as shown in this post.

ON UBUNTU USING PIP:

 (base) ashish@ashish-vBox:~/Desktop/workspace$ pip install pyod
 Collecting pyod
...
...
 Building wheels for collected packages: pyod, combo, suod
   Building wheel for pyod (setup.py) ... done
   Stored in directory: /home/ashish/.cache/pip/wheels/7a/72/cc/8d691190b9525ee49125be37ce231bb02ee0c71882dce4a1cd
...
...
 Successfully installed combo-0.1.0 pyod-0.7.8 suod-0.0.3

 (base) ashish@ashish-vBox:~/Desktop/workspace$ python
 Python 3.7.3 (default, Mar 27 2019, 22:11:17)
 [GCC 7.3.0] :: Anaconda, Inc. on linux
 Type "help", "copyright", "credits" or "license" for more information.

 >>> import pyod

 >>> dir(pyod.models)
 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']

 >>> pyod.models.__dir__()
 ['__name__', '__doc__', '__package__', '__loader__', '__spec__', '__path__', '__file__', '__cached__', '__builtins__']

 >>> dir(pyod.models.knn)
 Traceback (most recent call last):
   File "", line 1, in 
 AttributeError: module 'pyod.models' has no attribute 'knn'

 >>> import pyod.models.knn
 
 >>> dir(pyod.models.knn)
 ['BallTree', 'BaseDetector', 'KNN', 'NearestNeighbors', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'check_array', 'check_is_fitted', 'division', 'np', 'print_function', 'warn']
 >>>

ON UBUNTU USING "GIT CLONE":

 (base) ashish@ashish-vBox:~/Desktop/workspace/GitHub$ git clone https://github.com/yzhao062/pyod.git
 Cloning into 'pyod'...
 ...
 Receiving objects: 100% (6303/6303), 35.29 MiB | 201.00 KiB/s, done.
 Resolving deltas: 100% (4399/4399), done.
 
 (base) ashish@ashish-vBox:~/Desktop/workspace/GitHub$ dir
 pyod
 
 (base) ashish@ashish-vBox:~/Desktop/workspace/GitHub$ cd pyod
 
 (base) ashish@ashish-vBox:~/Desktop/workspace/GitHub/pyod$ ls
 appveyor.yml  docs             examples  MANIFEST.in  PULL_REQUEST_TEMPLATE.md  pypi_build_commands.txt  requirements_ci.txt  setup.cfg
 CHANGES.txt   environment.yml  LICENSE   notebooks    pyod                      README.rst               requirements.txt     setup.py
 
 (base) ashish@ashish-vBox:~/Desktop/workspace/GitHub/pyod$ pip install .
 Processing /home/ashish/Desktop/workspace/GitHub/pyod
 Requirement already satisfied: combo in /home/ashish/anaconda3/lib/python3.7/site-packages (from pyod==0.7.8) (0.1.0)
 ...
 Requirement already satisfied: setuptools in /home/ashish/anaconda3/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib->pyod==0.7.8) (41.0.1)
 Building wheels for collected packages: pyod
   Building wheel for pyod (setup.py) ... done
   Stored in directory: /tmp/pip-ephem-wheel-cache-0zrfc299/wheels/de/52/5e/5de975ee565f4a98ad7c50aacfcdb644c656fd3b9a68ed2f98
 Successfully built pyod
 Installing collected packages: pyod
 Successfully installed pyod-0.7.8 
 
 (base) ashish@ashish-vBox:~/Desktop/workspace/GitHub/pyod$ python
 Python 3.7.3 (default, Mar 27 2019, 22:11:17)
 [GCC 7.3.0] :: Anaconda, Inc. on linux
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import pyod
 >>> dir(pyod.models)
 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']

 >>>

--

IMPORTING THE PACKAGES:
 from pyod.models.lof import LOF
 from pyod.models.cblof import CBLOF
 from pyod.models.feature_bagging import FeatureBagging 

 dir(pyod.models.lof)
  ['BaseDetector',
   'LOF',
   'LocalOutlierFactor',
   '__builtins__',
   '__cached__',
   '__doc__',
   '__file__',
   '__loader__',
   '__name__',
   '__package__',
   '__spec__',
   '_get_sklearn_version',
   'check_array',
   'check_is_fitted',
   'division',
   'invert_order',
   'print_function']
   
 dir(pyod.models.cblof)
  ['BaseDetector',
   'CBLOF',
   'KMeans',
   '__all__',
   '__builtins__',
   '__cached__',
   '__doc__',
   '__file__',
   '__loader__',
   '__name__',
   '__package__',
   '__spec__',
   'cdist',
   'check_array',
   'check_estimator',
   'check_is_fitted',
   'check_parameter',
   'division',
   'np',
   'pairwise_distances_no_broadcast',
   'print_function',
   'warnings']
   
 dir(pyod.models.feature_bagging) 
  ['BaseDetector',
  'FeatureBagging',
  'LOF',
  'MAX_INT',
  'Parallel',
  '__builtins__',
  '__cached__',
  '__doc__',
  '__file__',
  '__loader__',
  '__name__',
  '__package__',
  '__spec__',
  '_parallel_decision_function',
  '_partition_estimators',
  '_set_random_states',
  'average',
  'check_array',
  'check_detector',
  'check_is_fitted',
  'check_parameter',
  'check_random_state',
  'clone',
  'delayed',
  'division',
  'generate_bagging_indices',
  'generate_indices',
  'maximization',
  'np',
  'numbers',
  'print_function',
  'sample_without_replacement']

--- --- ---

FILES THAT ARE DOWNLOADED ON "GIT CLONE":
D:\workspace\GitHub>git clone https://github.com/yzhao062/pyod.git

D:\workspace\GitHub>cd pyod

D:\workspace\GitHub\pyod>tree /f

D:.
¦   .gitattributes
¦   .gitignore
¦   .travis.yml
¦   appveyor.yml
¦   CHANGES.txt
¦   environment.yml
¦   LICENSE
¦   MANIFEST.in
¦   PULL_REQUEST_TEMPLATE.md
¦   pypi_build_commands.txt
¦   README.rst
¦   requirements.txt
¦   requirements_ci.txt
¦   setup.cfg
¦   setup.py
¦
+---.circleci
¦       config.backup
¦       config.backup_2
¦       config.backup_3
¦       config.yml
¦
+---docs
¦   ¦   about.rst
¦   ¦   api_cc.rst
¦   ¦   benchmark.rst
¦   ¦   command.txt
¦   ¦   conf.py
¦   ¦   example.rst
¦   ¦   faq.rst
¦   ¦   index.rst
¦   ¦   install.rst
¦   ¦   issues.rst
¦   ¦   make.bat
¦   ¦   Makefile
¦   ¦   pubs.rst
¦   ¦   pyod.models.rst
¦   ¦   pyod.rst
¦   ¦   pyod.test.rst
¦   ¦   pyod.utils.rst
¦   ¦   rebuild.bat
¦   ¦   relevant_knowledge.rst
¦   ¦   requirements.txt
¦   ¦   zreferences.bib
¦   ¦
¦   +---figs
¦   ¦       ALL.png
¦   ¦       KNN.png
¦   ¦
¦   +---tables
¦           prc.csv
¦           roc.csv
¦           time.csv
¦
+---examples
¦   ¦   abod_example.py
¦   ¦   ALL.png
¦   ¦   auto_encoder_example.py
¦   ¦   cblof_example.py
¦   ¦   cof_example.py
¦   ¦   comb_example.py
¦   ¦   compare_all_models.py
¦   ¦   feature_bagging_example.py
¦   ¦   generate_data_cluster_example.py
¦   ¦   hbos_example.py
¦   ¦   iforest_example.py
¦   ¦   KNN.png
¦   ¦   knn_example.py
¦   ¦   knn_mahalanobis_example.py
¦   ¦   lmdd_example.py
¦   ¦   loci_example.py
¦   ¦   loda_example.py
¦   ¦   lof_example.py
¦   ¦   lscp_example.py
¦   ¦   mcd_example.py
¦   ¦   mo_gaal_example.py
¦   ¦   ocsvm_example.py
¦   ¦   pca_example.py
¦   ¦   README.md
¦   ¦   sod_example.py
¦   ¦   sos_example.py
¦   ¦   so_gaal_example.py
¦   ¦   temp_do_not_use.ipynb
¦   ¦   temp_do_not_use.py
¦   ¦   vae_example.py
¦   ¦   xgbod_example.py
¦   ¦   __init__.py
¦   ¦
¦   +---data
¦   ¦       cardio.mat
¦   ¦       letter.mat
¦   ¦       mat_file_conversion.py
¦   ¦
¦   +---temp_do_not_use
¦           deprecated_functions.py
¦           fit_predict_verification.py
¦
+---notebooks
¦   ¦   Benchmark.ipynb
¦   ¦   benchmark.py
¦   ¦   Compare All Models.ipynb
¦   ¦   Model Combination.ipynb
¦   ¦
¦   +---data
¦           arrhythmia.mat
¦           cardio.mat
¦           glass.mat
¦           ionosphere.mat
¦           letter.mat
¦           lympho.mat
¦           mnist.mat
¦           musk.mat
¦           optdigits.mat
¦           pendigits.mat
¦           pima.mat
¦           README.md
¦           satellite.mat
¦           satimage-2.mat
¦           shuttle.mat
¦           vertebral.mat
¦           vowels.mat
¦           wbc.mat
¦
+---pyod
    ¦   version.py
    ¦   __init__.py
    ¦
    +---models
    ¦       abod.py
    ¦       auto_encoder.py
    ¦       base.py
    ¦       cblof.py
    ¦       cof.py
    ¦       combination.py
    ¦       feature_bagging.py
    ¦       gaal_base.py
    ¦       hbos.py
    ¦       iforest.py
    ¦       knn.py
    ¦       lmdd.py
    ¦       loci.py
    ¦       loda.py
    ¦       lof.py
    ¦       lscp.py
    ¦       mcd.py
    ¦       mo_gaal.py
    ¦       ocsvm.py
    ¦       pca.py
    ¦       sklearn_base.py
    ¦       sod.py
    ¦       sos.py
    ¦       so_gaal.py
    ¦       vae.py
    ¦       xgbod.py
    ¦       __init__.py
    ¦
    +---test
    ¦   ¦   conftest.py
    ¦   ¦   test_abod.py
    ¦   ¦   test_auto_encoder.py
    ¦   ¦   test_base.py
    ¦   ¦   test_cblof.py
    ¦   ¦   test_cof.py
    ¦   ¦   test_combination.py
    ¦   ¦   test_data.py
    ¦   ¦   test_feature_bagging.py
    ¦   ¦   test_hbos.py
    ¦   ¦   test_iforest.py
    ¦   ¦   test_knn.py
    ¦   ¦   test_lmdd.py
    ¦   ¦   test_loci.py
    ¦   ¦   test_loda.py
    ¦   ¦   test_lof.py
    ¦   ¦   test_lscp.py
    ¦   ¦   test_mcd.py
    ¦   ¦   test_mo_gaal.py
    ¦   ¦   test_ocsvm.py
    ¦   ¦   test_pca.py
    ¦   ¦   test_sod.py
    ¦   ¦   test_sos.py
    ¦   ¦   test_so_gaal.py
    ¦   ¦   test_stat_models.py
    ¦   ¦   test_utility.py
    ¦   ¦   test_vae.py
    ¦   ¦   test_xgbod.py
    ¦   ¦   __init__.py
    ¦   ¦
    ¦   +---data
    ¦           cardio.mat
    ¦           pima.mat
    ¦
    +---utils
            data.py
            example.py
            stat_models.py
            utility.py
            __init__.py 

D:\workspace\GitHub\pyod>

Note: It is beneficial to clone the Git repository of the PyOD package as it gives you the source code files that you can refer in case of any confusion and also it gives you the "examples" directory that code samples on how the PyOD models can be used and compared (such as in this file: "examples/compare_all_models.py").

No comments:

Post a Comment