12 |
Sales forecast
13 |
30 |
Prediction:
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/start.bat:
--------------------------------------------------------------------------------
1 | cd C:\app\continuous-intelligence\ && python src/app.py
2 |
--------------------------------------------------------------------------------
/start.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | cd /app/continuous-intelligence && python src/app.py
4 |
--------------------------------------------------------------------------------
/test/app_test.py:
--------------------------------------------------------------------------------
1 | import requests
2 |
3 | def test_endpoint():
4 | query_params = '?date=2017-06-14&item_nbr=99197';
5 | resp = requests.get('http://localhost:5005/prediction' + query_params);
6 |
7 | assert resp.status_code == 200
8 |
--------------------------------------------------------------------------------
/test/evaluation_test.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import os
3 | import numpy as np
4 | from pytest import approx
5 | sys.path.append(os.path.join('..', 'src'))
6 | sys.path.append(os.path.join('src'))
7 | import evaluation
8 |
9 |
10 | def test_calculates_nwrmsle_for_perfect_match():
11 | estimate = np.array([1, 2, 3])
12 | actual = np.array([1, 2, 3])
13 | weights = np.array([1, 1, 1])
14 | calculated_nwrmsle = evaluation.nwrmsle(estimate, actual, weights)
15 |
16 | assert calculated_nwrmsle == 0.0
17 |
18 |
19 | def test_calculates_nwrmsle_for_imperfect_match():
20 | estimate = np.array([0, 0, 0])
21 | actual = np.array([1, 1, 1])
22 | weights = np.array([1, 1, 1])
23 | calculated_nwrmsle = evaluation.nwrmsle(estimate, actual, weights)
24 |
25 | # Assert by-hand calculation of nwrmsle is reasonably close to python calculation
26 | assert approx(calculated_nwrmsle, 0.69314718)
27 |
--------------------------------------------------------------------------------
/test/splitter_test.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import os
3 | import pandas as pd
4 | sys.path.append(os.path.join('..', 'src'))
5 | sys.path.append(os.path.join('src'))
6 | import splitter
7 |
8 | def test_get_validation_period():
9 | latest_date = pd.to_datetime('2017-11-22')
10 | actual_begin_date, actual_end_date = splitter.get_validation_period(latest_date)
11 | expected_begin_date = pd.to_datetime('2017-11-01')
12 | expected_end_date = pd.to_datetime('2017-11-16')
13 | assert actual_begin_date == expected_begin_date
14 | assert actual_end_date == expected_end_date
15 |
16 | def test_split_validation_train_by_validation_period():
17 | date1 = pd.to_datetime('2017-11-12')
18 | date2 = pd.to_datetime('2017-11-25')
19 | date3 = pd.to_datetime('2017-11-30')
20 | date4 = pd.to_datetime('2017-12-01')
21 | validation_begin_date = pd.to_datetime('2017-11-15')
22 | validation_end_date = pd.to_datetime('2017-11-30')
23 | d = {'date': [date1, date2, date3, date4], 'col2': [3, 4, 5, 6]}
24 | df = pd.DataFrame(data=d)
25 | df_train, df_validation = splitter.split_validation_train_by_validation_period(df, validation_begin_date, validation_end_date)
26 | assert df_train.shape[0] == 1
27 | assert df_validation.shape[0] == 2
28 |
--------------------------------------------------------------------------------
/test/test.py:
--------------------------------------------------------------------------------
1 | import unittest
2 | import json
3 |
4 | class TestAccuracy(unittest.TestCase):
5 | METRICS_FILE = "results/metrics.json"
6 |
7 | def test_80percent_error_score(self):
8 | with open(self.METRICS_FILE, 'r') as file:
9 | metrics = json.load(file)
10 | self.assertLessEqual(metrics['nwrmsle'], 0.80)
11 | self.assertGreater(metrics['r2_score'], 0.0)
12 |
13 |
14 | if __name__ == "__main__":
15 | unittest.main()
16 |
--------------------------------------------------------------------------------
/undeploy.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -xe
3 |
4 | TENANT_NAMESPACE=${TENANT:-admin}
5 | cat kubernetes/web.yml | sed "s/\\\$tenant\\\$/$TENANT_NAMESPACE/" | kubectl delete -f -
6 |
--------------------------------------------------------------------------------