You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@madlib.apache.org by ri...@apache.org on 2018/07/12 21:03:59 UTC
[3/5] madlib git commit: CV: Fix incorrect dict index + change output
columns
CV: Fix incorrect dict index + change output columns
JIRA: MADLIB-1250
Cross validation had a minor bug that didn't fully index into a two-level
nested dictionary. This led to a KeyError while writing CV results to an
output table. This has been fixed in this commit.
Additionally, the CV output table columns are called 'mean_score' and
'std_dev_score', instead of 'mean_neg_loss' and 'std_neg_loss' to not
confuse with the loss function used in the primary modeling technique.
Closes #287
Project: http://git-wip-us.apache.org/repos/asf/madlib/repo
Commit: http://git-wip-us.apache.org/repos/asf/madlib/commit/834f543e
Tree: http://git-wip-us.apache.org/repos/asf/madlib/tree/834f543e
Diff: http://git-wip-us.apache.org/repos/asf/madlib/diff/834f543e
Branch: refs/heads/master
Commit: 834f543eefdbf321c2ce014d64f909138559c357
Parents: ceab57f
Author: Rahul Iyer <ri...@apache.org>
Authored: Tue Jul 3 14:28:21 2018 -0700
Committer: Rahul Iyer <ri...@apache.org>
Committed: Thu Jul 12 13:39:31 2018 -0700
----------------------------------------------------------------------
src/ports/postgres/modules/svm/test/svm.sql_in | 4 +++-
.../validation/internal/cross_validation.py_in | 16 ++++++++--------
2 files changed, 11 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/madlib/blob/834f543e/src/ports/postgres/modules/svm/test/svm.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/svm/test/svm.sql_in b/src/ports/postgres/modules/svm/test/svm.sql_in
index ad4b9ac..cba370c 100644
--- a/src/ports/postgres/modules/svm/test/svm.sql_in
+++ b/src/ports/postgres/modules/svm/test/svm.sql_in
@@ -581,7 +581,9 @@ SELECT svm_classification(
'gaussian',
'n_components=3, fit_intercept=true',
NULL,
- 'max_iter=2, n_folds=3, lambda=[0.01, 0.1, 0.5]');
+ 'init_stepsize=[0.01, 0.1], max_iter=2, n_folds=3, lambda=[0.01, 0.1, 0.5], validation_result=m7_cv');
+
+SELECT * FROM m7_cv;
SELECT svm_predict('m7','svm_test_data', 'id', 'svm_test_7');
SELECT
http://git-wip-us.apache.org/repos/asf/madlib/blob/834f543e/src/ports/postgres/modules/validation/internal/cross_validation.py_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/validation/internal/cross_validation.py_in b/src/ports/postgres/modules/validation/internal/cross_validation.py_in
index 84e52e9..c173533 100644
--- a/src/ports/postgres/modules/validation/internal/cross_validation.py_in
+++ b/src/ports/postgres/modules/validation/internal/cross_validation.py_in
@@ -67,8 +67,8 @@ class ValidationResult(object):
List of dictionaries.
Each dictionary contains the following three keys:
- - mean_neg_loss: float, average of scores using sub_args
- - std_neg_loss: float, standard deviation of scores using sub_args
+ - mean_score: float, average of scores using sub_args
+ - std_dev_score: float, standard deviation of scores using sub_args
- sub_args: dict, the values of arguments being validated
"""
def __init__(self, cv_history=None):
@@ -98,12 +98,12 @@ class ValidationResult(object):
def add_one(self, mean, std, sub_args):
"""Add one record to the history"""
- record = dict(mean_neg_loss=mean, std_neg_loss=std, sub_args=sub_args)
+ record = dict(mean_score=mean, std_dev_score=std, sub_args=sub_args)
self._cv_history.append(record)
def sorted(self):
"""Sort the history w.r.t. mean value and return a new ValidationResult object"""
- ch = sorted(self._cv_history, reverse=True, key=itemgetter('mean_neg_loss'))
+ ch = sorted(self._cv_history, reverse=True, key=itemgetter('mean_score'))
return ValidationResult(ch)
def first(self, attr=None):
@@ -112,7 +112,7 @@ class ValidationResult(object):
Parameters
==========
attr : string, optional
- Any string in {'mean_neg_loss', 'std_neg_loss', 'sub_args'} or None
+ Any string in {'mean_score', 'std_dev_score', 'sub_args'} or None
Returns
=======
@@ -133,13 +133,14 @@ class ValidationResult(object):
def output_tbl(self, tbl_name):
"""Create a table tbl_name that contains the history
- The columns of tbl_name are mean_neg_loss, std_neg_loss and the leaf keys in sub_args.
+ The columns of tbl_name are mean_score, std_dev_score and the leaf keys in sub_args.
All column types are assumed to be double precision.
"""
if not tbl_name or not str(tbl_name).strip():
return
- header = self._cv_history[0]['sub_args'].keys() + ['mean_neg_loss', 'std_neg_loss']
+ header = (self._cv_history[0]['sub_args']['params_dict'].keys() +
+ ['mean_score', 'std_dev_score'])
header_str = ','.join(map(str, header))
data = []
@@ -147,7 +148,6 @@ class ValidationResult(object):
values = ','.join([str(h[k]) for k in header])
data.append("({0})".format(values))
data = ','.join(data)
-
plpy.execute("""
CREATE TABLE {tbl_name} ({header_str}) AS
VALUES