Skip to content

Commit

Permalink
Improve example documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhao062 authored and yuezhao@cs.toronto.edu committed Jun 18, 2018
1 parent 1ba7e6f commit c03e950
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -163,6 +163,7 @@ Full package structure can be found below:
See **examples directory** for more demos. ["examples/knn_example.py"](https://github.com/yzhao062/Pyod/blob/master/examples/knn_example.py)
demonstrates the basic APIs of PyOD using kNN detector. **It is noted the APIs for other detectors are similar**.

More detailed instruction of running examples can be found [here.](https://github.com/yzhao062/Pyod/blob/master/examples)
1. Initialize a kNN detector, fit the model, and make the prediction.
```python

Expand Down
28 changes: 24 additions & 4 deletions examples/README.md
@@ -1,19 +1,39 @@
### How to run examples?

First pyod should be installed or you should download the github respository.
````cmd
pip install pyod
pip install --upgrade pyod # make sure the latest version is installed!
````

After that, you could simply copy & paste the code and run with it.

### Introduction of Examples
Examples are structured as follows:
- Each example is structued as XXX_example.py
- Examples are named as XXX_example.py, in whhich XXX is the model name.
- All examples can find corresponding models at pyod/models/

The implemented examples includes:
For instance:
- kNN: knn_example.py
- HBOS: hbos_example.py
- ABOD: abod_example.py
- ... other individual algorithms

- Combination Frameworks: comb_example.py

Additionally, compare_all_models.py is for comparing all implemented algorithms.
Some examples have a Jupyter Notebook version at [Jupyter Notebooks](https://github.com/yzhao062/Pyod/tree/master/notebooks)

### What if I see "xxx module could be found" or "Unresolved reference"
Note, the examples import the models by usuing:

**First check pyod is installed with pip.**

If you have not but simply download the github repositoty, please make
sure the following codes are presented at the top of the code.

```python
import sys
sys.path.append("..")

```
This is a **temporary solution** for relative imports in case **pyod is not installed**.

Expand Down
38 changes: 14 additions & 24 deletions examples/temp_do_not_use.py
Expand Up @@ -23,13 +23,8 @@
from pyod.utils.data import get_color_codes
from pyod.utils.data import evaluate_print



import numpy as np




if __name__ == "__main__":
contamination = 0.1 # percentage of outliers
n_train = 2000 # number of training points
Expand All @@ -45,25 +40,20 @@

# train CBLOF detector
clf_name = 'CBLOF'
# clf = CBLOF(random_state=42)
clf = CBLOF(use_weights=True)
# clf = CBLOF(random_state=42, use_weights=True)
clf = CBLOF(random_state=42)
clf.fit(X_train)




#
# # get the prediction labels and outlier scores of the training data
# y_train_pred = clf.labels_ # binary labels (0: inliers, 1: outliers)
# y_train_scores = clf.decision_scores_ # raw outlier scores
#
# # get the prediction on the test data
# y_test_pred = clf.predict(X_test) # outlier labels (0 or 1)
# y_test_scores = clf.decision_function(X_test) # outlier scores
#
# # evaluate and print the results
# print("\nOn Training Data:")
# evaluate_print(clf_name, y_train, y_train_scores)
# print("\nOn Test Data:")
# evaluate_print(clf_name, y_test, y_test_scores)
# get the prediction labels and outlier scores of the training data
y_train_pred = clf.labels_ # binary labels (0: inliers, 1: outliers)
y_train_scores = clf.decision_scores_ # raw outlier scores

# get the prediction on the test data
y_test_pred = clf.predict(X_test) # outlier labels (0 or 1)
y_test_scores = clf.decision_function(X_test) # outlier scores

# evaluate and print the results
print("\nOn Training Data:")
evaluate_print(clf_name, y_train, y_train_scores)
print("\nOn Test Data:")
evaluate_print(clf_name, y_test, y_test_scores)

0 comments on commit c03e950

Please sign in to comment.