Skip to content
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

features output of guanlab_model(), are 1s or 0s #57

Closed
itismeghasyam opened this issue Oct 25, 2018 · 1 comment
Closed

features output of guanlab_model(), are 1s or 0s #57

itismeghasyam opened this issue Oct 25, 2018 · 1 comment

Comments

@itismeghasyam
Copy link
Contributor

library(mhealthtools)

### Load data file
data("sensor_data")
dat <- mhealthtools::sensor_data

### flatten data to the format needed for mHealthTools
flatten_data <- function(dat, metric) {
  dat <- dat %>% 
    select(timestamp, metric) %>% 
    jsonlite::flatten()
  names(dat) <- c("t", "x", "y", "z")
  return(as_tibble(dat))
}

### Get the formatted accelerometer and gyroscope data to use in testing below
datAccel <- flatten_data(dat,'userAcceleration')

#### Test GuanLab model
guanlab_model <- function(sensor_data, models = load_guanlab_model) {
  if (is.function(models)) { # load weights from file
    models <- models()
  }
  features <- purrr::map_dfc(models, function(model) {
    padding <- matrix(0, 4000 - dim(sensor_data)[1], 3)
    standard_sensor_data <- sensor_data %>%
      dplyr::select(-t) %>% 
      purrr::map(~ (. - mean(.)) / sd(.)) %>% 
      unlist() %>% 
      matrix(ncol = 3, byrow = F)
    padded_sensor_data <- standard_sensor_data %>% 
      rbind(padding) %>% 
      keras::array_reshape(c(1, 4000, 3))
    proba <- model$predict_proba(padded_sensor_data)
    return(proba)
  })
  return(features)
}

#### feature output
a <- mhealthtools:::guanlab_model(sensor_data = datAccel)

 >a
# A tibble: 1 x 10
     V1    V2    V3    V4    V5    V6    V7    V8    V9   V10
  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1     0     0     1     1     0     0     0     1     0     0

When I run this a is just a vector of 0s and 1s, shouldn't it be probabilities instead of class predictions?
I think predict_proba is just giving out 1s and 0s as output, instead of the actual probability

@philerooski
Copy link
Collaborator

We discussed this last month. Closing because this is superseded by #37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants