### Install DeepOD from Source using Git Source: https://github.com/xuhongzuo/deepod/blob/main/docs/start.install.rst Clones the DeepOD repository from GitHub and installs it locally using setup.py. This method is useful for developers who want to contribute or modify the library's code. Navigate to the cloned directory before running the installation command. ```bash git clone https://github.com/xuhongzuo/deepod.git cd pyod pip install . ``` -------------------------------- ### Install and Upgrade DeepOD using Pip Source: https://github.com/xuhongzuo/deepod/blob/main/docs/start.install.rst Installs the DeepOD library using pip. The first command performs a standard installation, while the second command upgrades to the latest version if already installed. Ensure you have the latest version for the most up-to-date features. ```bash pip install deepod ``` ```bash pip install --upgrade deepod ``` -------------------------------- ### Install DeepOD development version Source: https://github.com/xuhongzuo/deepod/blob/main/README.rst Installs the DeepOD framework from source after cloning the repository. This is recommended for development or to get the latest features. ```bash git clone https://github.com/xuhongzuo/DeepOD.git cd DeepOD pip install . ``` -------------------------------- ### Running Unsupervised Tabular AD with Testbed Source: https://github.com/xuhongzuo/deepod/blob/main/docs/start.examples.rst Provides a bash command to run unsupervised tabular anomaly detection using the DeepOD testbed. It specifies the model, number of runs, and the input directory for datasets. ```bash cd DeepOD pip install . cd testbed python testbed_unsupervised_ad.py --model DeepIsolationForest --runs 5 --input_dir ADBench ``` -------------------------------- ### Install DeepOD with pip Source: https://github.com/xuhongzuo/deepod/blob/main/README.rst Installs the DeepOD framework using pip. This is the standard way to add the library to your Python environment. ```bash pip install deepod ``` -------------------------------- ### Tabular Anomaly Detection with DeepOD Source: https://github.com/xuhongzuo/deepod/blob/main/docs/start.examples.rst Demonstrates the direct use of DeepOD for unsupervised and weakly-supervised tabular anomaly detection. It includes fitting models and obtaining anomaly scores, as well as evaluating the results using tabular_metrics. ```python from deepod.models.tabular import DeepSVDD clf = DeepSVDD() clf.fit(X_train, y=None) scores = clf.decision_function(X_test) ``` ```python from deepod.models.tabular import DevNet clf = DevNet() clf.fit(X_train, y=semi_y) # semi_y uses 1 for known anomalies, and 0 for unlabeled data scores = clf.decision_function(X_test) ``` ```python from deepod.metrics import tabular_metrics auc, ap, f1 = tabular_metrics(y_test, scores) ``` -------------------------------- ### Time Series Anomaly Detection with DeepOD Source: https://github.com/xuhongzuo/deepod/blob/main/docs/start.examples.rst Illustrates how to use DeepOD for time series anomaly detection. It covers fitting the TimesNet model, generating anomaly scores, and evaluating the performance using ts_metrics and point_adjustment. ```python from deepod.models.time_series import TimesNet clf = TimesNet() clf.fit(X_train) scores = clf.decision_function(X_test) ``` ```python from deepod.metrics import ts_metrics from deepod.metrics import point_adjustment # execute point adjustment for time series ad eval_metrics = ts_metrics(labels, scores) adj_eval_metrics = ts_metrics(labels, point_adjustment(labels, scores)) ``` -------------------------------- ### BSD 2-Clause License Text Source: https://github.com/xuhongzuo/deepod/blob/main/docs/additional.license.rst Provides the full text of the BSD 2-Clause License, including copyright information and disclaimers. This license permits redistribution and use in source and binary forms with specific conditions. ```plaintext BSD 2-Clause License Copyright (c) 2023, Hongzuo Xu All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ``` -------------------------------- ### Save and Load DeepOD Model with built-in methods Source: https://github.com/xuhongzuo/deepod/blob/main/docs/start.model_save.rst Demonstrates saving a trained DeepSVDD model to a file and then loading it back using the model's `save_model` and `load_model` class methods. This method is specific to the DeepOD library. ```python from deepod.models import DeepSVDD # training an anomaly detection model model = DeepSVDD() # or any other models in DeepOD model.fit(X_train) # training path = 'save_file.pkl' model.save_model(path) # save trained model at the assigned path # directly load trained model from path model = DeepSVDD.load_model(path) model.decision_function(X_test) # or model.predict(X_test) ``` -------------------------------- ### Save and Load DeepOD Model with Pickle Source: https://github.com/xuhongzuo/deepod/blob/main/docs/start.model_save.rst Shows how to save and load a trained DeepSVDD model using Python's built-in `pickle` module. This method allows for standard serialization and deserialization of the model object. ```python import pickle from deepod.models import DeepSVDD model = DeepSVDD() model.fit(X_train) with open('save_file.pkl', 'wb'): pickle.dump(model) with open('save_file.pkl', 'rb') model = pickle.load(f) model.decision_function(X_test) ``` -------------------------------- ### BibTeX Entry for Deep Isolation Forest Source: https://github.com/xuhongzuo/deepod/blob/main/README.rst This BibTeX entry provides citation details for the paper 'Deep Isolation Forest for Anomaly Detection' published in IEEE Transactions on Knowledge and Data Engineering. ```bibtex @ARTICLE{xu2023deep, author={Xu, Hongzuo and Pang, Guansong and Wang, Yijie and Wang, Yongjun}, journal={IEEE Transactions on Knowledge and Data Engineering}, title={Deep Isolation Forest for Anomaly Detection}, year={2023}, volume={35}, number={12}, pages={12591--12604}, doi={10.1109/TKDE.2023.3270293} } ``` -------------------------------- ### Tabular Anomaly Detection (Weakly-Supervised) Source: https://github.com/xuhongzuo/deepod/blob/main/README.rst Shows weakly-supervised tabular anomaly detection using the DevNet model from DeepOD. It requires partially labeled data where known anomalies are marked. ```python # weakly-supervised methods from deepod.models.tabular import DevNet clf = DevNet() clf.fit(X_train, y=semi_y) # semi_y uses 1 for known anomalies, and 0 for unlabeled data scores = clf.decision_function(X_test) ``` -------------------------------- ### DeepOD Model Fitting (Python) Source: https://github.com/xuhongzuo/deepod/blob/main/docs/api_cc.rst The `fit` method is used to train an anomaly detection model. For unsupervised methods, the target variable `y` is ignored. ```python from deepod.core.base_model import BaseDeepAD # Assuming 'model' is an instance of a DeepOD detector # X_train is the training data model.fit(X_train) ``` -------------------------------- ### Accessing DeepOD Training Labels (Python) Source: https://github.com/xuhongzuo/deepod/blob/main/docs/api_cc.rst The `labels_` attribute provides the binary labels (0 for inlier, 1 for outlier) assigned to the training data by the fitted model. ```python from deepod.core.base_model import BaseDeepAD # Assuming 'model' is a fitted DeepOD detector training_labels = model.labels_ ``` -------------------------------- ### DeepOD Citation (BibTeX) Source: https://github.com/xuhongzuo/deepod/blob/main/docs/index.rst BibTeX entry for citing the DeepOD paper in academic work. This format is commonly used in LaTeX documents for managing bibliographies. ```bibtex @ARTICLE{xu2023deep, author={Xu, Hongzuo and Pang, Guansong and Wang, Yijie and Wang, Yongjun}, journal={IEEE Transactions on Knowledge and Data Engineering}, title={Deep Isolation Forest for Anomaly Detection}, year={2023}, volume={}, number={}, pages={1-14}, doi={10.1109/TKDE.2023.3270293} } ``` -------------------------------- ### BibTeX Entry for Calibrated One-Class Classification Source: https://github.com/xuhongzuo/deepod/blob/main/README.rst This BibTeX entry provides citation details for the paper 'Calibrated one-class classification for unsupervised time series anomaly detection' published in IEEE Transactions on Knowledge and Data Engineering. ```bibtex @ARTICLE{xu2024calibrated, title={Calibrated one-class classification for unsupervised time series anomaly detection}, author={Xu, Hongzuo and Wang, Yijie and Jian, Songlei and Liao, Qing and Wang, Yongjun and Pang, Guansong}, journal={IEEE Transactions on Knowledge and Data Engineering}, year={2024}, publisher={IEEE} } ``` -------------------------------- ### Tabular Anomaly Detection (Unsupervised) Source: https://github.com/xuhongzuo/deepod/blob/main/README.rst Demonstrates unsupervised tabular anomaly detection using the DeepSVDD model from DeepOD. It includes fitting the model to training data and generating anomaly scores for test data. ```python # unsupervised methods from deepod.models.tabular import DeepSVDD clf = DeepSVDD() clf.fit(X_train, y=None) scores = clf.decision_function(X_test) ``` -------------------------------- ### Fit Detector Source: https://github.com/xuhongzuo/deepod/blob/main/docs/api_cc.rst Fits the DeepOD detector model to the provided data. The 'y' parameter is ignored for unsupervised methods. ```APIDOC ## POST /fit ### Description Fits the detector model to the training data. ### Method POST ### Endpoint /fit ### Parameters #### Request Body - **X** (numpy.ndarray or similar) - Required - The input data for training. - **y** (numpy.ndarray or similar) - Optional - The target labels (ignored in unsupervised methods). ### Request Example ```json { "X": "[[1, 2], [3, 4], [5, 6]]", "y": "[0, 0, 1]" } ``` ### Response #### Success Response (200) - **message** (str) - Indicates successful fitting. #### Response Example ```json { "message": "Model fitted successfully." } ``` ``` -------------------------------- ### Fitted Model Attributes Source: https://github.com/xuhongzuo/deepod/blob/main/docs/api_cc.rst Retrieves key attributes of the fitted DeepOD model, including decision scores and labels from the training data. ```APIDOC ## GET /attributes ### Description Retrieves the `decision_scores_` and `labels_` attributes of the fitted model, which represent the anomaly scores and binary labels of the training data, respectively. ### Method GET ### Endpoint /attributes ### Response #### Success Response (200) - **decision_scores_** (list of float) - The outlier scores of the training data. Higher scores indicate greater abnormality. - **labels_** (list of int) - The binary labels of the training data (0 for inliers, 1 for outliers). #### Response Example ```json { "decision_scores_": [0.05, 0.15, 0.85], "labels_": [0, 0, 1] } ``` ``` -------------------------------- ### DeepOD Outlier Prediction (Python) Source: https://github.com/xuhongzuo/deepod/blob/main/docs/api_cc.rst The `predict` method classifies samples as inliers (0) or outliers (1) based on the fitted detector's thresholds. ```python from deepod.core.base_model import BaseDeepAD # Assuming 'model' is a fitted DeepOD detector # X_test is the data for which to predict labels predicted_labels = model.predict(X_test) ``` -------------------------------- ### Time Series Anomaly Detection Source: https://github.com/xuhongzuo/deepod/blob/main/README.rst Demonstrates time-series anomaly detection using the TimesNet model from DeepOD. It includes fitting the model to training data and generating anomaly scores for test data. ```python # time series anomaly detection methods from deepod.models.time_series import TimesNet clf = TimesNet() clf.fit(X_train) scores = clf.decision_function(X_test) ``` -------------------------------- ### Predict Outlier Labels Source: https://github.com/xuhongzuo/deepod/blob/main/docs/api_cc.rst Predicts binary labels (inlier/outlier) for a given set of data points using the fitted detector. ```APIDOC ## POST /predict ### Description Predicts whether each sample in the input data is an outlier (1) or an inlier (0) based on the fitted detector. ### Method POST ### Endpoint /predict ### Parameters #### Request Body - **X** (numpy.ndarray or similar) - Required - The input data for which to predict outlier labels. ### Request Example ```json { "X": "[[1, 1], [2, 3], [8, 8]]" } ``` ### Response #### Success Response (200) - **labels** (list of int) - A list of binary labels (0 for inlier, 1 for outlier) for each data point in X. #### Response Example ```json { "labels": [0, 0, 1] } ``` ``` -------------------------------- ### Evaluate Tabular Anomaly Detection Source: https://github.com/xuhongzuo/deepod/blob/main/README.rst Evaluates the performance of tabular anomaly detection models using metrics like AUC, AP, and F1-score. Requires true labels and predicted anomaly scores. ```python # evaluation of tabular anomaly detection from deepod.metrics import tabular_metrics auc, ap, f1 = tabular_metrics(y_test, scores) ``` -------------------------------- ### Evaluate Time Series Anomaly Detection Source: https://github.com/xuhongzuo/deepod/blob/main/README.rst Evaluates time-series anomaly detection performance with metrics and optional point adjustment. It compares predicted scores against true labels. ```python # evaluation of time series anomaly detection from deepod.metrics import ts_metrics from deepod.metrics import point_adjustment # execute point adjustment for time series ad eval_metrics = ts_metrics(labels, scores) adj_eval_metrics = ts_metrics(labels, point_adjustment(labels, scores)) ``` -------------------------------- ### Predict Raw Anomaly Score Source: https://github.com/xuhongzuo/deepod/blob/main/docs/api_cc.rst Predicts the raw anomaly score for a given set of data points using the fitted detector. ```APIDOC ## POST /decision_function ### Description Predicts the raw anomaly score for input data using the fitted detector. Higher scores indicate a higher likelihood of being an anomaly. ### Method POST ### Endpoint /decision_function ### Parameters #### Request Body - **X** (numpy.ndarray or similar) - Required - The input data for which to predict anomaly scores. ### Request Example ```json { "X": "[[1, 1], [2, 3], [8, 8]]" } ``` ### Response #### Success Response (200) - **decision_scores** (list of float) - A list of anomaly scores for each data point in X. #### Response Example ```json { "decision_scores": [0.1, 0.5, 0.9] } ``` ``` -------------------------------- ### DeepOD Anomaly Score Prediction (Python) Source: https://github.com/xuhongzuo/deepod/blob/main/docs/api_cc.rst The `decision_function` method predicts the raw anomaly score for given data points. Higher scores indicate a greater likelihood of being an outlier. ```python from deepod.core.base_model import BaseDeepAD # Assuming 'model' is a fitted DeepOD detector # X_test is the data for which to predict anomaly scores anomaly_scores = model.decision_function(X_test) ``` -------------------------------- ### Accessing DeepOD Training Decision Scores (Python) Source: https://github.com/xuhongzuo/deepod/blob/main/docs/api_cc.rst The `decision_scores_` attribute stores the calculated outlier scores for the training data. These scores can be used to analyze the distribution of anomaly scores within the training set. ```python from deepod.core.base_model import BaseDeepAD # Assuming 'model' is a fitted DeepOD detector training_scores = model.decision_scores_ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.