Skip to content

Commit

Permalink
Update: bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AchintyaX committed Sep 11, 2022
1 parent 5e3dc63 commit 1be88dd
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 13 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ You can download the stock data and perform anomaly detection using a range of a

## Installation
For installing the pre-release version use -
` pip install https://github.com/AchintyaX/fad/releases/download/v0.1.0/fad-0.1.0-py3-none-any.whl`

## Usage
1. fetch_data - Used for fetching stock data using yahoo finance API and transforming it for anamoly detection :
```
In [1]: from fad import FinancialAnomalyDetector
Expand Down Expand Up @@ -36,9 +39,7 @@ Out[6]:
```

` pip install https://github.com/AchintyaX/fad/releases/download/v0.1.0/fad-0.1.0-py3-none-any.whl`

## Usage
2. anamly_detection - Used to find anomalies in the data returning the dataframe along with plotting them in the time series

The package has 2 primary methods -
1.
Expand Down
Binary file modified dist/fad-0.1.0-py3-none-any.whl
Binary file not shown.
Binary file modified dist/fad-0.1.0.tar.gz
Binary file not shown.
Binary file added dist/fad-0.1.1-py3-none-any.whl
Binary file not shown.
Binary file added dist/fad-0.1.1.tar.gz
Binary file not shown.
14 changes: 7 additions & 7 deletions fad/anamoly_utils.py → fad/anomaly_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@

def seasonal_ad_detector(data: pd.DataFrame, print_plot: bool = True) -> Optional[pd.DataFrame]:
seasonal_ad = SeasonalAD(c=seasonal_c, side=side)
anamolies = seasonal_ad.fit_detect(data)
anomalies = seasonal_ad.fit_detect(data)

if print_plot == True:
print(plot(data, anomaly=anamolies, anomaly_color="orange", anomaly_tag="marker"))
print(plot(data, anomaly=anomalies, anomaly_color="orange", anomaly_tag="marker"))

return anamolies
return anomalies

def min_cluster_detector(data: pd.DataFrame, print_plot: bool =True) -> Optional[pd.DataFrame]:
min_cluster_ad = MinClusterDetector(KMeans(n_clusters=3))
anamolies = min_cluster_ad.fit_detect(data)
min_cluster_ad = MinClusterDetector(KMeans(n_clusters=n_clusters))
anomalies = min_cluster_ad.fit_detect(data)

if print_plot == True:
plot(data, anomaly=anamolies, ts_linewidth=1, ts_markersize=3, anomaly_color='red', anomaly_alpha=0.3, curve_group='all')
plot(data, anomaly=anomalies, ts_linewidth=1, ts_markersize=3, anomaly_color='red', anomaly_alpha=0.3, curve_group='all')

return anamolies
return anomalies

def outlier_detector(data: pd.DataFrame, print_plot: bool = True) -> Optional[pd.DataFrame]:
outlier_ad = OutlierDetector(LocalOutlierFactor(contamination=contamination))
Expand Down
4 changes: 2 additions & 2 deletions fad/financial_ad.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
import yfinance as yf
import numpy as np
from fad.anamoly_utils import seasonal_ad_detector, min_cluster_detector, outlier_detector, level_shift_detector, volatile_shift_detector
from fad.anomaly_utils import seasonal_ad_detector, min_cluster_detector, outlier_detector, level_shift_detector, volatile_shift_detector
from adtk.data import validate_series


Expand Down Expand Up @@ -30,7 +30,7 @@ def fetch_data(self, company_name: str, start_date: str, end_date: str) -> pd.Da

return data

def anamoly_detect(self, data: pd.DataFrame, method: str = 'min_cluster_ad', print_plot: bool = True) -> pd.DataFrame:
def anomaly_detect(self, data: pd.DataFrame, method: str = 'min_cluster_ad', print_plot: bool = True) -> pd.DataFrame:
detection_method = self.detector_map[method]

anomalies = detection_method(data=data, print_plot=print_plot)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fad"
version = "0.1.0"
version = "0.1.1"
description = "experimentation with anamoly detection"
authors = ["Achintya Shankhdhar <achintya.shankhdhar@simpplr.com>"]
license = "MIT"
Expand Down

0 comments on commit 1be88dd

Please sign in to comment.