Skip to content

Instantly share code, notes, and snippets.

@julianflowers
julianflowers / latitude_longitude.txt
Created July 18, 2022 14:41 — forked from pjobson/latitude_longitude.txt
Latitude / Longitude DMS, DDM, DD Regular Expressions
Degrees Minutes Seconds (DMS)
40° 26′ 46″ N 79° 58′ 56″ W
40° 26′ 46″ S 79° 58′ 56″ E
90° 0′ 0″ S 180° 0′ 0″ E
40° 26′ 45.9996″ N 79° 58′ 55.2″ E
Latitudes range from 0 to 90.
Longitudes range from 0 to 180.
Minutes & Seconds range from 0-60
Use N, S, E or W as either the last character,
which represents a compass direction North, South, East or West.
@julianflowers
julianflowers / regex.md
Created July 18, 2022 14:32 — forked from debkanchan/regex.md
RegEx for Latitude and Longitude

Regular Expression(RegExp) for Latitude and Longitude

Just Latitude:

^-?([0-8]?[0-9]|90)(\.[0-9]{1,10})$

matches:

  • 56.3847
  • -56.387

unmatches:

@julianflowers
julianflowers / ml-7
Created May 13, 2022 08:29
ml-7: remove highly correlated variables
data2_cor <- data2 %>%
select_if(is.numeric) %>%
cor(.)
highly_correlated <- caret::findCorrelation(data2_cor, cutoff = .9)
complete_data <- data2[, -highly_correlated]
@julianflowers
julianflowers / ml_14
Created February 20, 2019 08:54
vimp
varImp <- varImp(model.glmnet)
plot(varImp)
@julianflowers
julianflowers / ml_13
Created February 20, 2019 08:52
rmse-test
rmse <- sqrt(mean((pred_test - test$excess_weight_in_adults_aged_18_persons_18_yrs)^2))
rmse
@julianflowers
julianflowers / ml_12
Created February 20, 2019 08:51
predict-test
test <- test %>%
janitor::clean_names()
pred_test <- predict(model.glmnet, newdata = test)
@julianflowers
julianflowers / ml_9
Last active May 13, 2022 08:37
train-glmnet
train <- train %>% janitor::clean_names() ## rpart doesn't like variable names with spaces
model.glmnet <- train(percentage_of_adults_aged_18_classified_as_overweight_or_obese_persons_18_yrs ~., data = train, method = "glmnet", trControl = control)
@julianflowers
julianflowers / ml_11
Created February 20, 2019 08:43
model-performance
glm <- model.glm$results %>% select(RMSE:MAE) %>% mutate(model = "glm")
glmnet <- model.glmnet$results %>% select(RMSE:MAE) %>% mutate(model = "glmnet")
rpart <- model.rpart$results %>% select(RMSE:MAE) %>% mutate(model = "rpart")
ranger <- model.ranger$results %>% select(RMSE:MAE) %>% mutate(model = "ranger")
results <- bind_rows(glm, glmnet, rpart, ranger)
results
@julianflowers
julianflowers / lit-3
Created February 19, 2019 11:36
keywords
#install_github("dgrtwo/drlib")
library(drlib)
tidy_tm %>%
group_by(topic) %>%
top_n(10, beta) %>%
ungroup() %>%
mutate(topic = paste0("Topic ", topic),
term = reorder_within(term, beta, topic)) %>%
@julianflowers
julianflowers / lit-2
Created February 19, 2019 11:27
bigrams
bigrams <- check %>%
create_bigrams(title)
bigrams %>%
count(bigram, year) %>%
dplyr::top_n(100) %>%
ggplot(aes(bigram, fct_rev(year), fill = n)) +
geom_tile() +
theme(axis.text.x= element_text(size = 7, angle = 90, hjust = 0)) +
scale_x_discrete(position = "top") +