Skip to content

Commit 8c48e15

Browse files
authored
Merge pull request #101 from zillow/getting-started-example
2 parents b2d1516 + 1adb33a commit 8c48e15

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Import ``luminaire`` module in python
4141
import luminaire
4242
```
4343

44-
Check out [Luminaire documentation](https://zillow.github.io/luminaire) for detailed description of methods and usage.
44+
See [Examples](#Examples) to get started. Also, refer to the [Luminaire documentation](https://zillow.github.io/luminaire) for detailed description of methods and usage.
4545

4646

4747
## Time Series Outlier Detection Workflow
@@ -70,6 +70,61 @@ the user needs to provide very minimal configuration for monitoring any type of
7070

7171
Luminaire can also monitor a set of data points over windows of time instead of tracking individual data points. This approach is well-suited for streaming use cases where sustained fluctuations are of greater concern than individual fluctuations. See [anomaly detection for streaming data](https://zillow.github.io/luminaire/tutorial/streaming.html) for detailed information.
7272

73+
## Examples
74+
75+
### Batch Time Series Monitoring
76+
```python
77+
import pandas as pd
78+
from luminaire.optimization.hyperparameter_optimization import HyperparameterOptimization
79+
from luminaire.exploration.data_exploration import DataExploration
80+
81+
data = pd.read_csv('Path to input time series data')
82+
# Input data should have a time column set as the index column of the dataframe and a value column named as 'raw'
83+
84+
# Optimization
85+
hopt_obj = HyperparameterOptimization(freq='D')
86+
opt_config = hopt_obj.run(data=data)
87+
88+
# Profiling
89+
de_obj = DataExploration(freq='D', **opt_config)
90+
training_data, pre_prc = de_obj.profile(data)
91+
92+
# Identify Model
93+
model_class_name = opt_config['LuminaireModel']
94+
module = __import__('luminaire.model', fromlist=[''])
95+
model_class = getattr(module, model_class_name)
96+
97+
# Training
98+
model_object = model_class(hyper_params=opt_config, freq='D')
99+
success, model_date, trained_model = model_object.train(data=training_data, **pre_prc)
100+
101+
# Scoring
102+
trained_model.score(100, '2021-01-01')
103+
```
104+
105+
### Streaming Time Series Monitoring
106+
```python
107+
import pandas as pd
108+
from luminaire.model.window_density import WindowDensityHyperParams, WindowDensityModel
109+
from luminaire.exploration.data_exploration import DataExploration
110+
111+
data = pd.read_csv('Path to input time series data')
112+
# Input data should have a time column set as the index column of the dataframe and a value column named as 'raw'
113+
114+
# Configuration Specs and Profiling
115+
config = WindowDensityHyperParams().params
116+
de_obj = DataExploration(**config)
117+
data, pre_prc = de_obj.stream_profile(df=data)
118+
config.update(pre_prc)
119+
120+
# Training
121+
wdm_obj = WindowDensityModel(hyper_params=config)
122+
success, training_end, model = wdm_obj.train(data=data)
123+
124+
# Scoring
125+
score, scored_window = model.score(scoring_data) # scoring_data is data over a time-window instead of a datapoint
126+
```
127+
73128
## Contributing
74129

75130
Want to help improve Luminaire? Check out our [contributing documentation](CONTRIBUTING.rst).

0 commit comments

Comments
 (0)