Skip to content

Commit ecbf0fb

Browse files
committed
v0.4.0
changelog: - added function to compute AIC in metrics.so - added complete case check for TimeSeries module
1 parent 72855ef commit ecbf0fb

18 files changed

Lines changed: 911 additions & 250 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![checks](../../actions/workflows/checks.yml/badge.svg)](../../actions/workflows/checks.yml)
2-
[![pylint Score](https://mperlet.github.io/pybadge/badges/9.6.svg)](./logs/pylint/)
3-
[![Coverage score](https://img.shields.io/badge/coverage-99%25-red.svg)](./logs/cov.out)
2+
[![pylint Score](https://mperlet.github.io/pybadge/badges/10.0.svg)](./logs/pylint/)
3+
[![Coverage score](https://img.shields.io/badge/coverage-98%25-red.svg)](./logs/cov.out)
44
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](./LICENSE)
55
***
66

Binary file not shown.
125 KB
Binary file not shown.

bin/metrics/metrics.c

Lines changed: 820 additions & 162 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/metrics/metrics.pyx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Common metrics required in machine learning modules.
77
- ``rmse``: Root mean squared error
88
- ``mae``: Mean absolute error
99
- ``mape``: Mean absolute percentage error
10+
- ``aic``: Akaike information criterion
1011
1112
Credits
1213
-------
@@ -15,11 +16,13 @@ Credits
1516
Authors:
1617
- Diptesh
1718
18-
Date: Sep 10, 2021
19+
Date: Dec 19, 2021
1920
"""
2021

2122
import numpy as _np
2223

24+
from libc.math cimport log
25+
2326
# =============================================================================
2427
# --- User defined functions
2528
# =============================================================================
@@ -181,3 +184,48 @@ cpdef mape(list y, list y_hat):
181184
op += abs(1 - (b * a ** -1.0))
182185
op = op * arr_len ** -1.0
183186
return op
187+
188+
189+
cpdef double aic(list y, list y_hat, int k=1, str method="linear"):
190+
"""
191+
Compute `Akaike information criterion
192+
<https://en.wikipedia.org/wiki/Akaike_information_criterion>`_.
193+
194+
Parameters
195+
----------
196+
y : list
197+
198+
Actual values.
199+
200+
y_hat : list
201+
202+
Predicted values.
203+
204+
method : str, optional
205+
206+
Type of regression (the default is linear).
207+
208+
Returns
209+
-------
210+
op : float
211+
212+
Akaike information criterion.
213+
214+
"""
215+
cdef double op = 0.0
216+
cdef double sse = 0.0
217+
cdef double a = 0.0
218+
cdef double b = 0.0
219+
cdef int arr_len = 0
220+
cdef double small_sample = 0.0
221+
small_sample = arr_len * k ** -1
222+
arr_len = len(y)
223+
if method == "linear":
224+
for i in range(0, arr_len, 1):
225+
a = y[i]
226+
b = y_hat[i]
227+
sse += (a - b) ** 2
228+
op = 2 * k - 2 * log(sse)
229+
if small_sample <= 40:
230+
op += (2 * k * (k + 1)) * (arr_len - k - 1) ** -1
231+
return op

bin/metrics/metrics.so

58.5 KB
Binary file not shown.

bin/run_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ then
5151
printf "\nRating code style...\n\n"
5252
score=0
5353
cnt=0
54+
rm $proj_dir/logs/pylint/*.out
5455
for i in $(find "$proj_dir" -name "*.py")
5556
do
5657
file=${i#$(dirname "$(dirname "$i")")/}

logs/cov.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Name Stmts Miss Co
66
/media/ph33r/Data/Project/CodeLib/Git/mllib/lib/knn.py 70 0 100%
77
/media/ph33r/Data/Project/CodeLib/Git/mllib/lib/model.py 44 0 100%
88
/media/ph33r/Data/Project/CodeLib/Git/mllib/lib/opt.py 157 0 100%
9-
/media/ph33r/Data/Project/CodeLib/Git/mllib/lib/timeseries.py 33 1 97% 114
9+
/media/ph33r/Data/Project/CodeLib/Git/mllib/lib/timeseries.py 27 8 70% 95-99, 102-104
1010
/media/ph33r/Data/Project/CodeLib/Git/mllib/lib/tree.py 79 0 100%
1111
---------------------------------------------------------------------------------------------
12-
TOTAL 500 1 99%
12+
TOTAL 494 8 98%

logs/pylint/lib-timeseries-py.out

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
************* Module mllib.lib.timeseries
2-
timeseries.py:37:0: C0413: Import "import metrics" should be placed at the top of the module (wrong-import-position)
3-
timeseries.py:90:4: R0913: Too many arguments (6/5) (too-many-arguments)
4-
timeseries.py:108:8: E1101: Instance of 'TimeSeries' has no '_compute_metrics' member (no-member)
5-
timeseries.py:40:0: R0903: Too few public methods (1/2) (too-few-public-methods)
6-
timeseries.py:21:0: W0611: Unused Any imported from typing (unused-import)
7-
timeseries.py:25:0: W0611: Unused import os (unused-import)
8-
timeseries.py:31:0: W0611: Unused numpy imported as np (unused-import)
9-
timeseries.py:37:0: W0611: Unused import metrics (unused-import)
101

11-
-------------------------------------------------------------------
12-
Your code has been rated at 6.36/10 (previous run: 10.00/10, -3.64)
2+
--------------------------------------------------------------------
3+
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
134

logs/pylint/mllib-__main__-py.out

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
************* Module mllib.__main__
2-
__main__.py:168:24: E1136: Value 'op' is unsubscriptable (unsubscriptable-object)
31

4-
-------------------------------------------------------------------
5-
Your code has been rated at 9.43/10 (previous run: 10.00/10, -0.57)
2+
--------------------------------------------------------------------
3+
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
64

0 commit comments

Comments
 (0)