OwenStOnge commited on
Commit
9a1be5e
·
verified ·
1 Parent(s): cb8faf1

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +5 -2
app.R CHANGED
@@ -287,6 +287,7 @@ of_oaa_setup <- function(data) {
287
  d <- cbind(d, catch_prob = probs)
288
 
289
  d %>% mutate(
 
290
  catch_prob = 1 - catch_prob,
291
  pred_catch = ifelse(catch_prob >= .5, 1, 0),
292
  OAA = (as.numeric(success_ind) - 1) - catch_prob) %>%
@@ -351,15 +352,17 @@ if_oaa_setup <- function(data) {
351
  filter(!is.na(obs_player))
352
 
353
  # For IF model, success_ind needs to be factor
354
- d <- d %>% mutate(success_ind = as.factor(success_ind))
355
 
356
  processed <- bake(IF_OAA_recipe, new_data = d) %>%
357
  dplyr::select(-any_of("success_ind")) %>%
358
  mutate(across(where(is.factor), as.numeric), across(where(is.character), as.numeric))
 
359
  dmat <- xgb.DMatrix(data = as.matrix(processed))
360
  probs <- predict(IF_OAA_model, dmat)
 
361
  d <- cbind(d, play_prob = probs)
362
  d %>% mutate(
 
363
  play_prob = 1 - play_prob,
364
  play_pred = ifelse(play_prob >= .5, 1, 0),
365
  OAA = (as.numeric(success_ind) - 1) - play_prob) %>%
@@ -519,7 +522,7 @@ field_graph <- function(player, position, oaa_df) {
519
 
520
  # -- OF direction OAA --
521
  direction_oaa <- function(player, position, oaa_data) {
522
- dir_levels <- c("Back Right","Back","Back Left","Left","In Left","In","In Right","Right")
523
  if (position %in% c("RF","CF","LF")) {
524
  pd <- oaa_data %>% filter(obs_player == player, hit_location == position)
525
  } else {
 
287
  d <- cbind(d, catch_prob = probs)
288
 
289
  d %>% mutate(
290
+ obs_player = str_replace_all(obs_player, "(\\w+), (\\w+)", "\\2 \\1"),
291
  catch_prob = 1 - catch_prob,
292
  pred_catch = ifelse(catch_prob >= .5, 1, 0),
293
  OAA = (as.numeric(success_ind) - 1) - catch_prob) %>%
 
352
  filter(!is.na(obs_player))
353
 
354
  # For IF model, success_ind needs to be factor
 
355
 
356
  processed <- bake(IF_OAA_recipe, new_data = d) %>%
357
  dplyr::select(-any_of("success_ind")) %>%
358
  mutate(across(where(is.factor), as.numeric), across(where(is.character), as.numeric))
359
+
360
  dmat <- xgb.DMatrix(data = as.matrix(processed))
361
  probs <- predict(IF_OAA_model, dmat)
362
+
363
  d <- cbind(d, play_prob = probs)
364
  d %>% mutate(
365
+ obs_player_name = str_replace_all(obs_player_name, "(\\w+), (\\w+)", "\\2 \\1"),
366
  play_prob = 1 - play_prob,
367
  play_pred = ifelse(play_prob >= .5, 1, 0),
368
  OAA = (as.numeric(success_ind) - 1) - play_prob) %>%
 
522
 
523
  # -- OF direction OAA --
524
  direction_oaa <- function(player, position, oaa_data) {
525
+ dir_levels <- c("Right", "Back Right","Back","Back Left","Left","In Left","In","In Right")
526
  if (position %in% c("RF","CF","LF")) {
527
  pd <- oaa_data %>% filter(obs_player == player, hit_location == position)
528
  } else {