Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions 00_globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ library(magrittr)
library(stringr)
library(SigOptR)

### declare GLOBAL variables ----
random_seed <- 8675309

### declare functions ----

# Function to train random forest model
Expand All @@ -29,7 +26,4 @@ predict_classifier <- function(object, new_data){
predict(object = object, newdata = new_data, type = "prob")
}

# Function to get AUC from the random forest model



14 changes: 7 additions & 7 deletions 01_download_format_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
# This script splits data into two training sets and a test set
################################################################################

rm(list = ls())

set.seed(90210)

### Load necessary libraries ----
library(textmineR)

Expand Down Expand Up @@ -41,7 +37,10 @@ doc_class <- stringr::str_split(docnames, pattern = "/") %>%

doc_class <- factor(doc_class)

dtm <- CreateDtm(doc_vec = docs) # stopwords English and SMART
# Using the default stopwords from textmineR.
# The default is the "english" set and "SMART" set.
# Pretty common choice and it shouldn't make much of a difference on this data set.
dtm <- CreateDtm(doc_vec = docs)

dim(dtm)

Expand All @@ -51,12 +50,13 @@ dtm <- dtm[, colSums(dtm > 0) >= 5]
dim(dtm)

### sample rows into three groups ----
set.seed(90210) # Setting a seed for reproducibility since we call sample below

idx <- seq_len(nrow(dtm))

train1 <- sample(idx, 6665)
train1 <- sample(x = idx, size = 6665)

train2 <- sample(setdiff(idx, train1), 6665)
train2 <- sample(x = setdiff(idx, train1), size = 6665)

test <- setdiff(idx, c(train1, train2))

Expand Down
4 changes: 3 additions & 1 deletion 02_lsa_sigopt.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ create_model <- function(assignments) {

### run the optimization loop ----

Sys.sleep(60)
# need to pause the execution so the parallel workers don't get ahead of the
# API call
Sys.sleep(60)

output <- parallel::mclapply(seq_len(experiment$observation_budget), function(j){

Expand Down
3 changes: 3 additions & 0 deletions 03_lda_sigopt.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ create_model <- function(assignments) {
}

### run the optimization loop ----

# need to pause the execution so the parallel workers don't get ahead of the
# API call
Sys.sleep(60)

output <- parallel::mclapply(seq_len(experiment$observation_budget), function(j){
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
# topic-modeling-optimization-example
# topic-modeling-optimization-example

To successfully run the code in this repository you will need to have a SigOpt API key. Save it to a text file called "sigopt_api_key" in the root folder of this repository. The file should be a single line, with your API key saved on it.

You will also need to install the dependencies with the following commands:
```
install.packages("parallel")
install.packages("textmineR"")
install.packages("randomForest")
install.packages("magrittr")
install.packages("stringr")
install.packages("SigOptR")
```

You will also have to run this code from the root folder by doing one of the follwing:

1. From the command line: enter your R environment from the root directory of the folder
2. From any start point: run `setwd("X")` where `"X"` is the root folder of this repo.
3. Use RStudio and open the project "topic-modeing-optimization-example.Rproj" from your RStudio IDE. This will handle all working diretory issues.

Note that if you choose option "2" above [Jenny Bryan will set your computer on fire.](https://www.tidyverse.org/blog/2017/12/workflow-vs-script/)

## To run these files locally
Run the scripts in the following order:

1. 01_download_format_data.R
2. 02_lsa_sigopt.R
3. 03_lda_sigopt.R
4. 04_lda_optimal.R

# To run these files on google cloud compute

1. Install one more package with `install.packages("cloudml")`
2. If this is your first time using the `cloudml` package

131 changes: 87 additions & 44 deletions blog_post.Rmd

Large diffs are not rendered by default.

111 changes: 66 additions & 45 deletions blog_post.html

Large diffs are not rendered by default.

Binary file added process_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions process_diagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.