From 9060c5f302e245f8bf1fc940440a2982b04c05da Mon Sep 17 00:00:00 2001 From: Tomas Nykodym Date: Mon, 13 Apr 2015 15:46:25 -0700 Subject: [PATCH] Fixed ignored_columns handling in glm. --- smalldata/glm_test/abcd.csv | 10 +++++----- src/main/java/hex/glm/GLM2.java | 28 ++++++++-------------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/smalldata/glm_test/abcd.csv b/smalldata/glm_test/abcd.csv index 0fe0917f23..0d9038448a 100644 --- a/smalldata/glm_test/abcd.csv +++ b/smalldata/glm_test/abcd.csv @@ -1,5 +1,5 @@ -A B C D E -1 0 0 0 1 -0 1 0 0 1 -0 0 1 0 1 -1 1 0 1 1 \ No newline at end of file +A B C D E F +1 0 0 0 1 5 +0 1 0 0 1 5 +0 0 1 0 1 5 +1 1 0 1 1 5 \ No newline at end of file diff --git a/src/main/java/hex/glm/GLM2.java b/src/main/java/hex/glm/GLM2.java index 0432208c9f..7cf5130809 100644 --- a/src/main/java/hex/glm/GLM2.java +++ b/src/main/java/hex/glm/GLM2.java @@ -434,17 +434,9 @@ private double computeIntercept(DataInfo dinfo, double ymu, Vec offset, Vec resp _glm = new GLMParams(family, tweedie_variance_power, link, tweedie_link_power); source2 = new Frame(source); assert sorted(ignored_cols); - if (offset != null) { - if (offset.isEnum()) - throw new IllegalArgumentException("Categorical offsets are not supported. Can not use column '" + source2.names()[source2.find(offset)] + "' as offset"); - int id = source.find(offset); - int idx = Arrays.binarySearch(ignored_cols, id); - if (idx >= 0) Utils.remove(ignored_cols, idx); - source2.remove(ignored_cols); - String name = source2.names()[id]; -// source2.add(name, source2.remove(id)); - _noffsets = 1; - } + source2.remove(ignored_cols); + if(offset != null) + source2.remove(source2.find(offset)); // remove offset and add it later explicitly (so that it does not interfere with DataInfo.prepareFrame) if (nlambdas == -1) nlambdas = 100; if (lambda_search && lambda.length > 1) @@ -470,20 +462,16 @@ private double computeIntercept(DataInfo dinfo, double ymu, Vec offset, Vec resp //pass } toEnum = family == Family.binomial && (!response.isEnum() && (response.min() < 0 || response.max() > 1)); - String offsetName = ""; - int offsetId = -1; - if(offset != null) { - offsetId = source2.find(offset); - offsetName = source2.names()[offsetId]; - source2.remove(offsetId); - } Frame fr = DataInfo.prepareFrame(source2, response, new int[0], toEnum, true, true); - if(offset != null){ // now put the offset just before response + if(offset != null){ // now put the offset just in front of response + int id = source.find(offset); + String name = source.names()[id]; String responseName = fr.names()[fr.numCols()-1]; Vec responseVec = fr.remove(fr.numCols()-1); - fr.add(offsetName, offset); + fr.add(name, offset); fr.add(responseName,responseVec); + _noffsets = 1; } TransformType dt = TransformType.NONE; if (standardize)