egr95 / R-codacore

An R package for learning log-ratio biomarkers from high-throughput sequencing data.
Other
21 stars 3 forks source link

Add handling for character & factor y #2

Closed tpq closed 3 years ago

tpq commented 3 years ago

2-part bug report / question,

-- When using character, error is thrown:

`Error in y * 0 : non-numeric argument to binary operator'

-- Factor works, but unsure whether factor is handled as discrete classes (via a logistic / multinomial regression) or coerced into continuous numeric (via linear regression)

-- Proposed solution:

Always coerce character into factor

if(class(y) == "character"){
  y <- factor(y)
}

Then convert factor into 1-hot encoding of class labels


if(class(y) == "factor"){
  keras::to_categorical(as.numeric(y)-1) # <- -1 because keras, being Python, uses zero indexing
}
egr95 commented 3 years ago

Good catch, thanks!