-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added warning , if column is multi categorical in h2o.cor() #12903 #15674
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3182,9 +3182,16 @@ def cor(self, y=None, na_rm=False, use=None, method="Pearson"): | |
assert_is_type(y, H2OFrame, None) | ||
assert_is_type(na_rm, bool) | ||
assert_is_type(use, None, "everything", "all.obs", "complete.obs") | ||
if y is None: | ||
y = self | ||
if use is None: use = "complete.obs" if na_rm else "everything" | ||
y_categorical = any(self.types[col_name] == "enum" for col_name in y) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems incorrect - |
||
|
||
if y_categorical: | ||
num_unique_levels = {col: len(self[col].levels()) for col in y} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of |
||
multi_categorical = any(num_levels > 2 for num_levels in num_unique_levels.values()) | ||
|
||
if multi_categorical: | ||
import warnings | ||
warnings.warn("NA") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make the warning more informative. For example: for col, card in num_unique_levels.items():
if card > 2:
warnings.warn("Column {} contains {} levels. Only numerical and binary columns are supported.".format(col, card)) |
||
|
||
if self.nrow == 1 or (self.ncol == 1 and y.ncol == 1): return ExprNode("cor", self, y, use, method)._eager_scalar() | ||
return H2OFrame._expr(expr=ExprNode("cor", self, y, use, method))._frame() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2880,25 +2880,36 @@ var <- function(x, y = NULL, na.rm = FALSE, use) { | |
#' cor(prostate$AGE) | ||
#' } | ||
#' @export | ||
h2o.cor <- function(x, y=NULL,na.rm = FALSE, use, method="Pearson"){ | ||
h2o.cor <- function(x, y = NULL, na.rm = FALSE, use, method = "Pearson") { | ||
# Eager, mostly to match prior semantics but no real reason it need to be | ||
if( is.null(y) ){ | ||
if (is.null(y)) { | ||
y <- x | ||
} | ||
if(missing(use)) { | ||
if (missing(use)) { | ||
if (na.rm) use <- "complete.obs" else use <- "everything" | ||
} | ||
|
||
if (is.null(method) || is.na(method)) { | ||
stop("Correlation method must be specified.") | ||
} | ||
|
||
# Check for categorical columns in x and y | ||
x_categorical <- any(h2o.isfactor(x)) | ||
y_categorical <- any(h2o.isfactor(y)) | ||
|
||
if ((x_categorical && length(unique(h2o.levels(x))) > 2) || (y_categorical && length(unique(h2o.levels(y))) > 2)) { | ||
warning("NA") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make the warning more informative. |
||
} | ||
|
||
|
||
# Eager, mostly to match prior semantics but no real reason it need to be | ||
expr <- .newExpr("cor",x,y,.quote(use), .quote(method)) | ||
if( (nrow(x)==1L || (ncol(x)==1L && ncol(y)==1L)) ) .eval.scalar(expr) | ||
else .fetch.data(expr,ncol(x)) | ||
expr <- .newExpr("cor", x, y, .quote(use), .quote(method)) | ||
if ((nrow(x) == 1L || (ncol(x) == 1L && ncol(y) == 1L))) .eval.scalar(expr) | ||
else .fetch.data(expr, ncol(x)) | ||
} | ||
|
||
|
||
|
||
#' | ||
#' Compute a pairwise distance measure between all rows of two numeric H2OFrames. | ||
#' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be deleted.