diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index c7b9e16..8515c30 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -1,7 +1,7 @@ name: Bug Report description: File a bug report title: "[Bug]: " -labels: ["bug"] +labels: ["1: bug", "2: tests"] assignees: - octocat body: @@ -49,7 +49,8 @@ body: label: Version description: What version of our product are you running? options: - - v0.4.0 (Default) + - v0.4.1 (Default) + - v0.4.0 validations: required: true diff --git a/.github/ISSUE_TEMPLATE/eda_request.yaml b/.github/ISSUE_TEMPLATE/eda_request.yaml index 6606858..563bdf3 100644 --- a/.github/ISSUE_TEMPLATE/eda_request.yaml +++ b/.github/ISSUE_TEMPLATE/eda_request.yaml @@ -1,7 +1,7 @@ name: EDA request description: Request an EDA request title: "[EDA]: " -labels: ["eda"] +labels: ["1: eda"] assignees: - octocat body: @@ -27,10 +27,10 @@ body: label: Additional context placeholder: Add any other context or screenshots about the EDA request here. validations: - required: false + required: false - type: markdown attributes: value: | - + ### NOTE: EDA branch(es) if at all created should not be merged into production/perennial branches i.e. (stable/testing/master) diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml index 9a5f0ec..c936b91 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yaml +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -1,7 +1,7 @@ name: Feature request description: Request a feature addition title: "[Feature]: " -labels: ["feature"] +labels: ["1: feature", "2: tests"] assignees: - octocat body: @@ -68,6 +68,7 @@ body: label: Version description: What version of our product are you running? options: - - v0.4.0 (Default) + - v0.4.1 (Default) + - v0.4.0 validations: required: true diff --git a/.github/ISSUE_TEMPLATE/maintenance_request.yaml b/.github/ISSUE_TEMPLATE/maintenance_request.yaml index b64324f..69e6460 100644 --- a/.github/ISSUE_TEMPLATE/maintenance_request.yaml +++ b/.github/ISSUE_TEMPLATE/maintenance_request.yaml @@ -1,7 +1,7 @@ name: Maintenance request description: Describe the technical debt or runtime updates title: "[Maintenance]: " -labels: ["maintenance"] +labels: ["1: maintenance"] assignees: - octocat body: @@ -27,7 +27,8 @@ body: label: Version description: What version of our product are you running? options: - - v0.4.0 (Default) + - v0.4.1 (Default) + - v0.4.0 validations: required: true diff --git a/.github/ISSUE_TEMPLATE/user_story.yaml b/.github/ISSUE_TEMPLATE/user_story.yaml index a384558..ab3e87e 100644 --- a/.github/ISSUE_TEMPLATE/user_story.yaml +++ b/.github/ISSUE_TEMPLATE/user_story.yaml @@ -1,7 +1,7 @@ name: User story description: A valuable increment of functionality, testable by the users title: "[User story]: " -labels: ["user story"] +labels: ["1: story"] assignees: - octocat body: @@ -60,10 +60,10 @@ body: label: Acceptance criteria placeholder: | NOTE: Acceptance criteria should be measurable and should be based on maximum possible limit. - + Example: If the acceptance criteria for an application is based on response time, specify the response time such that post which the application will not be adopted/used at all i.e. a deal breaker. Meaning if the acceptance criteria for response time is 1 minute, the end user will NOT use the application at all if the response time is more than 1 minute. validations: - required: true + required: true - type: input id: sponsor @@ -73,12 +73,11 @@ body: placeholder: ex. email@example.com validations: required: true - + - type: textarea id: add-context attributes: label: Additional context placeholder: Add any other context or screenshots about the user story here. validations: - required: false - + required: false diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 6eaaf32..8185fdd 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -22,11 +22,13 @@ on: - 'stable' - 'testing' - 'feature*' + - 'bug*' pull_request: branches: - 'stable' - 'testing' - 'feature*' + - 'bug*' - '!maintenance*' jobs: diff --git a/bin/metrics/build/lib.linux-x86_64-3.7/metrics.cpython-37m-x86_64-linux-gnu.so b/bin/metrics/build/lib.linux-x86_64-3.7/metrics.cpython-37m-x86_64-linux-gnu.so index da0163e..eaf4b30 100644 Binary files a/bin/metrics/build/lib.linux-x86_64-3.7/metrics.cpython-37m-x86_64-linux-gnu.so and b/bin/metrics/build/lib.linux-x86_64-3.7/metrics.cpython-37m-x86_64-linux-gnu.so differ diff --git a/bin/metrics/build/temp.linux-x86_64-3.7/metrics.o b/bin/metrics/build/temp.linux-x86_64-3.7/metrics.o index c7cdbc4..bffd605 100644 Binary files a/bin/metrics/build/temp.linux-x86_64-3.7/metrics.o and b/bin/metrics/build/temp.linux-x86_64-3.7/metrics.o differ diff --git a/bin/metrics/metrics.c b/bin/metrics/metrics.c index 4f93738..ada2577 100644 --- a/bin/metrics/metrics.c +++ b/bin/metrics/metrics.c @@ -821,7 +821,7 @@ static const char *__pyx_f[] = { /*--- Type declarations ---*/ struct __pyx_opt_args_7metrics_aic; -/* "metrics.pyx":190 +/* "metrics.pyx":211 * * * cpdef double aic(list y, list y_hat, int k, str method="linear"): # <<<<<<<<<<<<<< @@ -907,90 +907,6 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject /* GetBuiltinName.proto */ static PyObject *__Pyx_GetBuiltinName(PyObject *name); -/* PyDictVersioning.proto */ -#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS -#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) -#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) -#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ - (version_var) = __PYX_GET_DICT_VERSION(dict);\ - (cache_var) = (value); -#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ - static PY_UINT64_T __pyx_dict_version = 0;\ - static PyObject *__pyx_dict_cached_value = NULL;\ - if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ - (VAR) = __pyx_dict_cached_value;\ - } else {\ - (VAR) = __pyx_dict_cached_value = (LOOKUP);\ - __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ - }\ -} -static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); -static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); -static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); -#else -#define __PYX_GET_DICT_VERSION(dict) (0) -#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) -#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); -#endif - -/* GetModuleGlobalName.proto */ -#if CYTHON_USE_DICT_VERSIONS -#define __Pyx_GetModuleGlobalName(var, name) {\ - static PY_UINT64_T __pyx_dict_version = 0;\ - static PyObject *__pyx_dict_cached_value = NULL;\ - (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ - (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ - __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} -#define __Pyx_GetModuleGlobalNameUncached(var, name) {\ - PY_UINT64_T __pyx_dict_version;\ - PyObject *__pyx_dict_cached_value;\ - (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} -static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); -#else -#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) -#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) -static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); -#endif - -/* PyFunctionFastCall.proto */ -#if CYTHON_FAST_PYCALL -#define __Pyx_PyFunction_FastCall(func, args, nargs)\ - __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL) -#if 1 || PY_VERSION_HEX < 0x030600B1 -static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs); -#else -#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) -#endif -#define __Pyx_BUILD_ASSERT_EXPR(cond)\ - (sizeof(char [1 - 2*!(cond)]) - 1) -#ifndef Py_MEMBER_SIZE -#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) -#endif - static size_t __pyx_pyframe_localsplus_offset = 0; - #include "frameobject.h" - #define __Pxy_PyFrame_Initialize_Offsets()\ - ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ - (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) - #define __Pyx_PyFrame_GetLocalsplus(frame)\ - (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) -#endif - -/* PyCFunctionFastCall.proto */ -#if CYTHON_FAST_PYCCALL -static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs); -#else -#define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL) -#endif - -/* PyObjectCall.proto */ -#if CYTHON_COMPILING_IN_CPYTHON -static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); -#else -#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) -#endif - /* GetItemInt.proto */ #define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ @@ -1091,6 +1007,32 @@ static void __Pyx_WriteUnraisable(const char *name, int clineno, /* Import.proto */ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); +/* PyDictVersioning.proto */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) +#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ + (version_var) = __PYX_GET_DICT_VERSION(dict);\ + (cache_var) = (value); +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ + (VAR) = __pyx_dict_cached_value;\ + } else {\ + (VAR) = __pyx_dict_cached_value = (LOOKUP);\ + __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ + }\ +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); +#else +#define __PYX_GET_DICT_VERSION(dict) (0) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); +#endif + /* CLineInTraceback.proto */ #ifdef CYTHON_CLINE_IN_TRACEBACK #define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) @@ -1117,15 +1059,15 @@ static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename); -/* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); - /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); /* None.proto */ static CYTHON_INLINE long __Pyx_pow_long(long, long); +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + /* CIntFromPy.proto */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); @@ -1175,16 +1117,13 @@ static const char __pyx_k_name[] = "__name__"; static const char __pyx_k_test[] = "__test__"; static const char __pyx_k_numpy[] = "numpy"; static const char __pyx_k_range[] = "range"; -static const char __pyx_k_round[] = "round"; static const char __pyx_k_y_hat[] = "y_hat"; static const char __pyx_k_import[] = "__import__"; static const char __pyx_k_linear[] = "linear"; static const char __pyx_k_method[] = "method"; -static const char __pyx_k_corrcoef[] = "corrcoef"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; static const char __pyx_k_Common_metrics_required_in_mach[] = "\nCommon metrics required in machine learning modules.\n\n**Available functions:**\n - ``rsq``: R-Squared\n - ``mse``: Mean squared error\n - ``rmse``: Root mean squared error\n - ``mae``: Mean absolute error\n - ``mape``: Mean absolute percentage error\n - ``aic``: Akaike information criterion\n\nCredits\n-------\n::\n\n Authors:\n - Diptesh\n\n Date: Dec 19, 2021\n"; static PyObject *__pyx_n_s_cline_in_traceback; -static PyObject *__pyx_n_s_corrcoef; static PyObject *__pyx_n_s_import; static PyObject *__pyx_n_s_k; static PyObject *__pyx_n_s_linear; @@ -1194,7 +1133,6 @@ static PyObject *__pyx_n_s_name; static PyObject *__pyx_n_s_np; static PyObject *__pyx_n_s_numpy; static PyObject *__pyx_n_s_range; -static PyObject *__pyx_n_s_round; static PyObject *__pyx_n_s_test; static PyObject *__pyx_n_s_y; static PyObject *__pyx_n_s_y_hat; @@ -1205,8 +1143,6 @@ static PyObject *__pyx_pf_7metrics_6mae(CYTHON_UNUSED PyObject *__pyx_self, PyOb static PyObject *__pyx_pf_7metrics_8mape(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat); /* proto */ static PyObject *__pyx_pf_7metrics_10aic(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, int __pyx_v_k, PyObject *__pyx_v_method); /* proto */ static PyObject *__pyx_float_0_5; -static PyObject *__pyx_int_2; -static PyObject *__pyx_int_3; /* Late includes */ /* "metrics.pyx":31 @@ -1219,138 +1155,274 @@ static PyObject *__pyx_int_3; static PyObject *__pyx_pw_7metrics_1rsq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_f_7metrics_rsq(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, CYTHON_UNUSED int __pyx_skip_dispatch) { + int __pyx_v_i; + int __pyx_v_arr_len; + double __pyx_v_a; + double __pyx_v_b; + double __pyx_v_y_sum; + double __pyx_v_y_mean; + double __pyx_v_num; + double __pyx_v_den; + double __pyx_v_op; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; + Py_ssize_t __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; + double __pyx_t_6; + int __pyx_t_7; __Pyx_RefNannySetupContext("rsq", 0); /* "metrics.pyx":54 * * """ - * return _np.round(_np.corrcoef(y, y_hat)[0][1] ** 2, 3) # <<<<<<<<<<<<<< - * - * + * cdef int i = 0 # <<<<<<<<<<<<<< + * cdef int arr_len = 0 + * cdef double a = 0.0 */ - __Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_round); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_corrcoef); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - __pyx_t_6 = 1; - } + __pyx_v_i = 0; + + /* "metrics.pyx":55 + * """ + * cdef int i = 0 + * cdef int arr_len = 0 # <<<<<<<<<<<<<< + * cdef double a = 0.0 + * cdef double b = 0.0 + */ + __pyx_v_arr_len = 0; + + /* "metrics.pyx":56 + * cdef int i = 0 + * cdef int arr_len = 0 + * cdef double a = 0.0 # <<<<<<<<<<<<<< + * cdef double b = 0.0 + * cdef double y_sum = 0.0 + */ + __pyx_v_a = 0.0; + + /* "metrics.pyx":57 + * cdef int arr_len = 0 + * cdef double a = 0.0 + * cdef double b = 0.0 # <<<<<<<<<<<<<< + * cdef double y_sum = 0.0 + * cdef double y_mean = 0.0 + */ + __pyx_v_b = 0.0; + + /* "metrics.pyx":58 + * cdef double a = 0.0 + * cdef double b = 0.0 + * cdef double y_sum = 0.0 # <<<<<<<<<<<<<< + * cdef double y_mean = 0.0 + * cdef double num = 0.0 + */ + __pyx_v_y_sum = 0.0; + + /* "metrics.pyx":59 + * cdef double b = 0.0 + * cdef double y_sum = 0.0 + * cdef double y_mean = 0.0 # <<<<<<<<<<<<<< + * cdef double num = 0.0 + * cdef double den = 0.0 + */ + __pyx_v_y_mean = 0.0; + + /* "metrics.pyx":60 + * cdef double y_sum = 0.0 + * cdef double y_mean = 0.0 + * cdef double num = 0.0 # <<<<<<<<<<<<<< + * cdef double den = 0.0 + * cdef double op = 0.0 + */ + __pyx_v_num = 0.0; + + /* "metrics.pyx":61 + * cdef double y_mean = 0.0 + * cdef double num = 0.0 + * cdef double den = 0.0 # <<<<<<<<<<<<<< + * cdef double op = 0.0 + * arr_len = len(y) + */ + __pyx_v_den = 0.0; + + /* "metrics.pyx":62 + * cdef double num = 0.0 + * cdef double den = 0.0 + * cdef double op = 0.0 # <<<<<<<<<<<<<< + * arr_len = len(y) + * for i in range(0, arr_len, 1): + */ + __pyx_v_op = 0.0; + + /* "metrics.pyx":63 + * cdef double den = 0.0 + * cdef double op = 0.0 + * arr_len = len(y) # <<<<<<<<<<<<<< + * for i in range(0, arr_len, 1): + * a = y[i] + */ + if (unlikely(__pyx_v_y == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(0, 63, __pyx_L1_error) } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_y, __pyx_v_y_hat}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_y, __pyx_v_y_hat}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL; + __pyx_t_1 = PyList_GET_SIZE(__pyx_v_y); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 63, __pyx_L1_error) + __pyx_v_arr_len = __pyx_t_1; + + /* "metrics.pyx":64 + * cdef double op = 0.0 + * arr_len = len(y) + * for i in range(0, arr_len, 1): # <<<<<<<<<<<<<< + * a = y[i] + * y_sum += a + */ + __pyx_t_2 = __pyx_v_arr_len; + __pyx_t_3 = __pyx_t_2; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_i = __pyx_t_4; + + /* "metrics.pyx":65 + * arr_len = len(y) + * for i in range(0, arr_len, 1): + * a = y[i] # <<<<<<<<<<<<<< + * y_sum += a + * y_mean = y_sum * arr_len ** -1.0 + */ + if (unlikely(__pyx_v_y == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 65, __pyx_L1_error) } - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_y); - __Pyx_INCREF(__pyx_v_y_hat); - __Pyx_GIVEREF(__pyx_v_y_hat); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_y_hat); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_y, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 65, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 65, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_a = __pyx_t_6; + + /* "metrics.pyx":66 + * for i in range(0, arr_len, 1): + * a = y[i] + * y_sum += a # <<<<<<<<<<<<<< + * y_mean = y_sum * arr_len ** -1.0 + * for i in range(0, arr_len, 1): + */ + __pyx_v_y_sum = (__pyx_v_y_sum + __pyx_v_a); } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_5, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Power(__pyx_t_2, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_6 = 1; + + /* "metrics.pyx":67 + * a = y[i] + * y_sum += a + * y_mean = y_sum * arr_len ** -1.0 # <<<<<<<<<<<<<< + * for i in range(0, arr_len, 1): + * a = y[i] + */ + __pyx_v_y_mean = (__pyx_v_y_sum * pow(((double)__pyx_v_arr_len), -1.0)); + + /* "metrics.pyx":68 + * y_sum += a + * y_mean = y_sum * arr_len ** -1.0 + * for i in range(0, arr_len, 1): # <<<<<<<<<<<<<< + * a = y[i] + * b = y_hat[i] + */ + __pyx_t_2 = __pyx_v_arr_len; + __pyx_t_3 = __pyx_t_2; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_i = __pyx_t_4; + + /* "metrics.pyx":69 + * y_mean = y_sum * arr_len ** -1.0 + * for i in range(0, arr_len, 1): + * a = y[i] # <<<<<<<<<<<<<< + * b = y_hat[i] + * num += (a - b) ** 2 + */ + if (unlikely(__pyx_v_y == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 69, __pyx_L1_error) } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_5, __pyx_int_3}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_5, __pyx_int_3}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_y, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 69, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 69, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_2) { - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2); __pyx_t_2 = NULL; + __pyx_v_a = __pyx_t_6; + + /* "metrics.pyx":70 + * for i in range(0, arr_len, 1): + * a = y[i] + * b = y_hat[i] # <<<<<<<<<<<<<< + * num += (a - b) ** 2 + * den += (a - y_mean) ** 2 + */ + if (unlikely(__pyx_v_y_hat == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 70, __pyx_L1_error) } - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_t_5); - __Pyx_INCREF(__pyx_int_3); - __Pyx_GIVEREF(__pyx_int_3); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_int_3); - __pyx_t_5 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_y_hat, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 70, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 70, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_b = __pyx_t_6; + + /* "metrics.pyx":71 + * a = y[i] + * b = y_hat[i] + * num += (a - b) ** 2 # <<<<<<<<<<<<<< + * den += (a - y_mean) ** 2 + * if den != 0.0: + */ + __pyx_v_num = (__pyx_v_num + pow((__pyx_v_a - __pyx_v_b), 2.0)); + + /* "metrics.pyx":72 + * b = y_hat[i] + * num += (a - b) ** 2 + * den += (a - y_mean) ** 2 # <<<<<<<<<<<<<< + * if den != 0.0: + * op = 1 - (num * den ** -1.0) + */ + __pyx_v_den = (__pyx_v_den + pow((__pyx_v_a - __pyx_v_y_mean), 2.0)); } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + + /* "metrics.pyx":73 + * num += (a - b) ** 2 + * den += (a - y_mean) ** 2 + * if den != 0.0: # <<<<<<<<<<<<<< + * op = 1 - (num * den ** -1.0) + * return op + */ + __pyx_t_7 = ((__pyx_v_den != 0.0) != 0); + if (__pyx_t_7) { + + /* "metrics.pyx":74 + * den += (a - y_mean) ** 2 + * if den != 0.0: + * op = 1 - (num * den ** -1.0) # <<<<<<<<<<<<<< + * return op + * + */ + __pyx_v_op = (1.0 - (__pyx_v_num * pow(__pyx_v_den, -1.0))); + + /* "metrics.pyx":73 + * num += (a - b) ** 2 + * den += (a - y_mean) ** 2 + * if den != 0.0: # <<<<<<<<<<<<<< + * op = 1 - (num * den ** -1.0) + * return op + */ + } + + /* "metrics.pyx":75 + * if den != 0.0: + * op = 1 - (num * den ** -1.0) + * return op # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = PyFloat_FromDouble(__pyx_v_op); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 75, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; goto __pyx_L0; /* "metrics.pyx":31 @@ -1363,12 +1435,7 @@ static PyObject *__pyx_f_7metrics_rsq(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("metrics.rsq", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; @@ -1468,7 +1535,7 @@ static PyObject *__pyx_pf_7metrics_rsq(CYTHON_UNUSED PyObject *__pyx_self, PyObj return __pyx_r; } -/* "metrics.pyx":57 +/* "metrics.pyx":78 * * * cpdef mse(list y, list y_hat): # <<<<<<<<<<<<<< @@ -1493,7 +1560,7 @@ static PyObject *__pyx_f_7metrics_mse(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h double __pyx_t_6; __Pyx_RefNannySetupContext("mse", 0); - /* "metrics.pyx":83 + /* "metrics.pyx":104 * cdef double a * cdef double b * cdef double op = 0.0 # <<<<<<<<<<<<<< @@ -1502,7 +1569,7 @@ static PyObject *__pyx_f_7metrics_mse(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h */ __pyx_v_op = 0.0; - /* "metrics.pyx":84 + /* "metrics.pyx":105 * cdef double b * cdef double op = 0.0 * arr_len = len(y) # <<<<<<<<<<<<<< @@ -1511,12 +1578,12 @@ static PyObject *__pyx_f_7metrics_mse(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h */ if (unlikely(__pyx_v_y == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 84, __pyx_L1_error) + __PYX_ERR(0, 105, __pyx_L1_error) } - __pyx_t_1 = PyList_GET_SIZE(__pyx_v_y); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 84, __pyx_L1_error) + __pyx_t_1 = PyList_GET_SIZE(__pyx_v_y); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 105, __pyx_L1_error) __pyx_v_arr_len = __pyx_t_1; - /* "metrics.pyx":85 + /* "metrics.pyx":106 * cdef double op = 0.0 * arr_len = len(y) * for i in range(0, arr_len, 1): # <<<<<<<<<<<<<< @@ -1528,7 +1595,7 @@ static PyObject *__pyx_f_7metrics_mse(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; - /* "metrics.pyx":86 + /* "metrics.pyx":107 * arr_len = len(y) * for i in range(0, arr_len, 1): * a = y[i] # <<<<<<<<<<<<<< @@ -1537,15 +1604,15 @@ static PyObject *__pyx_f_7metrics_mse(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h */ if (unlikely(__pyx_v_y == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 86, __pyx_L1_error) + __PYX_ERR(0, 107, __pyx_L1_error) } - __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_y, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_y, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_a = __pyx_t_6; - /* "metrics.pyx":87 + /* "metrics.pyx":108 * for i in range(0, arr_len, 1): * a = y[i] * b = y_hat[i] # <<<<<<<<<<<<<< @@ -1554,15 +1621,15 @@ static PyObject *__pyx_f_7metrics_mse(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h */ if (unlikely(__pyx_v_y_hat == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 87, __pyx_L1_error) + __PYX_ERR(0, 108, __pyx_L1_error) } - __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_y_hat, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 87, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_y_hat, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 108, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 87, __pyx_L1_error) + __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 108, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_b = __pyx_t_6; - /* "metrics.pyx":88 + /* "metrics.pyx":109 * a = y[i] * b = y_hat[i] * op = op + (a - b) ** 2 # <<<<<<<<<<<<<< @@ -1572,7 +1639,7 @@ static PyObject *__pyx_f_7metrics_mse(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h __pyx_v_op = (__pyx_v_op + pow((__pyx_v_a - __pyx_v_b), 2.0)); } - /* "metrics.pyx":89 + /* "metrics.pyx":110 * b = y_hat[i] * op = op + (a - b) ** 2 * op = op * arr_len ** -1.0 # <<<<<<<<<<<<<< @@ -1581,7 +1648,7 @@ static PyObject *__pyx_f_7metrics_mse(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h */ __pyx_v_op = (__pyx_v_op * pow(((double)__pyx_v_arr_len), -1.0)); - /* "metrics.pyx":90 + /* "metrics.pyx":111 * op = op + (a - b) ** 2 * op = op * arr_len ** -1.0 * return op # <<<<<<<<<<<<<< @@ -1589,13 +1656,13 @@ static PyObject *__pyx_f_7metrics_mse(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h * cpdef rmse(list y, list y_hat): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = PyFloat_FromDouble(__pyx_v_op); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_5 = PyFloat_FromDouble(__pyx_v_op); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 111, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0; - /* "metrics.pyx":57 + /* "metrics.pyx":78 * * * cpdef mse(list y, list y_hat): # <<<<<<<<<<<<<< @@ -1646,11 +1713,11 @@ static PyObject *__pyx_pw_7metrics_3mse(PyObject *__pyx_self, PyObject *__pyx_ar case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y_hat)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("mse", 1, 2, 2, 1); __PYX_ERR(0, 57, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("mse", 1, 2, 2, 1); __PYX_ERR(0, 78, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "mse") < 0)) __PYX_ERR(0, 57, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "mse") < 0)) __PYX_ERR(0, 78, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -1663,14 +1730,14 @@ static PyObject *__pyx_pw_7metrics_3mse(PyObject *__pyx_self, PyObject *__pyx_ar } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("mse", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 57, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("mse", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 78, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrics.mse", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), (&PyList_Type), 1, "y", 1))) __PYX_ERR(0, 57, __pyx_L1_error) - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_hat), (&PyList_Type), 1, "y_hat", 1))) __PYX_ERR(0, 57, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), (&PyList_Type), 1, "y", 1))) __PYX_ERR(0, 78, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_hat), (&PyList_Type), 1, "y_hat", 1))) __PYX_ERR(0, 78, __pyx_L1_error) __pyx_r = __pyx_pf_7metrics_2mse(__pyx_self, __pyx_v_y, __pyx_v_y_hat); /* function exit code */ @@ -1688,7 +1755,7 @@ static PyObject *__pyx_pf_7metrics_2mse(CYTHON_UNUSED PyObject *__pyx_self, PyOb PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("mse", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_7metrics_mse(__pyx_v_y, __pyx_v_y_hat, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error) + __pyx_t_1 = __pyx_f_7metrics_mse(__pyx_v_y, __pyx_v_y_hat, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -1705,7 +1772,7 @@ static PyObject *__pyx_pf_7metrics_2mse(CYTHON_UNUSED PyObject *__pyx_self, PyOb return __pyx_r; } -/* "metrics.pyx":92 +/* "metrics.pyx":113 * return op * * cpdef rmse(list y, list y_hat): # <<<<<<<<<<<<<< @@ -1721,7 +1788,7 @@ static PyObject *__pyx_f_7metrics_rmse(PyObject *__pyx_v_y, PyObject *__pyx_v_y_ PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("rmse", 0); - /* "metrics.pyx":114 + /* "metrics.pyx":135 * * """ * return mse(y, y_hat) ** 0.5 # <<<<<<<<<<<<<< @@ -1729,16 +1796,16 @@ static PyObject *__pyx_f_7metrics_rmse(PyObject *__pyx_v_y, PyObject *__pyx_v_y_ * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_7metrics_mse(__pyx_v_y, __pyx_v_y_hat, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 114, __pyx_L1_error) + __pyx_t_1 = __pyx_f_7metrics_mse(__pyx_v_y, __pyx_v_y_hat, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_Power(__pyx_t_1, __pyx_float_0_5, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 114, __pyx_L1_error) + __pyx_t_2 = PyNumber_Power(__pyx_t_1, __pyx_float_0_5, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 135, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "metrics.pyx":92 + /* "metrics.pyx":113 * return op * * cpdef rmse(list y, list y_hat): # <<<<<<<<<<<<<< @@ -1790,11 +1857,11 @@ static PyObject *__pyx_pw_7metrics_5rmse(PyObject *__pyx_self, PyObject *__pyx_a case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y_hat)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("rmse", 1, 2, 2, 1); __PYX_ERR(0, 92, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("rmse", 1, 2, 2, 1); __PYX_ERR(0, 113, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "rmse") < 0)) __PYX_ERR(0, 92, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "rmse") < 0)) __PYX_ERR(0, 113, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -1807,14 +1874,14 @@ static PyObject *__pyx_pw_7metrics_5rmse(PyObject *__pyx_self, PyObject *__pyx_a } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("rmse", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 92, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("rmse", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 113, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrics.rmse", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), (&PyList_Type), 1, "y", 1))) __PYX_ERR(0, 92, __pyx_L1_error) - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_hat), (&PyList_Type), 1, "y_hat", 1))) __PYX_ERR(0, 92, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), (&PyList_Type), 1, "y", 1))) __PYX_ERR(0, 113, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_hat), (&PyList_Type), 1, "y_hat", 1))) __PYX_ERR(0, 113, __pyx_L1_error) __pyx_r = __pyx_pf_7metrics_4rmse(__pyx_self, __pyx_v_y, __pyx_v_y_hat); /* function exit code */ @@ -1832,7 +1899,7 @@ static PyObject *__pyx_pf_7metrics_4rmse(CYTHON_UNUSED PyObject *__pyx_self, PyO PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("rmse", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_7metrics_rmse(__pyx_v_y, __pyx_v_y_hat, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 92, __pyx_L1_error) + __pyx_t_1 = __pyx_f_7metrics_rmse(__pyx_v_y, __pyx_v_y_hat, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 113, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -1849,7 +1916,7 @@ static PyObject *__pyx_pf_7metrics_4rmse(CYTHON_UNUSED PyObject *__pyx_self, PyO return __pyx_r; } -/* "metrics.pyx":117 +/* "metrics.pyx":138 * * * cpdef mae(list y, list y_hat): # <<<<<<<<<<<<<< @@ -1874,7 +1941,7 @@ static PyObject *__pyx_f_7metrics_mae(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h double __pyx_t_6; __Pyx_RefNannySetupContext("mae", 0); - /* "metrics.pyx":143 + /* "metrics.pyx":164 * cdef double a * cdef double b * cdef double op = 0.0 # <<<<<<<<<<<<<< @@ -1883,7 +1950,7 @@ static PyObject *__pyx_f_7metrics_mae(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h */ __pyx_v_op = 0.0; - /* "metrics.pyx":144 + /* "metrics.pyx":165 * cdef double b * cdef double op = 0.0 * arr_len = len(y) # <<<<<<<<<<<<<< @@ -1892,12 +1959,12 @@ static PyObject *__pyx_f_7metrics_mae(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h */ if (unlikely(__pyx_v_y == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 144, __pyx_L1_error) + __PYX_ERR(0, 165, __pyx_L1_error) } - __pyx_t_1 = PyList_GET_SIZE(__pyx_v_y); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 144, __pyx_L1_error) + __pyx_t_1 = PyList_GET_SIZE(__pyx_v_y); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 165, __pyx_L1_error) __pyx_v_arr_len = __pyx_t_1; - /* "metrics.pyx":145 + /* "metrics.pyx":166 * cdef double op = 0.0 * arr_len = len(y) * for i in range(0, arr_len, 1): # <<<<<<<<<<<<<< @@ -1909,7 +1976,7 @@ static PyObject *__pyx_f_7metrics_mae(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; - /* "metrics.pyx":146 + /* "metrics.pyx":167 * arr_len = len(y) * for i in range(0, arr_len, 1): * a = y[i] # <<<<<<<<<<<<<< @@ -1918,15 +1985,15 @@ static PyObject *__pyx_f_7metrics_mae(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h */ if (unlikely(__pyx_v_y == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 146, __pyx_L1_error) + __PYX_ERR(0, 167, __pyx_L1_error) } - __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_y, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 146, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_y, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 167, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 146, __pyx_L1_error) + __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 167, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_a = __pyx_t_6; - /* "metrics.pyx":147 + /* "metrics.pyx":168 * for i in range(0, arr_len, 1): * a = y[i] * b = y_hat[i] # <<<<<<<<<<<<<< @@ -1935,15 +2002,15 @@ static PyObject *__pyx_f_7metrics_mae(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h */ if (unlikely(__pyx_v_y_hat == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 147, __pyx_L1_error) + __PYX_ERR(0, 168, __pyx_L1_error) } - __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_y_hat, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 147, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_y_hat, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 168, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 147, __pyx_L1_error) + __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 168, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_b = __pyx_t_6; - /* "metrics.pyx":148 + /* "metrics.pyx":169 * a = y[i] * b = y_hat[i] * op += abs(a - b) # <<<<<<<<<<<<<< @@ -1953,7 +2020,7 @@ static PyObject *__pyx_f_7metrics_mae(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h __pyx_v_op = (__pyx_v_op + fabs((__pyx_v_a - __pyx_v_b))); } - /* "metrics.pyx":149 + /* "metrics.pyx":170 * b = y_hat[i] * op += abs(a - b) * op = op * arr_len ** -1.0 # <<<<<<<<<<<<<< @@ -1962,7 +2029,7 @@ static PyObject *__pyx_f_7metrics_mae(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h */ __pyx_v_op = (__pyx_v_op * pow(((double)__pyx_v_arr_len), -1.0)); - /* "metrics.pyx":150 + /* "metrics.pyx":171 * op += abs(a - b) * op = op * arr_len ** -1.0 * return op # <<<<<<<<<<<<<< @@ -1970,13 +2037,13 @@ static PyObject *__pyx_f_7metrics_mae(PyObject *__pyx_v_y, PyObject *__pyx_v_y_h * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = PyFloat_FromDouble(__pyx_v_op); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 150, __pyx_L1_error) + __pyx_t_5 = PyFloat_FromDouble(__pyx_v_op); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0; - /* "metrics.pyx":117 + /* "metrics.pyx":138 * * * cpdef mae(list y, list y_hat): # <<<<<<<<<<<<<< @@ -2027,11 +2094,11 @@ static PyObject *__pyx_pw_7metrics_7mae(PyObject *__pyx_self, PyObject *__pyx_ar case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y_hat)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("mae", 1, 2, 2, 1); __PYX_ERR(0, 117, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("mae", 1, 2, 2, 1); __PYX_ERR(0, 138, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "mae") < 0)) __PYX_ERR(0, 117, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "mae") < 0)) __PYX_ERR(0, 138, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -2044,14 +2111,14 @@ static PyObject *__pyx_pw_7metrics_7mae(PyObject *__pyx_self, PyObject *__pyx_ar } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("mae", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 117, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("mae", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 138, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrics.mae", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), (&PyList_Type), 1, "y", 1))) __PYX_ERR(0, 117, __pyx_L1_error) - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_hat), (&PyList_Type), 1, "y_hat", 1))) __PYX_ERR(0, 117, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), (&PyList_Type), 1, "y", 1))) __PYX_ERR(0, 138, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_hat), (&PyList_Type), 1, "y_hat", 1))) __PYX_ERR(0, 138, __pyx_L1_error) __pyx_r = __pyx_pf_7metrics_6mae(__pyx_self, __pyx_v_y, __pyx_v_y_hat); /* function exit code */ @@ -2069,7 +2136,7 @@ static PyObject *__pyx_pf_7metrics_6mae(CYTHON_UNUSED PyObject *__pyx_self, PyOb PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("mae", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_7metrics_mae(__pyx_v_y, __pyx_v_y_hat, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 117, __pyx_L1_error) + __pyx_t_1 = __pyx_f_7metrics_mae(__pyx_v_y, __pyx_v_y_hat, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2086,7 +2153,7 @@ static PyObject *__pyx_pf_7metrics_6mae(CYTHON_UNUSED PyObject *__pyx_self, PyOb return __pyx_r; } -/* "metrics.pyx":153 +/* "metrics.pyx":174 * * * cpdef mape(list y, list y_hat): # <<<<<<<<<<<<<< @@ -2112,7 +2179,7 @@ static PyObject *__pyx_f_7metrics_mape(PyObject *__pyx_v_y, PyObject *__pyx_v_y_ int __pyx_t_7; __Pyx_RefNannySetupContext("mape", 0); - /* "metrics.pyx":179 + /* "metrics.pyx":200 * cdef double a * cdef double b * cdef double op = 0.0 # <<<<<<<<<<<<<< @@ -2121,7 +2188,7 @@ static PyObject *__pyx_f_7metrics_mape(PyObject *__pyx_v_y, PyObject *__pyx_v_y_ */ __pyx_v_op = 0.0; - /* "metrics.pyx":180 + /* "metrics.pyx":201 * cdef double b * cdef double op = 0.0 * arr_len = len(y) # <<<<<<<<<<<<<< @@ -2130,12 +2197,12 @@ static PyObject *__pyx_f_7metrics_mape(PyObject *__pyx_v_y, PyObject *__pyx_v_y_ */ if (unlikely(__pyx_v_y == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 180, __pyx_L1_error) + __PYX_ERR(0, 201, __pyx_L1_error) } - __pyx_t_1 = PyList_GET_SIZE(__pyx_v_y); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 180, __pyx_L1_error) + __pyx_t_1 = PyList_GET_SIZE(__pyx_v_y); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 201, __pyx_L1_error) __pyx_v_arr_len = __pyx_t_1; - /* "metrics.pyx":181 + /* "metrics.pyx":202 * cdef double op = 0.0 * arr_len = len(y) * for i in range(0, arr_len, 1): # <<<<<<<<<<<<<< @@ -2147,7 +2214,7 @@ static PyObject *__pyx_f_7metrics_mape(PyObject *__pyx_v_y, PyObject *__pyx_v_y_ for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; - /* "metrics.pyx":182 + /* "metrics.pyx":203 * arr_len = len(y) * for i in range(0, arr_len, 1): * a = y[i] # <<<<<<<<<<<<<< @@ -2156,15 +2223,15 @@ static PyObject *__pyx_f_7metrics_mape(PyObject *__pyx_v_y, PyObject *__pyx_v_y_ */ if (unlikely(__pyx_v_y == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 182, __pyx_L1_error) + __PYX_ERR(0, 203, __pyx_L1_error) } - __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_y, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 182, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_y, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 203, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 182, __pyx_L1_error) + __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 203, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_a = __pyx_t_6; - /* "metrics.pyx":183 + /* "metrics.pyx":204 * for i in range(0, arr_len, 1): * a = y[i] * b = y_hat[i] # <<<<<<<<<<<<<< @@ -2173,15 +2240,15 @@ static PyObject *__pyx_f_7metrics_mape(PyObject *__pyx_v_y, PyObject *__pyx_v_y_ */ if (unlikely(__pyx_v_y_hat == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 183, __pyx_L1_error) + __PYX_ERR(0, 204, __pyx_L1_error) } - __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_y_hat, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 183, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_y_hat, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 204, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 183, __pyx_L1_error) + __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 204, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_b = __pyx_t_6; - /* "metrics.pyx":184 + /* "metrics.pyx":205 * a = y[i] * b = y_hat[i] * if a != 0.0: # <<<<<<<<<<<<<< @@ -2191,7 +2258,7 @@ static PyObject *__pyx_f_7metrics_mape(PyObject *__pyx_v_y, PyObject *__pyx_v_y_ __pyx_t_7 = ((__pyx_v_a != 0.0) != 0); if (__pyx_t_7) { - /* "metrics.pyx":185 + /* "metrics.pyx":206 * b = y_hat[i] * if a != 0.0: * op += abs(1 - (b * a ** -1.0)) # <<<<<<<<<<<<<< @@ -2200,7 +2267,7 @@ static PyObject *__pyx_f_7metrics_mape(PyObject *__pyx_v_y, PyObject *__pyx_v_y_ */ __pyx_v_op = (__pyx_v_op + fabs((1.0 - (__pyx_v_b * pow(__pyx_v_a, -1.0))))); - /* "metrics.pyx":184 + /* "metrics.pyx":205 * a = y[i] * b = y_hat[i] * if a != 0.0: # <<<<<<<<<<<<<< @@ -2210,7 +2277,7 @@ static PyObject *__pyx_f_7metrics_mape(PyObject *__pyx_v_y, PyObject *__pyx_v_y_ } } - /* "metrics.pyx":186 + /* "metrics.pyx":207 * if a != 0.0: * op += abs(1 - (b * a ** -1.0)) * op = op * arr_len ** -1.0 # <<<<<<<<<<<<<< @@ -2219,7 +2286,7 @@ static PyObject *__pyx_f_7metrics_mape(PyObject *__pyx_v_y, PyObject *__pyx_v_y_ */ __pyx_v_op = (__pyx_v_op * pow(((double)__pyx_v_arr_len), -1.0)); - /* "metrics.pyx":187 + /* "metrics.pyx":208 * op += abs(1 - (b * a ** -1.0)) * op = op * arr_len ** -1.0 * return op # <<<<<<<<<<<<<< @@ -2227,13 +2294,13 @@ static PyObject *__pyx_f_7metrics_mape(PyObject *__pyx_v_y, PyObject *__pyx_v_y_ * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = PyFloat_FromDouble(__pyx_v_op); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 187, __pyx_L1_error) + __pyx_t_5 = PyFloat_FromDouble(__pyx_v_op); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 208, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0; - /* "metrics.pyx":153 + /* "metrics.pyx":174 * * * cpdef mape(list y, list y_hat): # <<<<<<<<<<<<<< @@ -2284,11 +2351,11 @@ static PyObject *__pyx_pw_7metrics_9mape(PyObject *__pyx_self, PyObject *__pyx_a case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y_hat)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("mape", 1, 2, 2, 1); __PYX_ERR(0, 153, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("mape", 1, 2, 2, 1); __PYX_ERR(0, 174, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "mape") < 0)) __PYX_ERR(0, 153, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "mape") < 0)) __PYX_ERR(0, 174, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -2301,14 +2368,14 @@ static PyObject *__pyx_pw_7metrics_9mape(PyObject *__pyx_self, PyObject *__pyx_a } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("mape", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 153, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("mape", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 174, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrics.mape", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), (&PyList_Type), 1, "y", 1))) __PYX_ERR(0, 153, __pyx_L1_error) - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_hat), (&PyList_Type), 1, "y_hat", 1))) __PYX_ERR(0, 153, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), (&PyList_Type), 1, "y", 1))) __PYX_ERR(0, 174, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_hat), (&PyList_Type), 1, "y_hat", 1))) __PYX_ERR(0, 174, __pyx_L1_error) __pyx_r = __pyx_pf_7metrics_8mape(__pyx_self, __pyx_v_y, __pyx_v_y_hat); /* function exit code */ @@ -2326,7 +2393,7 @@ static PyObject *__pyx_pf_7metrics_8mape(CYTHON_UNUSED PyObject *__pyx_self, PyO PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("mape", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_7metrics_mape(__pyx_v_y, __pyx_v_y_hat, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error) + __pyx_t_1 = __pyx_f_7metrics_mape(__pyx_v_y, __pyx_v_y_hat, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 174, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2343,7 +2410,7 @@ static PyObject *__pyx_pf_7metrics_8mape(CYTHON_UNUSED PyObject *__pyx_self, PyO return __pyx_r; } -/* "metrics.pyx":190 +/* "metrics.pyx":211 * * * cpdef double aic(list y, list y_hat, int k, str method="linear"): # <<<<<<<<<<<<<< @@ -2378,7 +2445,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, } } - /* "metrics.pyx":220 + /* "metrics.pyx":241 * * """ * cdef double op = 0.0 # <<<<<<<<<<<<<< @@ -2387,7 +2454,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, */ __pyx_v_op = 0.0; - /* "metrics.pyx":221 + /* "metrics.pyx":242 * """ * cdef double op = 0.0 * cdef double sse = 0.0 # <<<<<<<<<<<<<< @@ -2396,7 +2463,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, */ __pyx_v_sse = 0.0; - /* "metrics.pyx":222 + /* "metrics.pyx":243 * cdef double op = 0.0 * cdef double sse = 0.0 * cdef double a = 0.0 # <<<<<<<<<<<<<< @@ -2405,7 +2472,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, */ __pyx_v_a = 0.0; - /* "metrics.pyx":223 + /* "metrics.pyx":244 * cdef double sse = 0.0 * cdef double a = 0.0 * cdef double b = 0.0 # <<<<<<<<<<<<<< @@ -2414,7 +2481,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, */ __pyx_v_b = 0.0; - /* "metrics.pyx":224 + /* "metrics.pyx":245 * cdef double a = 0.0 * cdef double b = 0.0 * cdef int arr_len = 0 # <<<<<<<<<<<<<< @@ -2423,7 +2490,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, */ __pyx_v_arr_len = 0; - /* "metrics.pyx":225 + /* "metrics.pyx":246 * cdef double b = 0.0 * cdef int arr_len = 0 * cdef double small_sample = 0.0 # <<<<<<<<<<<<<< @@ -2432,7 +2499,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, */ __pyx_v_small_sample = 0.0; - /* "metrics.pyx":226 + /* "metrics.pyx":247 * cdef int arr_len = 0 * cdef double small_sample = 0.0 * small_sample = arr_len * k ** -1 # <<<<<<<<<<<<<< @@ -2441,7 +2508,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, */ __pyx_v_small_sample = (__pyx_v_arr_len * __Pyx_pow_long(((long)__pyx_v_k), -1L)); - /* "metrics.pyx":227 + /* "metrics.pyx":248 * cdef double small_sample = 0.0 * small_sample = arr_len * k ** -1 * arr_len = len(y) # <<<<<<<<<<<<<< @@ -2450,23 +2517,23 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, */ if (unlikely(__pyx_v_y == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 227, __pyx_L1_error) + __PYX_ERR(0, 248, __pyx_L1_error) } - __pyx_t_1 = PyList_GET_SIZE(__pyx_v_y); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 227, __pyx_L1_error) + __pyx_t_1 = PyList_GET_SIZE(__pyx_v_y); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 248, __pyx_L1_error) __pyx_v_arr_len = __pyx_t_1; - /* "metrics.pyx":228 + /* "metrics.pyx":249 * small_sample = arr_len * k ** -1 * arr_len = len(y) * if method == "linear": # <<<<<<<<<<<<<< * for i in range(0, arr_len, 1): * a = y[i] */ - __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_method, __pyx_n_s_linear, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 228, __pyx_L1_error) + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_method, __pyx_n_s_linear, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 249, __pyx_L1_error) __pyx_t_3 = (__pyx_t_2 != 0); if (__pyx_t_3) { - /* "metrics.pyx":229 + /* "metrics.pyx":250 * arr_len = len(y) * if method == "linear": * for i in range(0, arr_len, 1): # <<<<<<<<<<<<<< @@ -2478,7 +2545,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { __pyx_v_i = __pyx_t_6; - /* "metrics.pyx":230 + /* "metrics.pyx":251 * if method == "linear": * for i in range(0, arr_len, 1): * a = y[i] # <<<<<<<<<<<<<< @@ -2487,15 +2554,15 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, */ if (unlikely(__pyx_v_y == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 230, __pyx_L1_error) + __PYX_ERR(0, 251, __pyx_L1_error) } - __pyx_t_7 = __Pyx_GetItemInt_List(__pyx_v_y, __pyx_v_i, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 230, __pyx_L1_error) + __pyx_t_7 = __Pyx_GetItemInt_List(__pyx_v_y, __pyx_v_i, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 251, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __pyx_PyFloat_AsDouble(__pyx_t_7); if (unlikely((__pyx_t_8 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 230, __pyx_L1_error) + __pyx_t_8 = __pyx_PyFloat_AsDouble(__pyx_t_7); if (unlikely((__pyx_t_8 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 251, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_v_a = __pyx_t_8; - /* "metrics.pyx":231 + /* "metrics.pyx":252 * for i in range(0, arr_len, 1): * a = y[i] * b = y_hat[i] # <<<<<<<<<<<<<< @@ -2504,15 +2571,15 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, */ if (unlikely(__pyx_v_y_hat == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 231, __pyx_L1_error) + __PYX_ERR(0, 252, __pyx_L1_error) } - __pyx_t_7 = __Pyx_GetItemInt_List(__pyx_v_y_hat, __pyx_v_i, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 231, __pyx_L1_error) + __pyx_t_7 = __Pyx_GetItemInt_List(__pyx_v_y_hat, __pyx_v_i, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 252, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __pyx_PyFloat_AsDouble(__pyx_t_7); if (unlikely((__pyx_t_8 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 231, __pyx_L1_error) + __pyx_t_8 = __pyx_PyFloat_AsDouble(__pyx_t_7); if (unlikely((__pyx_t_8 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 252, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_v_b = __pyx_t_8; - /* "metrics.pyx":232 + /* "metrics.pyx":253 * a = y[i] * b = y_hat[i] * sse += (a - b) ** 2 # <<<<<<<<<<<<<< @@ -2522,7 +2589,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, __pyx_v_sse = (__pyx_v_sse + pow((__pyx_v_a - __pyx_v_b), 2.0)); } - /* "metrics.pyx":233 + /* "metrics.pyx":254 * b = y_hat[i] * sse += (a - b) ** 2 * op = 2 * k - 2 * log(sse) # <<<<<<<<<<<<<< @@ -2531,7 +2598,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, */ __pyx_v_op = ((2 * __pyx_v_k) - (2.0 * log(__pyx_v_sse))); - /* "metrics.pyx":234 + /* "metrics.pyx":255 * sse += (a - b) ** 2 * op = 2 * k - 2 * log(sse) * if small_sample <= 40: # <<<<<<<<<<<<<< @@ -2541,7 +2608,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, __pyx_t_3 = ((__pyx_v_small_sample <= 40.0) != 0); if (__pyx_t_3) { - /* "metrics.pyx":235 + /* "metrics.pyx":256 * op = 2 * k - 2 * log(sse) * if small_sample <= 40: * op += (2 * k * (k + 1)) * (arr_len - k - 1) ** -1 # <<<<<<<<<<<<<< @@ -2549,7 +2616,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, */ __pyx_v_op = (__pyx_v_op + (((2 * __pyx_v_k) * (__pyx_v_k + 1)) * __Pyx_pow_long(((__pyx_v_arr_len - __pyx_v_k) - 1), -1L))); - /* "metrics.pyx":234 + /* "metrics.pyx":255 * sse += (a - b) ** 2 * op = 2 * k - 2 * log(sse) * if small_sample <= 40: # <<<<<<<<<<<<<< @@ -2558,7 +2625,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, */ } - /* "metrics.pyx":228 + /* "metrics.pyx":249 * small_sample = arr_len * k ** -1 * arr_len = len(y) * if method == "linear": # <<<<<<<<<<<<<< @@ -2567,7 +2634,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, */ } - /* "metrics.pyx":236 + /* "metrics.pyx":257 * if small_sample <= 40: * op += (2 * k * (k + 1)) * (arr_len - k - 1) ** -1 * return op # <<<<<<<<<<<<<< @@ -2575,7 +2642,7 @@ static double __pyx_f_7metrics_aic(PyObject *__pyx_v_y, PyObject *__pyx_v_y_hat, __pyx_r = __pyx_v_op; goto __pyx_L0; - /* "metrics.pyx":190 + /* "metrics.pyx":211 * * * cpdef double aic(list y, list y_hat, int k, str method="linear"): # <<<<<<<<<<<<<< @@ -2632,13 +2699,13 @@ static PyObject *__pyx_pw_7metrics_11aic(PyObject *__pyx_self, PyObject *__pyx_a case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y_hat)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("aic", 0, 3, 4, 1); __PYX_ERR(0, 190, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("aic", 0, 3, 4, 1); __PYX_ERR(0, 211, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_k)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("aic", 0, 3, 4, 2); __PYX_ERR(0, 190, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("aic", 0, 3, 4, 2); __PYX_ERR(0, 211, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: @@ -2648,7 +2715,7 @@ static PyObject *__pyx_pw_7metrics_11aic(PyObject *__pyx_self, PyObject *__pyx_a } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "aic") < 0)) __PYX_ERR(0, 190, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "aic") < 0)) __PYX_ERR(0, 211, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -2663,20 +2730,20 @@ static PyObject *__pyx_pw_7metrics_11aic(PyObject *__pyx_self, PyObject *__pyx_a } __pyx_v_y = ((PyObject*)values[0]); __pyx_v_y_hat = ((PyObject*)values[1]); - __pyx_v_k = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_k == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 190, __pyx_L3_error) + __pyx_v_k = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_k == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 211, __pyx_L3_error) __pyx_v_method = ((PyObject*)values[3]); } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("aic", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 190, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("aic", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 211, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrics.aic", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), (&PyList_Type), 1, "y", 1))) __PYX_ERR(0, 190, __pyx_L1_error) - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_hat), (&PyList_Type), 1, "y_hat", 1))) __PYX_ERR(0, 190, __pyx_L1_error) - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_method), (&PyString_Type), 1, "method", 1))) __PYX_ERR(0, 190, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), (&PyList_Type), 1, "y", 1))) __PYX_ERR(0, 211, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_hat), (&PyList_Type), 1, "y_hat", 1))) __PYX_ERR(0, 211, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_method), (&PyString_Type), 1, "method", 1))) __PYX_ERR(0, 211, __pyx_L1_error) __pyx_r = __pyx_pf_7metrics_10aic(__pyx_self, __pyx_v_y, __pyx_v_y_hat, __pyx_v_k, __pyx_v_method); /* function exit code */ @@ -2699,7 +2766,7 @@ static PyObject *__pyx_pf_7metrics_10aic(CYTHON_UNUSED PyObject *__pyx_self, PyO __pyx_t_2.__pyx_n = 1; __pyx_t_2.method = __pyx_v_method; __pyx_t_1 = __pyx_f_7metrics_aic(__pyx_v_y, __pyx_v_y_hat, __pyx_v_k, 0, &__pyx_t_2); - __pyx_t_3 = PyFloat_FromDouble(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 190, __pyx_L1_error) + __pyx_t_3 = PyFloat_FromDouble(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 211, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; @@ -2769,7 +2836,6 @@ static struct PyModuleDef __pyx_moduledef = { static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, - {&__pyx_n_s_corrcoef, __pyx_k_corrcoef, sizeof(__pyx_k_corrcoef), 0, 0, 1, 1}, {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, {&__pyx_n_s_k, __pyx_k_k, sizeof(__pyx_k_k), 0, 0, 1, 1}, {&__pyx_n_s_linear, __pyx_k_linear, sizeof(__pyx_k_linear), 0, 0, 1, 1}, @@ -2779,14 +2845,13 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_np, __pyx_k_np, sizeof(__pyx_k_np), 0, 0, 1, 1}, {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1}, {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, - {&__pyx_n_s_round, __pyx_k_round, sizeof(__pyx_k_round), 0, 0, 1, 1}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, {&__pyx_n_s_y, __pyx_k_y, sizeof(__pyx_k_y), 0, 0, 1, 1}, {&__pyx_n_s_y_hat, __pyx_k_y_hat, sizeof(__pyx_k_y_hat), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 85, __pyx_L1_error) + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 64, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; @@ -2802,8 +2867,6 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); __pyx_float_0_5 = PyFloat_FromDouble(0.5); if (unlikely(!__pyx_float_0_5)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) __PYX_ERR(0, 1, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; @@ -3162,229 +3225,6 @@ static PyObject *__Pyx_GetBuiltinName(PyObject *name) { return result; } -/* PyDictVersioning */ -#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS -static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { - PyObject *dict = Py_TYPE(obj)->tp_dict; - return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; -} -static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { - PyObject **dictptr = NULL; - Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; - if (offset) { -#if CYTHON_COMPILING_IN_CPYTHON - dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); -#else - dictptr = _PyObject_GetDictPtr(obj); -#endif - } - return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; -} -static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { - PyObject *dict = Py_TYPE(obj)->tp_dict; - if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) - return 0; - return obj_dict_version == __Pyx_get_object_dict_version(obj); -} -#endif - -/* GetModuleGlobalName */ -#if CYTHON_USE_DICT_VERSIONS -static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) -#else -static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) -#endif -{ - PyObject *result; -#if !CYTHON_AVOID_BORROWED_REFS -#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 - result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } else if (unlikely(PyErr_Occurred())) { - return NULL; - } -#else - result = PyDict_GetItem(__pyx_d, name); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } -#endif -#else - result = PyObject_GetItem(__pyx_d, name); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } - PyErr_Clear(); -#endif - return __Pyx_GetBuiltinName(name); -} - -/* PyFunctionFastCall */ -#if CYTHON_FAST_PYCALL -static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na, - PyObject *globals) { - PyFrameObject *f; - PyThreadState *tstate = __Pyx_PyThreadState_Current; - PyObject **fastlocals; - Py_ssize_t i; - PyObject *result; - assert(globals != NULL); - /* XXX Perhaps we should create a specialized - PyFrame_New() that doesn't take locals, but does - take builtins without sanity checking them. - */ - assert(tstate != NULL); - f = PyFrame_New(tstate, co, globals, NULL); - if (f == NULL) { - return NULL; - } - fastlocals = __Pyx_PyFrame_GetLocalsplus(f); - for (i = 0; i < na; i++) { - Py_INCREF(*args); - fastlocals[i] = *args++; - } - result = PyEval_EvalFrameEx(f,0); - ++tstate->recursion_depth; - Py_DECREF(f); - --tstate->recursion_depth; - return result; -} -#if 1 || PY_VERSION_HEX < 0x030600B1 -static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) { - PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); - PyObject *globals = PyFunction_GET_GLOBALS(func); - PyObject *argdefs = PyFunction_GET_DEFAULTS(func); - PyObject *closure; -#if PY_MAJOR_VERSION >= 3 - PyObject *kwdefs; -#endif - PyObject *kwtuple, **k; - PyObject **d; - Py_ssize_t nd; - Py_ssize_t nk; - PyObject *result; - assert(kwargs == NULL || PyDict_Check(kwargs)); - nk = kwargs ? PyDict_Size(kwargs) : 0; - if (Py_EnterRecursiveCall((char*)" while calling a Python object")) { - return NULL; - } - if ( -#if PY_MAJOR_VERSION >= 3 - co->co_kwonlyargcount == 0 && -#endif - likely(kwargs == NULL || nk == 0) && - co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { - if (argdefs == NULL && co->co_argcount == nargs) { - result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals); - goto done; - } - else if (nargs == 0 && argdefs != NULL - && co->co_argcount == Py_SIZE(argdefs)) { - /* function called with no arguments, but all parameters have - a default value: use default values as arguments .*/ - args = &PyTuple_GET_ITEM(argdefs, 0); - result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals); - goto done; - } - } - if (kwargs != NULL) { - Py_ssize_t pos, i; - kwtuple = PyTuple_New(2 * nk); - if (kwtuple == NULL) { - result = NULL; - goto done; - } - k = &PyTuple_GET_ITEM(kwtuple, 0); - pos = i = 0; - while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) { - Py_INCREF(k[i]); - Py_INCREF(k[i+1]); - i += 2; - } - nk = i / 2; - } - else { - kwtuple = NULL; - k = NULL; - } - closure = PyFunction_GET_CLOSURE(func); -#if PY_MAJOR_VERSION >= 3 - kwdefs = PyFunction_GET_KW_DEFAULTS(func); -#endif - if (argdefs != NULL) { - d = &PyTuple_GET_ITEM(argdefs, 0); - nd = Py_SIZE(argdefs); - } - else { - d = NULL; - nd = 0; - } -#if PY_MAJOR_VERSION >= 3 - result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL, - args, (int)nargs, - k, (int)nk, - d, (int)nd, kwdefs, closure); -#else - result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, - args, (int)nargs, - k, (int)nk, - d, (int)nd, closure); -#endif - Py_XDECREF(kwtuple); -done: - Py_LeaveRecursiveCall(); - return result; -} -#endif -#endif - -/* PyCFunctionFastCall */ -#if CYTHON_FAST_PYCCALL -static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) { - PyCFunctionObject *func = (PyCFunctionObject*)func_obj; - PyCFunction meth = PyCFunction_GET_FUNCTION(func); - PyObject *self = PyCFunction_GET_SELF(func); - int flags = PyCFunction_GET_FLAGS(func); - assert(PyCFunction_Check(func)); - assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))); - assert(nargs >= 0); - assert(nargs == 0 || args != NULL); - /* _PyCFunction_FastCallDict() must not be called with an exception set, - because it may clear it (directly or indirectly) and so the - caller loses its exception */ - assert(!PyErr_Occurred()); - if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) { - return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL); - } else { - return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs); - } -} -#endif - -/* PyObjectCall */ -#if CYTHON_COMPILING_IN_CPYTHON -static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { - PyObject *result; - ternaryfunc call = func->ob_type->tp_call; - if (unlikely(!call)) - return PyObject_Call(func, arg, kw); - if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) - return NULL; - result = (*call)(func, arg, kw); - Py_LeaveRecursiveCall(); - if (unlikely(!result) && unlikely(!PyErr_Occurred())) { - PyErr_SetString( - PyExc_SystemError, - "NULL result without error in PyObject_Call"); - } - return result; -} -#endif - /* GetItemInt */ static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { PyObject *r; @@ -3915,6 +3755,32 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { return module; } +/* PyDictVersioning */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { + PyObject **dictptr = NULL; + Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; + if (offset) { +#if CYTHON_COMPILING_IN_CPYTHON + dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); +#else + dictptr = _PyObject_GetDictPtr(obj); +#endif + } + return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; +} +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) + return 0; + return obj_dict_version == __Pyx_get_object_dict_version(obj); +} +#endif + /* CLineInTraceback */ #ifndef CYTHON_CLINE_IN_TRACEBACK static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) { @@ -4144,37 +4010,6 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, return (target_type) value;\ } -/* CIntToPy */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { - const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; - const int is_unsigned = neg_one > const_zero; - if (is_unsigned) { - if (sizeof(long) < sizeof(long)) { - return PyInt_FromLong((long) value); - } else if (sizeof(long) <= sizeof(unsigned long)) { - return PyLong_FromUnsignedLong((unsigned long) value); -#ifdef HAVE_LONG_LONG - } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { - return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); -#endif - } - } else { - if (sizeof(long) <= sizeof(long)) { - return PyInt_FromLong((long) value); -#ifdef HAVE_LONG_LONG - } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { - return PyLong_FromLongLong((PY_LONG_LONG) value); -#endif - } - } - { - int one = 1; int little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&value; - return _PyLong_FromByteArray(bytes, sizeof(long), - little, !is_unsigned); - } -} - /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0; @@ -4233,6 +4068,37 @@ static CYTHON_INLINE long __Pyx_pow_long(long b, long e) { return t; } +/* CIntToPy */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); + } +} + /* CIntFromPy */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0; diff --git a/bin/metrics/metrics.pyx b/bin/metrics/metrics.pyx index 1ee757a..dcfdced 100644 --- a/bin/metrics/metrics.pyx +++ b/bin/metrics/metrics.pyx @@ -51,7 +51,28 @@ cpdef rsq(list y, list y_hat): R-Squared value. """ - return _np.round(_np.corrcoef(y, y_hat)[0][1] ** 2, 3) + cdef int i = 0 + cdef int arr_len = 0 + cdef double a = 0.0 + cdef double b = 0.0 + cdef double y_sum = 0.0 + cdef double y_mean = 0.0 + cdef double num = 0.0 + cdef double den = 0.0 + cdef double op = 0.0 + arr_len = len(y) + for i in range(0, arr_len, 1): + a = y[i] + y_sum += a + y_mean = y_sum * arr_len ** -1.0 + for i in range(0, arr_len, 1): + a = y[i] + b = y_hat[i] + num += (a - b) ** 2 + den += (a - y_mean) ** 2 + if den != 0.0: + op = 1 - (num * den ** -1.0) + return op cpdef mse(list y, list y_hat): diff --git a/bin/metrics/metrics.so b/bin/metrics/metrics.so index da0163e..eaf4b30 100644 Binary files a/bin/metrics/metrics.so and b/bin/metrics/metrics.so differ diff --git a/bin/run_tests.sh b/bin/run_tests.sh index a39cb95..2b9ae8c 100644 --- a/bin/run_tests.sh +++ b/bin/run_tests.sh @@ -31,7 +31,7 @@ printf "=%.0s" {1..70} # Run unit tests if [[ $module == "-a" || $module == "-u" ]] then - printf "\nRunning unit & integration tests...\n\n" + printf "\nRunning unit & integration tests ...\n\n" coverage run -m unittest discover -v -s $test_dir -p "test_*.py" coverage report -m --omit="*/tests/test_*,*/opt/spark-*" > "$proj_dir/logs/cov.out" COV_SCORE=`grep "TOTAL" $proj_dir/logs/cov.out | tail -1 | awk '{ printf("%d", $4) }'` @@ -48,7 +48,7 @@ fi # Rate coding styles for all python scripts if [[ $module == "-a" || $module == "-r" ]] then - printf "\nRating code style...\n\n" + printf "\nRating code style ...\n\n" score=0 cnt=0 rm $proj_dir/logs/pylint/*.out diff --git a/logs/cov.out b/logs/cov.out index c53241a..a011f83 100644 --- a/logs/cov.out +++ b/logs/cov.out @@ -6,7 +6,7 @@ Name Stmts Miss Co /media/ph33r/Data/Project/CodeLib/Git/mllib/lib/knn.py 70 0 100% /media/ph33r/Data/Project/CodeLib/Git/mllib/lib/model.py 44 0 100% /media/ph33r/Data/Project/CodeLib/Git/mllib/lib/opt.py 157 0 100% -/media/ph33r/Data/Project/CodeLib/Git/mllib/lib/timeseries.py 62 0 100% -/media/ph33r/Data/Project/CodeLib/Git/mllib/lib/tree.py 79 0 100% +/media/ph33r/Data/Project/CodeLib/Git/mllib/lib/timeseries.py 60 0 100% +/media/ph33r/Data/Project/CodeLib/Git/mllib/lib/tree.py 158 0 100% --------------------------------------------------------------------------------------------- -TOTAL 529 0 100% +TOTAL 606 0 100% diff --git a/logs/pylint/lib-timeseries-py.out b/logs/pylint/lib-timeseries-py.out index 255eb0b..21b6189 100644 --- a/logs/pylint/lib-timeseries-py.out +++ b/logs/pylint/lib-timeseries-py.out @@ -1,8 +1,8 @@ ************* Module mllib.lib.timeseries -timeseries.py:209:41: I1101: Module 'metrics' has no 'rsq' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) -timeseries.py:210:41: I1101: Module 'metrics' has no 'mae' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) -timeseries.py:211:42: I1101: Module 'metrics' has no 'mape' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) -timeseries.py:212:42: I1101: Module 'metrics' has no 'rmse' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) +timeseries.py:201:41: I1101: Module 'metrics' has no 'rsq' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) +timeseries.py:202:41: I1101: Module 'metrics' has no 'mae' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) +timeseries.py:203:42: I1101: Module 'metrics' has no 'mape' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) +timeseries.py:204:42: I1101: Module 'metrics' has no 'rmse' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) -------------------------------------------------------------------- Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00) diff --git a/logs/pylint/lib-tree-py.out b/logs/pylint/lib-tree-py.out index 1b9facf..874b694 100644 --- a/logs/pylint/lib-tree-py.out +++ b/logs/pylint/lib-tree-py.out @@ -1,8 +1,8 @@ ************* Module mllib.lib.tree -tree.py:73:45: I1101: Module 'metrics' has no 'rsq' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) -tree.py:74:45: I1101: Module 'metrics' has no 'mae' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) -tree.py:75:46: I1101: Module 'metrics' has no 'mape' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) -tree.py:76:46: I1101: Module 'metrics' has no 'rmse' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) +tree.py:96:45: I1101: Module 'metrics' has no 'rsq' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) +tree.py:97:45: I1101: Module 'metrics' has no 'mae' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) +tree.py:98:46: I1101: Module 'metrics' has no 'mape' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) +tree.py:99:46: I1101: Module 'metrics' has no 'rmse' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) -------------------------------------------------------------------- Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00) diff --git a/mllib/__main__.py b/mllib/__main__.py index c15175e..d2144a1 100644 --- a/mllib/__main__.py +++ b/mllib/__main__.py @@ -83,7 +83,7 @@ sep="\n") # --- Clustering start_t = time.time_ns() - df_ip = pd.read_csv(path + "input/" + fn_ip) + df_ip = pd.read_csv(path + "input/iris.csv") clus_sol = Cluster(df=df_ip, x_var=["x1"]) clus_sol.opt_k() print("\nClustering\n", @@ -160,12 +160,36 @@ sheet_name="exog") df_ip = df_ip.set_index("ts") mod = AutoArima(df=df_ip, y_var="y", x_var=["cost"]) - op = mod.metrics - print("\nTime series\n") + op = mod.model_summary + print("\nAutoArima timeseries\n") for k, v in op.items(): print(k, str(v).rjust(69 - len(k))) print(elapsed_time("Time", start_t), sep, sep="\n") + # --- Random forest time series + start_t = time.time_ns() + df_ip = pd.read_excel(path + "input/test_time_series.xlsx", + sheet_name="exog") + df_ip = df_ip.set_index("ts") + mod = RandomForest(df_ip, y_var="y", x_var=["cost"], method="timeseries") + print("\nRandom forest timeseries\n") + for k, v in mod.model_summary.items(): + print(k, str(v).rjust(69 - len(k))) + print(elapsed_time("Time", start_t), + sep, + sep="\n") + # --- XGBoost time series + start_t = time.time_ns() + df_ip = pd.read_excel(path + "input/test_time_series.xlsx", + sheet_name="exog") + df_ip = df_ip.set_index("ts") + mod = XGBoost(df=df_ip, y_var="y", x_var=["cost"], method="timeseries") + print("\nXGBoost timeseries\n") + for k, v in mod.model_summary.items(): + print(k, str(v).rjust(69 - len(k))) + print(elapsed_time("Time", start_t), + sep, + sep="\n") # --- EOF print(sep, elapsed_time("Total time", start), sep, sep="\n") diff --git a/mllib/lib/cfg.py b/mllib/lib/cfg.py index 8d1f966..042a6c6 100644 --- a/mllib/lib/cfg.py +++ b/mllib/lib/cfg.py @@ -44,7 +44,7 @@ from inspect import getsourcefile from os.path import abspath -__version__: str = "0.4.0" +__version__: str = "0.4.1" __doc__: str = "Machine Learning Library" module: str = "mllib" diff --git a/mllib/lib/metrics.so b/mllib/lib/metrics.so index da0163e..eaf4b30 100644 Binary files a/mllib/lib/metrics.so and b/mllib/lib/metrics.so differ diff --git a/mllib/lib/timeseries.py b/mllib/lib/timeseries.py index 9e29393..fb86ec0 100644 --- a/mllib/lib/timeseries.py +++ b/mllib/lib/timeseries.py @@ -13,7 +13,7 @@ - Diptesh - Madhu - Date: Dec 31, 2021 + Date: Jan 05, 2022 """ # pylint: disable=invalid-name @@ -64,7 +64,7 @@ class AutoArima(): Independant variables (the default is None). - params: dict, optional + param: dict, optional Time series parameters (the default is None). If no parameters are passed the following is set as parameters:: @@ -86,12 +86,7 @@ class AutoArima(): Final optimal model. - metrics: Dict - - Model metrics containing key metrics like R-squared, RMSE, MSE, MAE, - MAPE. - - model_summary: object + model_summary: Dict Model summary with optimal parameters. @@ -116,25 +111,22 @@ def __init__(self, df: pd.DataFrame, y_var: str, x_var: List[str] = None, - params: Dict[str, object] = None + param: Dict[str, object] = None ): """Initialize variables.""" self.df = df self.y_var = y_var self.x_var = x_var - self.params = params + self.param = param self.y_hat = None - self.model_summary = None # Set default parameters - if self.params is None: - self.params = self._seasonality() + if self.param is None: + self.param = self._seasonality() # Build optimal model - self.model = self._opt_params() - self.opt_params = self.model.to_dict() + self.model = self._opt_param() + self.opt_param = self.model.to_dict() # Compute metrics - self.metrics = self._compute_metrics() - # Model summary - self.model_summary = self.model.summary() + self.model_summary = self._compute_metrics() def _seasonality(self) -> Dict[str, object]: """Determine seasonality and return parameters.""" @@ -146,61 +138,61 @@ def _seasonality(self) -> Dict[str, object]: seasonal = True if m < 2: # pragma: no cover seasonal = False - params = {"max_p": 15, - "max_d": 2, - "max_q": 15, - "max_P": 15, - "max_D": 2, - "max_Q": 15, - "seasonal": seasonal, - "m": m, - "threshold": 0.05, - "debug": False} - return params - - def _opt_params(self) -> object: + param = {"max_p": 15, + "max_d": 2, + "max_q": 15, + "max_P": 15, + "max_D": 2, + "max_Q": 15, + "seasonal": seasonal, + "m": m, + "threshold": 0.05, + "debug": False} + return param + + def _opt_param(self) -> object: if self.x_var is None: model = pm.auto_arima(y=self.df[[self.y_var]], start_p=0, - max_p=self.params["max_p"], - max_d=self.params["max_d"], + max_p=self.param["max_p"], + max_d=self.param["max_d"], start_q=0, - max_q=self.params["max_q"], + max_q=self.param["max_q"], start_P=0, - max_P=self.params["max_P"], - max_D=self.params["max_D"], + max_P=self.param["max_P"], + max_D=self.param["max_D"], start_Q=0, - max_Q=self.params["max_Q"], + max_Q=self.param["max_Q"], information_criterion="aicc", - alpha=self.params["threshold"], - trace=self.params["debug"], - seasonal=self.params["seasonal"], - m=self.params["m"]) + alpha=self.param["threshold"], + trace=self.param["debug"], + seasonal=self.param["seasonal"], + m=self.param["m"]) else: model = pm.auto_arima(y=self.df[[self.y_var]], X=self.df[self.x_var], start_p=0, - max_p=self.params["max_p"], - max_d=self.params["max_d"], + max_p=self.param["max_p"], + max_d=self.param["max_d"], start_q=0, - max_q=self.params["max_q"], + max_q=self.param["max_q"], start_P=0, - max_P=self.params["max_P"], - max_D=self.params["max_D"], + max_P=self.param["max_P"], + max_D=self.param["max_D"], start_Q=0, - max_Q=self.params["max_Q"], + max_Q=self.param["max_Q"], information_criterion="aicc", - alpha=self.params["threshold"], - trace=self.params["debug"], - seasonal=self.params["seasonal"], - m=self.params["m"]) + alpha=self.param["threshold"], + trace=self.param["debug"], + seasonal=self.param["seasonal"], + m=self.param["m"]) return model def _compute_metrics(self) -> Dict[str, float]: """Compute commonly used metrics to evaluate the model.""" y = self.df[[self.y_var]].iloc[:, 0].values.tolist() if self.x_var is None: - d = self.opt_params["order"][1] + d = self.opt_param["order"][1] y_hat = list(self.model.predict_in_sample(start=d, end=len(self.df))) else: @@ -238,7 +230,7 @@ def predict(self, """ if self.x_var is None: df_pred = self.model.predict(n_periods=n_interval, - alpha=self.params["threshold"], + alpha=self.param["threshold"], return_conf_int=False) df_pred = pd.DataFrame(df_pred) df_pred.columns = [self.y_var] @@ -246,7 +238,7 @@ def predict(self, n_interval = x_predict.shape[0] df_pred = self.model.predict(n_periods=n_interval, X=x_predict, - alpha=self.params["threshold"], + alpha=self.param["threshold"], return_conf_int=False) df_pred = pd.DataFrame(df_pred) df_pred = pd.concat([df_pred, x_predict.reset_index(drop=True)], diff --git a/mllib/lib/tree.py b/mllib/lib/tree.py index 5a33fb9..18dec44 100644 --- a/mllib/lib/tree.py +++ b/mllib/lib/tree.py @@ -14,11 +14,11 @@ - Diptesh - Madhu - Date: Sep 27, 2021 + Date: Jan 15, 2022 """ # pylint: disable=invalid-name -# pylint: disable=R0902,R0903,R0913,C0413 +# pylint: disable=W0511,R0902,R0903,R0913,C0413 from typing import List, Dict, Any @@ -32,8 +32,12 @@ import sklearn.ensemble as rf import xgboost as xgb -from sklearn.model_selection import RandomizedSearchCV +from scipy.stats import norm from sklearn.metrics import classification_report +from sklearn.model_selection import RandomizedSearchCV +from sklearn.model_selection import TimeSeriesSplit as ts_split +from statsmodels.tsa.stattools import pacf +from statsmodels.tsa.seasonal import seasonal_decompose path = abspath(getsourcefile(lambda: 0)) path = re.sub(r"(.+\/)(.+.py)", "\\1", path) @@ -48,17 +52,31 @@ class Tree(): def __init__(self, df: pd.DataFrame, y_var: str, - x_var: List[str], + x_var: List[str] = None, method: str = "regression", k_fold: int = 5, - param: Dict = None): + param: Dict = None, + ts_param: Dict = None): """Initialize variables.""" self.y_var = y_var self.x_var = x_var - self.df = df.reset_index(drop=True) + self.df = df self.method = method + if self.method in ("classify", "regression"): + self.df = self.df.reset_index(drop=True) self.k_fold = k_fold self.seed = 1 + if self.method == "timeseries": + self.ts_param = ts_param + if self.ts_param is None: + self.ts_param = {} + self.ts_param["threshold"] = 0.05 + self.ts_param["max_lag"] = 20 + self.ts_param["ts_x_var"] = None + self.ts_param["ts_lag_var"] = None + self._ts_data_transform() + self.k_fold = ts_split(n_splits=self.k_fold)\ + .split(X=self.ts_df[self.y_var]) self.model = None self.model_summary = None self.param = param @@ -67,9 +85,14 @@ def __init__(self, def _compute_metrics(self): """Compute commonly used metrics to evaluate the model.""" - y = self.df.loc[:, self.y_var].values.tolist() - y_hat = list(self.model.predict(self.df[self.x_var])) - if self.method == "regression": + if self.method in ("classify", "regression"): + y = self.df.loc[:, self.y_var].values.tolist() + y_hat = list(self.model.predict(self.df[self.x_var])) + elif self.method == "timeseries": + y = self.ts_df.loc[:, self.y_var].values.tolist() + y_hat = list(self.model.predict( + self.ts_df[self.ts_param["ts_x_var"]])) + if self.method in ("regression", "timeseries"): model_summary = {"rsq": np.round(metrics.rsq(y, y_hat), 3), "mae": np.round(metrics.mae(y, y_hat), 3), "mape": np.round(metrics.mape(y, y_hat), 3), @@ -86,15 +109,86 @@ def _compute_metrics(self): for key in model_summary} self.model_summary = model_summary + def _ts_data_transform(self): + """Transform input data with significant lag variables.""" + # Determine seasonality and return seaonal lag + decomposition = seasonal_decompose(self.df[self.y_var], + model="additive") + _seasonal = decomposition.seasonal + freq = _seasonal.value_counts() + self.ts_param["seasonality"] = \ + int(np.ceil(len(self.df) / freq.iloc[0])) + # Determine significant lags + df = self.df.copy(deep=True) + df = df[self.y_var] + df = pd.DataFrame({"lag": list(range(self.ts_param["max_lag"]+1)), + "pacf": pacf(df, + nlags=self.ts_param["max_lag"], + method='ols')}) + df["thres_val"] = \ + (np.round(norm.ppf(1 - (self.ts_param["threshold"] / 2)), 2) + / (len(self.df) ** 0.5)) + df["pacf_sig"] = np.where((df['pacf'] >= df["thres_val"]) + | (df['pacf'] <= - df["thres_val"]), + 1, 0) + df = df.where(df['pacf_sig'] > 0) + df = df.dropna() + self.ts_param["ts_lag_var"] = df['lag'].astype(int).to_list() + self.ts_param["ts_lag_var"].append(self.ts_param["seasonality"]) + self.ts_param["ts_lag_var"] = \ + [x for x in self.ts_param["ts_lag_var"] if x != 0] + self.ts_param["ts_lag_var"] = list(set(self.ts_param["ts_lag_var"])) + self.ts_df = pd.DataFrame(self.df.loc[:, self.y_var]) + # TODO: Add integration test + if len(self.ts_param["ts_lag_var"]) == 0: # pragma: no cover + self.ts_param["ts_lag_var"] = [1] + for lag in self.ts_param["ts_lag_var"]: + self.ts_df.loc[:, "lag_" + str(lag)] = \ + self.ts_df[self.y_var].shift(lag) + if self.x_var is not None: + self.ts_df = self.ts_df.join(self.df[self.x_var]) + self.ts_df = self.ts_df.dropna() + self.ts_param["ts_x_var"] = list(self.ts_df.columns) + self.ts_param["ts_x_var"].remove(self.y_var) + def _fit(self) -> Dict[str, Any]: # pragma: no cover """Fit model.""" return self.best_params_ - def predict(self, x_predict: pd.DataFrame) -> pd.DataFrame: + def _ts_predict(self, + x_predict: pd.DataFrame = None, + n_interval: int = 1) -> pd.DataFrame: + """Predict values for time series.""" + if self.x_var is None: + df_op = [-1.0] * n_interval + df_op = pd.DataFrame(df_op) + df_op.columns = [self.y_var] + else: + df_op = x_predict.copy(deep=True) + df_op[self.y_var] = -1.0 + lst_lag_val = self.df[self.y_var].tolist() + for i, _ in enumerate(df_op): + df_pred_x = pd.DataFrame(df_op.iloc[i]).T + for j, _ in enumerate(self.ts_param["ts_lag_var"]): + df_pred_x["lag_" + str(self.ts_param["ts_lag_var"][j])] \ + = lst_lag_val[len(lst_lag_val) + - self.ts_param["ts_lag_var"][j]] + df_pred_x = pd.DataFrame(df_pred_x) + y_hat = self.model.predict(df_pred_x[self.ts_param["ts_x_var"]]) + df_op.iloc[i, df_op.columns.get_loc(self.y_var)] = y_hat[0] + lst_lag_val.append(y_hat[0]) + return df_op + + def predict(self, + x_predict: pd.DataFrame = None, + n_interval: int = 1) -> pd.DataFrame: """Predict values.""" - df_op = x_predict.copy(deep=True) - y_hat = self.model.predict(x_predict) - df_op.insert(loc=0, column=self.y_var, value=y_hat) + if self.method == "timeseries": + df_op = self._ts_predict(x_predict, n_interval) + else: + df_op = x_predict.copy(deep=True) + y_hat = self.model.predict(x_predict) + df_op.insert(loc=0, column=self.y_var, value=y_hat) return df_op @@ -122,12 +216,17 @@ class RandomForest(Tree): method : str, optional - Can be either `classify` or `regression` (the default is regression) + Can be either `classify`, `timeseries` or `regression` + (the default is regression) k_fold : int, optional Number of cross validations folds (the default is 5) + threshold : float, optional + + Threshold to identify significant lag values (the default is 0.05) + param : dict, optional Random forest parameters (the default is None). @@ -139,6 +238,17 @@ class RandomForest(Tree): max_features: ["sqrt", "auto"] min_samples_leaf: [2, 5] + ts_param : dict, optional + + Random forest parameters (the default is None). + In case of None, the parameters will default to:: + + threshold: 0.05 + max_lag: 20 + ts_x_var: None + ts_lag_var: None + seasonality: None + Returns ------- model : object @@ -170,18 +280,27 @@ def _fit(self) -> Dict[str, Any]: """Fit RandomForest model.""" if self.param is None: self.param = {"bootstrap": [True], - "max_depth": list(range(1, len(self.x_var))), "n_estimators": [100]} if self.method == "classify": self.param["max_features"] = ["sqrt"] self.param["min_samples_leaf"] = [2] + self.param["max_depth"] = list(range(1, len(self.x_var))) elif self.method == "regression": - self.param["max_features"] = [int(len(self.x_var) / 3)] + self.param["max_features"] \ + = [int(np.ceil(len(self.x_var) / 3))] + self.param["min_samples_leaf"] = [5] + self.param["max_depth"] \ + = list(range(1, len(self.x_var))) + elif self.method == "timeseries": + self.param["max_features"] \ + = [int(np.ceil(len(self.ts_param["ts_x_var"]) / 3))] self.param["min_samples_leaf"] = [5] + self.param["max_depth"] = \ + list(range(1, len(self.ts_param["ts_x_var"]))) if self.method == "classify": tmp_model = rf.RandomForestClassifier(oob_score=True, random_state=self.seed) - elif self.method == "regression": + elif self.method in ("regression", "timeseries"): tmp_model = rf.RandomForestRegressor(oob_score=True, random_state=self.seed) gs = RandomizedSearchCV(estimator=tmp_model, @@ -192,8 +311,12 @@ def _fit(self) -> Dict[str, Any]: n_iter=3, return_train_score=True, cv=self.k_fold) - gs_op = gs.fit(self.df[self.x_var], - self.df[self.y_var]) + if self.method == "timeseries": + gs_op = gs.fit(self.ts_df[self.ts_param["ts_x_var"]], + self.ts_df[self.y_var]) + elif self.method in ("regression", "classify"): + gs_op = gs.fit(self.df[self.x_var], + self.df[self.y_var]) self.model = gs_op return gs_op.best_params_ @@ -222,12 +345,17 @@ class XGBoost(Tree): method : str, optional - Can be either `classify` or `regression` (the default is regression) + Can be either `classify`, `timeseries` or `regression` + (the default is regression) k_fold : int, optional Number of cross validations folds (the default is 5) + threshold : float, optional + + Threshold to identify significant lag values (the default is 0.05) + param : dict, optional XGBoost parameters (the default is None). @@ -238,9 +366,20 @@ class XGBoost(Tree): subsample: [0.5, 0.75, 1.0] colsample_bytree: [0.5, 1.0] min_child_weight: [0.5, 1.0, 3.0] - max_depth: [int(len(self.x_var) * 0.8)] + max_depth: [int(len(self.x_var) * 0.8] objective: ["reg:squarederror", "binary:logistic"] + ts_param : dict, optional + + Random forest time series parameters (the default is None). + In case of None, the parameters will default to:: + + threshold: 0.05 + max_lag: 20 + ts_x_var: None + ts_lag_var: None + seasonlity: None + Returns ------- model : object @@ -275,11 +414,15 @@ def _fit(self) -> Dict[str, Any]: "learning_rate": [0.01, 0.1, 0.2, 0.3], "subsample": [0.5, 0.75, 1.0], "colsample_bytree": [0.5, 1.0], - "min_child_weight": [0.5, 1.0, 3.0], - "max_depth": [int(len(self.x_var) * 0.8)]} + "min_child_weight": [0.5, 1.0, 3.0]} + if self.method == "timeseries": + self.param["max_depth"] = \ + [int(len(self.ts_param["ts_x_var"]) * 0.8)] + elif self.method in ("regression", "classify"): + self.param["max_depth"] = [int(len(self.x_var) * 0.8)] if self.method == "classify": self.param["objective"] = ["binary:logistic"] - elif self.method == "regression": + elif self.method in ("regression", "timeseries"): self.param["objective"] = ["reg:squarederror"] if self.method == "classify": tmp_model = xgb.XGBClassifier(n_jobs=1, @@ -288,7 +431,7 @@ def _fit(self) -> Dict[str, Any]: random_state=self.seed, seed=self.seed, use_label_encoder=False) - elif self.method == "regression": + elif self.method in ("regression", "timeseries"): tmp_model = xgb.XGBRegressor(n_jobs=1, verbosity=0, silent=True, @@ -303,7 +446,11 @@ def _fit(self) -> Dict[str, Any]: return_train_score=True, cv=self.k_fold, random_state=self.seed) - gs_op = gs.fit(self.df[self.x_var], - self.df[self.y_var]) + if self.method == "timeseries": + gs_op = gs.fit(self.ts_df[self.ts_param["ts_x_var"]], + self.ts_df[self.y_var]) + elif self.method in ("regression", "classify"): + gs_op = gs.fit(self.df[self.x_var], + self.df[self.y_var]) self.model = gs_op return gs_op.best_params_ diff --git a/requirements.txt b/requirements.txt index cf109e0..4cac1b2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,10 @@ -pandas==1.0.1 +pmdarima==1.8.0 +xgboost==1.5.0 +scipy==1.4.1 xlrd==1.2.0 PuLP==1.6.8 -pmdarima==1.8.0 numpy==1.18.1 +pandas==1.0.1 Cython==0.29.15 statsmodels==0.11.0 -xgboost==1.5.0 scikit_learn==1.0.2 diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 3132a1d..29a5a05 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -57,7 +57,7 @@ def test_rsq(self): """Metrics: Test for R-squared""" y = [3, 8, 10, 17, 24, 27] y_hat = [2, 8, 10, 13, 18, 20] - exp_op = 0.973 + exp_op = 0.772 op = np.round(metrics.rsq(y, y_hat), 3) self.assertEqual(op, exp_op) diff --git a/tests/test_timeseries.py b/tests/test_timeseries.py index 35964f6..c8f2c0b 100644 --- a/tests/test_timeseries.py +++ b/tests/test_timeseries.py @@ -8,7 +8,7 @@ Authors: - Diptesh - Date: Sep 07, 2021 + Date: Jan 05, 2022 """ # pylint: disable=invalid-name @@ -72,11 +72,11 @@ def test_multivariate(self): y_var = "y" x_var = ["cost"] mod = AutoArima(df=df_ip, y_var=y_var, x_var=x_var) - metrics = mod.metrics + metrics = mod.model_summary X = pd.DataFrame(df_ip.iloc[-1]).T op = mod.predict(x_predict=X[x_var])[y_var][0] exp_op = X[y_var][0] - self.assertEqual(mod.opt_params["order"], (0, 1, 1)) + self.assertEqual(mod.opt_param["order"], (0, 1, 1)) self.assertAlmostEqual(1.0, metrics["rsq"], places=1) self.assertLessEqual(metrics["mape"], 0.1) self.assertAlmostEqual(op, exp_op, places=0) diff --git a/tests/test_tree.py b/tests/test_tree.py index 016e8e9..d049730 100644 --- a/tests/test_tree.py +++ b/tests/test_tree.py @@ -80,7 +80,6 @@ def test_rf_class(self): acc = round(sk_metrics.accuracy_score(y, y_hat), 2) self.assertGreaterEqual(acc, 0.93) - @ignore_warnings def test_rf_reg(self): """RandomForest: Test for regression""" x_var = ["x1", "x2", "x3", "x4"] @@ -97,6 +96,35 @@ def test_rf_reg(self): mse = round(sk_metrics.mean_squared_error(y, y_hat), 2) self.assertLessEqual(mse, 0.1) + def test_rf_ts_exog(self): + """RandomForest: Test for time series with exogenous variables""" + x_var = ["cost"] + y_var = "y" + test_perc = 0.2 + df_ip = pd.read_excel(path + "test_time_series.xlsx", + sheet_name="exog") + df_ip = df_ip.set_index("ts") + df_train = df_ip.iloc[0:int(len(df_ip) * (1-test_perc)), :] + df_test = df_ip.iloc[int(len(df_ip) * (1-test_perc)): len(df_ip), :] + df_test = df_test[x_var] + mod = RandomForest(df_train, y_var, x_var, method="timeseries") + mod.predict(df_test) + metrics = mod.model_summary + self.assertGreaterEqual(metrics["rsq"], 0.8) + self.assertLessEqual(metrics["mape"], 0.5) + + def test_rf_ts_endog(self): + """RandomForest: Test for time series with endogenous variable""" + y_var = "y" + df_ip = pd.read_excel(path + "test_time_series.xlsx", + sheet_name="exog") + df_ip = df_ip.set_index("ts") + mod = RandomForest(df_ip, y_var, method="timeseries") + mod.predict() + metrics = mod.model_summary + self.assertGreaterEqual(metrics["rsq"], 0.6) + self.assertLessEqual(metrics["mape"], 1) + class Test_XGBoost(unittest.TestCase): """Test suite for module ``XGBoost``.""" @@ -104,7 +132,6 @@ class Test_XGBoost(unittest.TestCase): def setUp(self): """Set up for module ``XGBoost``.""" - @ignore_warnings def test_xgboost_class(self): """XGBoost: Test for classification""" x_var = ["x1", "x2"] @@ -121,7 +148,6 @@ def test_xgboost_class(self): acc = round(sk_metrics.accuracy_score(y, y_hat), 2) self.assertGreaterEqual(acc, 0.93) - @ignore_warnings def test_xgboost_reg(self): """XGBoost: Test for regression""" x_var = ["x1", "x2", "x3", "x4"] @@ -138,6 +164,35 @@ def test_xgboost_reg(self): mse = round(sk_metrics.mean_squared_error(y, y_hat), 2) self.assertLessEqual(mse, 0.5) + def test_xgboost_ts_exog(self): + """XGBoost: Test for time series with exogenous variables""" + x_var = ["cost"] + y_var = "y" + test_perc = 0.2 + df_ip = pd.read_excel(path + "test_time_series.xlsx", + sheet_name="exog") + df_ip = df_ip.set_index("ts") + df_train = df_ip.iloc[0:int(len(df_ip) * (1-test_perc)), :] + df_test = df_ip.iloc[int(len(df_ip) * (1-test_perc)): len(df_ip), :] + df_test = df_test[x_var] + mod = XGBoost(df_train, y_var, x_var, method="timeseries") + mod.predict(df_test) + metrics = mod.model_summary + self.assertAlmostEqual(1.0, metrics["rsq"], places=1) + self.assertLessEqual(metrics["mape"], 0.1) + + def test_xgboost_ts_endog(self): + """XGBoost: Test for time series with endogenous variable""" + y_var = "y" + df_ip = pd.read_excel(path + "test_time_series.xlsx", + sheet_name="exog") + df_ip = df_ip.set_index("ts") + mod = XGBoost(df_ip, y_var, method="timeseries") + mod.predict() + metrics = mod.model_summary + self.assertGreaterEqual(metrics["rsq"], 0.7) + self.assertLessEqual(metrics["mape"], 0.5) + # ============================================================================= # --- Main