Skip to content

Commit

Permalink
Include handling for categorical
Browse files Browse the repository at this point in the history
  • Loading branch information
Damonamajor committed Aug 7, 2024
1 parent 9cfce31 commit 35faf5f
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions analyses/Data_transformation.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
target_feature_value <- params$added_feature
target_feature_shap <- params$added_feature_shap
type <- params$type
nbhd <- ccao::nbhd_shp

# Create a individual card level dataset
Expand Down Expand Up @@ -79,15 +80,27 @@ pin_individual <- assessment_pin_new %>%
# Aggregate to neighborhood level
pin_nbhd <- pin_individual %>%
group_by(meta_nbhd_code) %>%
summarize(
!!paste0({{ target_feature_value }}, "_neighborhood_mean") :=
mean(!!sym({{ target_feature_value }}), na.rm = TRUE),
!!paste0({{ target_feature_value }}, "_neighborhood_median") :=
median(!!sym({{ target_feature_value }}), na.rm = TRUE),
!!paste0({{ target_feature_value }}, "_neighborhood_90th") :=
quantile(!!sym({{ target_feature_value }}), 0.9, na.rm = TRUE)
) %>%
ungroup() %>%
if (type == "continuous") {
summarize(
!!paste0({{ target_feature_value }}, "_neighborhood_mean") :=
mean(!!sym({{ target_feature_value }}), na.rm = TRUE),
!!paste0({{ target_feature_value }}, "_neighborhood_median") :=
median(!!sym({{ target_feature_value }}), na.rm = TRUE),
!!paste0({{ target_feature_value }}, "_neighborhood_90th") :=
quantile(!!sym({{ target_feature_value }}), 0.9, na.rm = TRUE)
)
} else {
summarize(
!!paste0({{ target_feature_value }}, "_most_common_value") :=
names(sort(table(!!sym({{ target_feature_value }})), decreasing = TRUE)[1]),

Check warning on line 95 in analyses/Data_transformation.R

View workflow job for this annotation

GitHub Actions / pre-commit

file=/home/runner/work/model-res-avm/model-res-avm/analyses/Data_transformation.R,line=95,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 84 characters.
!!paste0({{ target_feature_value }}, "_top5_common_values_percent") := {
freq <- sort(table(!!sym({{ target_feature_value }})), decreasing = TRUE)

Check warning on line 97 in analyses/Data_transformation.R

View workflow job for this annotation

GitHub Actions / pre-commit

file=/home/runner/work/model-res-avm/model-res-avm/analyses/Data_transformation.R,line=97,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 81 characters.
top5 <- head(freq, 5)
sum(top5) / sum(freq) * 100
}
)
}
ungroup() %>%
inner_join(
nbhd,
by = c("meta_nbhd_code" = "town_nbhd")
Expand Down

0 comments on commit 35faf5f

Please sign in to comment.