Skip to content

Commit

Permalink
Fixed ignored_columns handling in glm.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasnykodym committed Apr 13, 2015
1 parent f825772 commit 9060c5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
10 changes: 5 additions & 5 deletions 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
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
28 changes: 8 additions & 20 deletions src/main/java/hex/glm/GLM2.java
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 9060c5f

Please sign in to comment.